1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +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 logging
import coloredlogs import coloredlogs
logging.lastResort = None logging.getLogger().disabled = True
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
coloredlogs.install(level="DEBUG", logger=logger) 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) stats = multiprocessing.Process(target=statsupdater.process, daemon=True)
if __name__ == "__main__": if __name__ == "__main__":
logging.info("Starting Discord Bot process...") logger.info("Starting Discord Bot process...")
discord.start() discord.start()
logging.info("Starting Telegram Bot process...") logger.info("Starting Telegram Bot process...")
telegram.start() telegram.start()
logging.info("Starting Reddit Bot process...") logger.info("Starting Reddit Bot process...")
reddit.start() reddit.start()
logging.info("Starting StatsUpdater process...") logger.info("Starting StatsUpdater process...")
stats.start() stats.start()
try: try:
while True: while True:
if discord.exitcode is not None: 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 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 = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True)
discord.start() discord.start()
if telegram.exitcode is not None: 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 del telegram
telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],), daemon=True) 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() telegram.start()
if reddit.exitcode is not None: 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 del reddit
reddit = multiprocessing.Process(target=redditbot.process, daemon=True) reddit = multiprocessing.Process(target=redditbot.process, daemon=True)
logging.info("Restarting Reddit Bot process...") logger.info("Restarting Reddit Bot process...")
reddit.start() reddit.start()
if stats.exitcode is not None: if stats.exitcode is not None:
logging.warning(f"StatsUpdater exited with {stats.exitcode}") logger.warning(f"StatsUpdater exited with {stats.exitcode}")
del stats del stats
stats = multiprocessing.Process(target=statsupdater.process, daemon=True) stats = multiprocessing.Process(target=statsupdater.process, daemon=True)
logging.info("Restarting StatsUpdater process...") logger.info("Restarting StatsUpdater process...")
stats.start() stats.start()
time.sleep(10) time.sleep(10)
except KeyboardInterrupt: except KeyboardInterrupt:
logging.info("Now stopping...") logger.info("Now stopping...")
logging.info("Asking Discord process to stop...") logger.info("Asking Discord process to stop...")
discord_telegram_pipe[0].send("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() discord.join()
logging.info("Waiting for Telegram Bot process to stop...") logger.info("Waiting for Telegram Bot process to stop...")
telegram.join() telegram.join()
logging.info("Waiting for Reddit Bot process to stop...") logger.info("Waiting for Reddit Bot process to stop...")
reddit.join() reddit.join()
logging.info("Waiting for StatsUpdater process to stop...") logger.info("Waiting for StatsUpdater process to stop...")
stats.join() stats.join()

13
db.py
View file

@ -1,4 +1,6 @@
import datetime import datetime
import logging
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship, joinedload from sqlalchemy.orm import sessionmaker, relationship, joinedload
from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.ext.hybrid import hybrid_property
@ -587,16 +589,19 @@ class Overwatch(Base):
try: try:
j = r.json()["eu"]["stats"].get("competitive") j = r.json()["eu"]["stats"].get("competitive")
if j is None: 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"]: 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"] j = j["overall_stats"]
except TypeError: except TypeError:
raise RequestError("Something went wrong when retrieving the stats.") logging.debug(f"No stats for {repr(self)}, skipping...")
return
try: try:
self.icon = re.search(r"https://.+\.cloudfront\.net/game/unlocks/(0x[0-9A-F]+)\.png", j["avatar"]).group(1) self.icon = re.search(r"https://.+\.cloudfront\.net/game/unlocks/(0x[0-9A-F]+)\.png", j["avatar"]).group(1)
except AttributeError: except AttributeError:
pass logging.debug(f"No icon available for {repr(self)}.")
self.level = j["prestige"] * 100 + j["level"] self.level = j["prestige"] * 100 + j["level"]
self.rank = j["comprank"] self.rank = j["comprank"]

View file

@ -20,7 +20,7 @@ import datetime
import sqlalchemy.exc import sqlalchemy.exc
import coloredlogs import coloredlogs
logging.lastResort = None logging.getLogger().disabled = True
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
coloredlogs.install(level="DEBUG", logger=logger) coloredlogs.install(level="DEBUG", logger=logger)

View file

@ -13,7 +13,7 @@ import coloredlogs
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read("config.ini") config.read("config.ini")
logging.lastResort = None logging.getLogger().disabled = True
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
coloredlogs.install(level="DEBUG", logger=logger) coloredlogs.install(level="DEBUG", logger=logger)

View file

@ -9,7 +9,7 @@ import telegram
import sys import sys
import coloredlogs import coloredlogs
logging.lastResort = None logging.getLogger().disabled = True
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
coloredlogs.install(level="DEBUG", logger=logger) coloredlogs.install(level="DEBUG", logger=logger)
@ -71,16 +71,16 @@ def process():
update_block(session.query(db.Steam).all()) update_block(session.query(db.Steam).all())
session.commit() session.commit()
logger.info("Now updating Dota data.") 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() session.commit()
logger.info("Now updating League of Legends data.") 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() session.commit()
logger.info("Now updating osu! data.") 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() session.commit()
logger.info("Now updating Overwatch data.") 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() session.commit()

View file

@ -24,7 +24,7 @@ try:
except Exception: except Exception:
model = None model = None
logging.lastResort = None logging.getLogger().disabled = True
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
coloredlogs.install(level="DEBUG", logger=logger) coloredlogs.install(level="DEBUG", logger=logger)