1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

logging stuff as always

This commit is contained in:
Steffo 2018-09-19 00:02:39 +02:00
parent 05552c14e3
commit bf5debbda6
6 changed files with 36 additions and 31 deletions

38
bots.py
View file

@ -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()

13
db.py
View file

@ -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"]

View file

@ -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)

View file

@ -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)

View file

@ -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()

View file

@ -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)