RcGcDb/src/queue_handler.py

29 lines
643 B
Python
Raw Normal View History

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:
sql = "UPDATE rcgcdw SET rcid = ? WHERE wiki = ? AND rcid != -1"
else:
sql = "UPDATE rcgcdw SET postid = ? WHERE wikiid = ?"
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()