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-03 11:03:36 +00:00
|
|
|
update_type = "postid" if update[2] is not None else "rcid"
|
|
|
|
db_cursor.execute("UPDATE rcgcdw SET {} = ? WHERE wiki = ?".format(update_type), (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()
|