mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
fix queue handler
This commit is contained in:
parent
fca9eb72b9
commit
6658c399dc
13
src/bot.py
13
src/bot.py
|
@ -100,7 +100,7 @@ class RcQueue:
|
|||
"""Makes a round on rcgcdw DB and looks for updates to the queues in self.domain_list"""
|
||||
try:
|
||||
fetch_all = db_cursor.execute(
|
||||
'SELECT ROWID, webhook, wiki, lang, display, wikiid, rcid FROM rcgcdw WHERE NOT rcid = -1 GROUP BY wiki ORDER BY ROWID')
|
||||
'SELECT ROWID, webhook, wiki, lang, display, wikiid, rcid FROM rcgcdw WHERE rcid != -1 GROUP BY wiki ORDER BY ROWID')
|
||||
self.to_remove = [x[0] for x in filter(self.filter_rc_active, all_wikis.items())] # first populate this list and remove wikis that are still in the db, clean up the rest
|
||||
full = []
|
||||
for db_wiki in fetch_all.fetchall():
|
||||
|
@ -176,7 +176,7 @@ def generate_targets(wiki_url: str) -> defaultdict:
|
|||
async def generate_domain_groups():
|
||||
"""Generate a list of wikis per domain (fandom.com, wikipedia.org etc.)"""
|
||||
domain_wikis = defaultdict(list)
|
||||
fetch_all = db_cursor.execute('SELECT ROWID, webhook, wiki, lang, display, wikiid, rcid FROM rcgcdw WHERE NOT rcid = -1 GROUP BY wiki ORDER BY ROWID ASC')
|
||||
fetch_all = db_cursor.execute('SELECT ROWID, webhook, wiki, lang, display, wikiid, rcid FROM rcgcdw WHERE rcid != -1 GROUP BY wiki ORDER BY ROWID ASC')
|
||||
for db_wiki in fetch_all.fetchall():
|
||||
all_wikis[db_wiki["wiki"]].rc_active = db_wiki["rcid"]
|
||||
domain_wikis[get_domain(db_wiki["wiki"])].append(db_wiki)
|
||||
|
@ -289,9 +289,8 @@ async def discussion_handler():
|
|||
try:
|
||||
while True:
|
||||
fetch_all = db_cursor.execute(
|
||||
'SELECT ROWID, webhook, wiki, lang, display, wikiid, rcid, postid FROM rcgcdw WHERE NOT wikiid = ""')
|
||||
'SELECT wiki, wikiid, postid FROM rcgcdw WHERE wikiid IS NOT NULL')
|
||||
for db_wiki in fetch_all.fetchall():
|
||||
if db_wiki["wikiid"] is not None:
|
||||
header = settings["header"]
|
||||
header["Accept"] = "application/hal+json"
|
||||
async with aiohttp.ClientSession(headers=header,
|
||||
|
@ -325,9 +324,9 @@ async def discussion_handler():
|
|||
continue
|
||||
if db_wiki["postid"] is None: # new wiki, just get the last post to not spam the channel
|
||||
if len(discussion_feed) > 0:
|
||||
DBHandler.add(db_wiki["wiki"], discussion_feed[-1]["id"], True)
|
||||
DBHandler.add(db_wiki["wikiid"], discussion_feed[-1]["id"], True)
|
||||
else:
|
||||
DBHandler.add(db_wiki["wiki"], "0", True)
|
||||
DBHandler.add(db_wiki["wikiid"], "0", True)
|
||||
DBHandler.update_db()
|
||||
continue
|
||||
targets = generate_targets(db_wiki["wiki"])
|
||||
|
@ -346,7 +345,7 @@ async def discussion_handler():
|
|||
logger.exception("Exception on Feeds formatter")
|
||||
await generic_msg_sender_exception_logger(traceback.format_exc(), "Exception in feed formatter", Post=str(post)[0:1000], Wiki=db_wiki["wiki"])
|
||||
if discussion_feed:
|
||||
DBHandler.add(db_wiki["wiki"], post["id"], True)
|
||||
DBHandler.add(db_wiki["wikiid"], post["id"], True)
|
||||
await asyncio.sleep(delay=2.0) # hardcoded really doesn't need much more
|
||||
DBHandler.update_db()
|
||||
except asyncio.CancelledError:
|
||||
|
|
|
@ -16,8 +16,11 @@ class UpdateDB:
|
|||
|
||||
def update_db(self):
|
||||
for update in self.updated:
|
||||
update_type = "postid" if update[2] is not None else "rcid"
|
||||
db_cursor.execute("UPDATE rcgcdw SET {} = ? WHERE wiki = ? AND NOT ? = -1".format(update_type), (update[1], update[0], update_type))
|
||||
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]))
|
||||
db_connection.commit()
|
||||
self.clear_list()
|
||||
|
||||
|
|
Loading…
Reference in a new issue