2020-07-11 15:54:08 +00:00
|
|
|
import logging
|
2020-07-21 12:15:40 +00:00
|
|
|
from src.database import db_cursor, db_connection
|
2020-07-11 15:54:08 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger("rcgcdb.queue_handler")
|
|
|
|
|
2020-07-28 12:39:32 +00:00
|
|
|
|
|
|
|
class UpdateDB:
|
2020-07-11 15:54:08 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.updated = []
|
|
|
|
|
2020-08-02 21:40:30 +00:00
|
|
|
def add(self, wiki, rc_id, feeds=None):
|
2020-08-02 17:27:42 +00:00
|
|
|
self.updated.append((wiki, rc_id, feeds))
|
2020-07-11 15:54:08 +00:00
|
|
|
|
|
|
|
def clear_list(self):
|
|
|
|
self.updated.clear()
|
|
|
|
|
|
|
|
def update_db(self):
|
|
|
|
for update in self.updated:
|
2020-08-08 17:25:32 +00:00
|
|
|
if update[2] is None:
|
2020-08-11 16:45:08 +00:00
|
|
|
sql = "UPDATE rcgcdw SET rcid = ? WHERE wiki = ? AND ( rcid != -1 OR rcid IS NULL )"
|
2020-08-08 17:25:32 +00:00
|
|
|
else:
|
|
|
|
sql = "UPDATE rcgcdw SET postid = ? WHERE wikiid = ?"
|
2020-08-08 17:32:53 +00:00
|
|
|
db_cursor.execute(sql, (update[1], update[0],))
|
2020-07-21 12:15:40 +00:00
|
|
|
db_connection.commit()
|
|
|
|
self.clear_list()
|
2020-07-18 12:12:00 +00:00
|
|
|
|
|
|
|
|
2020-07-21 12:15:40 +00:00
|
|
|
DBHandler = UpdateDB()
|