From ea1b56b1c12deb35f73904ec9f696ec9329668bc Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Tue, 4 Sep 2012 14:54:59 -0400 Subject: [PATCH] Some fixes and cleanup. --- toolserver/copyvios/checker.py | 11 +++++------ toolserver/sites.py | 5 ++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/toolserver/copyvios/checker.py b/toolserver/copyvios/checker.py index 94e5a46..69a938f 100644 --- a/toolserver/copyvios/checker.py +++ b/toolserver/copyvios/checker.py @@ -2,7 +2,6 @@ from datetime import datetime from hashlib import sha256 -from time import time from earwigbot import exceptions @@ -16,7 +15,7 @@ def get_results(bot, site, query): return page, None if query.url: - result = page.copyvio_compare(url) + result = page.copyvio_compare(query.url) result.cached = False else: conn = open_sql_connection(bot, "copyvioCache") @@ -33,11 +32,11 @@ def _get_cached_results(page, conn): query1 = "DELETE FROM cache WHERE cache_time < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 3 DAY)" query2 = "SELECT cache_url, cache_time, cache_queries, cache_process_time FROM cache WHERE cache_id = ? AND cache_hash = ?" pageid = page.pageid() - hash = sha256(page.get()).hexdigest() + shahash = sha256(page.get()).hexdigest() with conn.cursor() as cursor: cursor.execute(query1) - cursor.execute(query2, (pageid, hash)) + cursor.execute(query2, (pageid, shahash)) results = cursor.fetchall() if not results: return None @@ -61,7 +60,7 @@ def _format_date(cache_time): def _cache_result(page, result, conn): pageid = page.pageid() - hash = sha256(page.get()).hexdigest() + shahash = sha256(page.get()).hexdigest() query1 = "SELECT 1 FROM cache WHERE cache_id = ?" query2 = "DELETE FROM cache WHERE cache_id = ?" query3 = "INSERT INTO cache VALUES (?, ?, ?, CURRENT_TIMESTAMP, ?, ?)" @@ -69,5 +68,5 @@ def _cache_result(page, result, conn): cursor.execute(query1, (pageid,)) if cursor.fetchall(): cursor.execute(query2, (pageid,)) - cursor.execute(query3, (pageid, hash, result.url, result.queries, + cursor.execute(query3, (pageid, shahash, result.url, result.queries, result.time)) diff --git a/toolserver/sites.py b/toolserver/sites.py index e0260aa..4430512 100644 --- a/toolserver/sites.py +++ b/toolserver/sites.py @@ -108,6 +108,9 @@ def _synchronize_sites_with_db(cursor, updates, q_list, q_rmv, q_update): removals = [] cursor.execute(q_list) for site in cursor: - updates.remove(site) if site in updates else removals.append(site) + if site in updates: + updates.remove(site) + else: + removals.append(site) cursor.executemany(q_rmv, removals) cursor.executemany(q_update, updates)