summaryrefslogtreecommitdiffstats
path: root/feed/sse_db.py
diff options
context:
space:
mode:
Diffstat (limited to 'feed/sse_db.py')
-rw-r--r--feed/sse_db.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/feed/sse_db.py b/feed/sse_db.py
index e99c5d0..6a0f7e6 100644
--- a/feed/sse_db.py
+++ b/feed/sse_db.py
@@ -1,7 +1,8 @@
import sys, os, MySQLdb, stat
+from sse_config import *
-db = MySQLdb.connect(host = "localhost", user = "sse_web", passwd = "ece6Yoli", db = "sse")
+db = MySQLdb.connect(SSE_DB_HOST, SSE_DB_USER, SSE_DB_PASSWORD, SSE_DB_DATABASE)
cursor = db.cursor();
def commit():
@@ -19,18 +20,18 @@ def last_insert_id():
def new_package(archive, root, meta):
- cursor.execute('INSERT INTO package (path, timestamp, md) VALUES (%s, NOW(), %s)', (root + '/%s', meta["md"]))
+ cursor.execute('INSERT INTO package (crawler_id, path, timestamp, md) VALUES (%s, %s, NOW(), %s)', (SSE_CRAWLER_ID, root + '/%s', meta["md"]))
- return last_insert_id();
+ return (SSE_CRAWLER_ID, last_insert_id())
def find_package(md):
- cursor.execute('SELECT id FROM package WHERE md=%s', md)
+ cursor.execute('SELECT crawler_id, id FROM package WHERE md=%s', md)
if cursor.rowcount <= 0:
return None
- return int(cursor.fetchone()[0])
+ return (int(cursor.fetchone()[0]), int(cursor.fetchone()[1]))
def new_provider_record(recid, package_id, provider_id, meta):
@@ -54,14 +55,13 @@ def new_provider_record(recid, package_id, provider_id, meta):
except KeyError:
l = ""
- cursor.execute('REPLACE provider_record (id, package_id, provider_id, name, url, download_url, license) VALUES (%s, %s, %s, %s, %s, %s, %s)', (recid, package_id, provider_id, name, url, download_url, l))
-
+ cursor.execute('REPLACE provider_record (id, crawler_id, package_id, provider_id, name, url, download_url, license) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)', (recid, package_id[0], package_id[1], provider_id, name, url, download_url, l))
def new_file(package_id, path, language_id = 0):
- cursor.execute('INSERT INTO file (package_id, path, language_id) VALUES (%s, %s, %s)', (package_id, path, language_id));
+ cursor.execute('INSERT INTO file (crawler_id, package_id, path, language_id) VALUES (%s, %s, %s)', (package_id[0], package_id[1], path, language_id));
- return last_insert_id()
+ return (SSE_CRAWLER_ID, last_insert_id())
def new_word(file_id, text, is_subword):
@@ -70,5 +70,5 @@ def new_word(file_id, text, is_subword):
else:
t = "word"
- cursor.execute('INSERT IGNORE INTO word (text, type, file_id, cnt) VALUES (%s, %s, %s, 0)', (text, t, file_id))
- cursor.execute('UPDATE word SET cnt=cnt+1 WHERE text=%s AND type=%s AND file_id=%s', (text, t, file_id))
+ cursor.execute('INSERT IGNORE INTO word (text, type, crawler_id, file_id, cnt) VALUES (%s, %s, %s, 0)', (text, t, crawler_id, file_id))
+ cursor.execute('UPDATE word SET cnt=cnt+1 WHERE text=%s AND type=%s AND crawler_id=%s AND file_id=%s', (text, t, crawler_id, file_id))