From bf5debbda6e4393440432f987e8f9c58c7640a5d Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 19 Sep 2018 00:02:39 +0200 Subject: [PATCH] logging stuff as always --- bots.py | 38 +++++++++++++++++++------------------- db.py | 13 +++++++++---- discordbot.py | 2 +- redditbot.py | 2 +- statsupdater.py | 10 +++++----- telegrambot.py | 2 +- 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/bots.py b/bots.py index 721994c1..3467eb36 100644 --- a/bots.py +++ b/bots.py @@ -7,7 +7,7 @@ import time import logging import coloredlogs -logging.lastResort = None +logging.getLogger().disabled = True logger = logging.getLogger(__name__) coloredlogs.install(level="DEBUG", logger=logger) @@ -18,50 +18,50 @@ reddit = multiprocessing.Process(target=redditbot.process, daemon=True) stats = multiprocessing.Process(target=statsupdater.process, daemon=True) if __name__ == "__main__": - logging.info("Starting Discord Bot process...") + logger.info("Starting Discord Bot process...") discord.start() - logging.info("Starting Telegram Bot process...") + logger.info("Starting Telegram Bot process...") telegram.start() - logging.info("Starting Reddit Bot process...") + logger.info("Starting Reddit Bot process...") reddit.start() - logging.info("Starting StatsUpdater process...") + logger.info("Starting StatsUpdater process...") stats.start() try: while True: if discord.exitcode is not None: - logging.warning(f"Discord Bot exited with {discord.exitcode}") + logger.warning(f"Discord Bot exited with {discord.exitcode}") del discord - logging.info("Restarting Discord Bot process...") + logger.info("Restarting Discord Bot process...") discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True) discord.start() if telegram.exitcode is not None: - logging.warning(f"Telegram Bot exited with {telegram.exitcode}") + logger.warning(f"Telegram Bot exited with {telegram.exitcode}") del telegram telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],), daemon=True) - logging.info("Restarting Telegram Bot process...") + logger.info("Restarting Telegram Bot process...") telegram.start() if reddit.exitcode is not None: - logging.warning(f"Reddit Bot exited with {reddit.exitcode}") + logger.warning(f"Reddit Bot exited with {reddit.exitcode}") del reddit reddit = multiprocessing.Process(target=redditbot.process, daemon=True) - logging.info("Restarting Reddit Bot process...") + logger.info("Restarting Reddit Bot process...") reddit.start() if stats.exitcode is not None: - logging.warning(f"StatsUpdater exited with {stats.exitcode}") + logger.warning(f"StatsUpdater exited with {stats.exitcode}") del stats stats = multiprocessing.Process(target=statsupdater.process, daemon=True) - logging.info("Restarting StatsUpdater process...") + logger.info("Restarting StatsUpdater process...") stats.start() time.sleep(10) except KeyboardInterrupt: - logging.info("Now stopping...") - logging.info("Asking Discord process to stop...") + logger.info("Now stopping...") + logger.info("Asking Discord process to stop...") discord_telegram_pipe[0].send("stop") - logging.info("Waiting for Discord Bot process to stop...") + logger.info("Waiting for Discord Bot process to stop...") discord.join() - logging.info("Waiting for Telegram Bot process to stop...") + logger.info("Waiting for Telegram Bot process to stop...") telegram.join() - logging.info("Waiting for Reddit Bot process to stop...") + logger.info("Waiting for Reddit Bot process to stop...") reddit.join() - logging.info("Waiting for StatsUpdater process to stop...") + logger.info("Waiting for StatsUpdater process to stop...") stats.join() diff --git a/db.py b/db.py index 9a1b1fc3..7939eea8 100644 --- a/db.py +++ b/db.py @@ -1,4 +1,6 @@ import datetime +import logging + from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, relationship, joinedload from sqlalchemy.ext.hybrid import hybrid_property @@ -587,16 +589,19 @@ class Overwatch(Base): try: j = r.json()["eu"]["stats"].get("competitive") if j is None: - raise RequestError("Something went wrong when retrieving the stats.") + logging.debug(f"No stats for {repr(self)}, skipping...") + return if not j["game_stats"]: - raise RequestError("Something went wrong when retrieving the stats.") + logging.debug(f"No stats for {repr(self)}, skipping...") + return j = j["overall_stats"] except TypeError: - raise RequestError("Something went wrong when retrieving the stats.") + logging.debug(f"No stats for {repr(self)}, skipping...") + return try: self.icon = re.search(r"https://.+\.cloudfront\.net/game/unlocks/(0x[0-9A-F]+)\.png", j["avatar"]).group(1) except AttributeError: - pass + logging.debug(f"No icon available for {repr(self)}.") self.level = j["prestige"] * 100 + j["level"] self.rank = j["comprank"] diff --git a/discordbot.py b/discordbot.py index cb25189a..996d9c09 100644 --- a/discordbot.py +++ b/discordbot.py @@ -20,7 +20,7 @@ import datetime import sqlalchemy.exc import coloredlogs -logging.lastResort = None +logging.getLogger().disabled = True logger = logging.getLogger(__name__) coloredlogs.install(level="DEBUG", logger=logger) diff --git a/redditbot.py b/redditbot.py index 34ccc75f..a23d4cc3 100644 --- a/redditbot.py +++ b/redditbot.py @@ -13,7 +13,7 @@ import coloredlogs config = configparser.ConfigParser() config.read("config.ini") -logging.lastResort = None +logging.getLogger().disabled = True logger = logging.getLogger(__name__) coloredlogs.install(level="DEBUG", logger=logger) diff --git a/statsupdater.py b/statsupdater.py index f11fb25e..62a20068 100644 --- a/statsupdater.py +++ b/statsupdater.py @@ -9,7 +9,7 @@ import telegram import sys import coloredlogs -logging.lastResort = None +logging.getLogger().disabled = True logger = logging.getLogger(__name__) coloredlogs.install(level="DEBUG", logger=logger) @@ -71,16 +71,16 @@ def process(): update_block(session.query(db.Steam).all()) session.commit() logger.info("Now updating Dota data.") - update_block(session.query(db.Dota).all(), delay=1, change_callback=new_dota_rank) + update_block(session.query(db.Dota).all(), delay=5, change_callback=new_dota_rank) session.commit() logger.info("Now updating League of Legends data.") - update_block(session.query(db.LeagueOfLegends).all(), delay=0.3, change_callback=new_lol_rank) + update_block(session.query(db.LeagueOfLegends).all(), delay=5, change_callback=new_lol_rank) session.commit() logger.info("Now updating osu! data.") - update_block(session.query(db.Osu).all(), delay=0.3) + update_block(session.query(db.Osu).all(), delay=5) session.commit() logger.info("Now updating Overwatch data.") - update_block(session.query(db.Overwatch).all(), delay=1) + update_block(session.query(db.Overwatch).all(), delay=5) session.commit() diff --git a/telegrambot.py b/telegrambot.py index 688a32cc..52bdd329 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -24,7 +24,7 @@ try: except Exception: model = None -logging.lastResort = None +logging.getLogger().disabled = True logger = logging.getLogger(__name__) coloredlogs.install(level="DEBUG", logger=logger)