mirror of
https://github.com/house-of-vanity/tracker_watcher.git
synced 2025-07-07 09:54:08 +00:00
Additional check if size of topic is changed.
This commit is contained in:
@ -28,7 +28,7 @@ connection = pymysql.connect(host=mysql_host,
|
|||||||
# If u_date which already stored older than fresh u_date
|
# If u_date which already stored older than fresh u_date
|
||||||
# so going to notify
|
# so going to notify
|
||||||
# Any way update last_check
|
# Any way update last_check
|
||||||
def check_updates(id, u_date, cursor):
|
def check_updates(id, u_date, size, cursor):
|
||||||
link = "http://api.rutracker.org/v1/get_tor_topic_data?by=topic_id&val="+id
|
link = "http://api.rutracker.org/v1/get_tor_topic_data?by=topic_id&val="+id
|
||||||
with urllib.request.urlopen(link) as url:
|
with urllib.request.urlopen(link) as url:
|
||||||
data = json.loads(url.read().decode())
|
data = json.loads(url.read().decode())
|
||||||
@ -36,6 +36,7 @@ def check_updates(id, u_date, cursor):
|
|||||||
new_u_date = dt.datetime.fromtimestamp(int(data['result'][id]['reg_time']), tz=pytz.utc)
|
new_u_date = dt.datetime.fromtimestamp(int(data['result'][id]['reg_time']), tz=pytz.utc)
|
||||||
u_date = pytz.utc.localize(u_date)
|
u_date = pytz.utc.localize(u_date)
|
||||||
if new_u_date > u_date:
|
if new_u_date > u_date:
|
||||||
|
if int(data['result'][id]['size']) != int(size):
|
||||||
log(logger='Updater',
|
log(logger='Updater',
|
||||||
line='Update found',
|
line='Update found',
|
||||||
link=id)
|
link=id)
|
||||||
@ -62,10 +63,11 @@ def check_updates(id, u_date, cursor):
|
|||||||
|
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
# Create a new record
|
# Create a new record
|
||||||
sql = "UPDATE url SET last_check = %s, u_date = %s WHERE link = %s"
|
sql = "UPDATE url SET last_check = %s, u_date = %s, size = %s WHERE link = %s"
|
||||||
cursor.execute(sql, (
|
cursor.execute(sql, (
|
||||||
last_check.strftime('%Y-%m-%d %H:%M:%S'),
|
last_check.strftime('%Y-%m-%d %H:%M:%S'),
|
||||||
new_u_date.strftime('%Y-%m-%d %H:%M:%S'),
|
new_u_date.strftime('%Y-%m-%d %H:%M:%S'),
|
||||||
|
int(data['result'][id]['size']),
|
||||||
id))
|
id))
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ try:
|
|||||||
result = cursor.fetchall()
|
result = cursor.fetchall()
|
||||||
for line in result:
|
for line in result:
|
||||||
print('Going to check %s. Last check was at %s' % (line['link'], line['last_check']))
|
print('Going to check %s. Last check was at %s' % (line['link'], line['last_check']))
|
||||||
check_updates(line['link'], line['u_date'], cursor)
|
check_updates(line['link'], line['u_date'], line['size'], cursor)
|
||||||
finally:
|
finally:
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
@ -117,8 +117,8 @@ function notify($url){
|
|||||||
|
|
||||||
|
|
||||||
$stmt = $dbh->query(
|
$stmt = $dbh->query(
|
||||||
'INSERT into url (link,u_date)
|
'INSERT into url (link,u_date, size)
|
||||||
VALUES ("'.$url.'","'.gmdate("Y-m-d H:i:s", $obj->reg_time).'")'
|
VALUES ("'.$url.'","'.gmdate("Y-m-d H:i:s", $obj->reg_time).'", "'.$obj->size.'")'
|
||||||
);
|
);
|
||||||
$stmt = $dbh->query(
|
$stmt = $dbh->query(
|
||||||
'INSERT into notification (user_id, topic_id)
|
'INSERT into notification (user_id, topic_id)
|
||||||
|
Reference in New Issue
Block a user