update logger
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
# weekly_games_roundup.py
|
# weekly_games_roundup.py
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import argparse
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import html
|
import html
|
||||||
import json
|
import json
|
||||||
@@ -17,10 +18,26 @@ import aiohttp
|
|||||||
import jwt # PyJWT
|
import jwt # PyJWT
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from logging.handlers import RotatingFileHandler
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
import zoneinfo
|
import zoneinfo
|
||||||
|
|
||||||
LOG = logging.getLogger("weekly")
|
LOG = logging.getLogger("bot_weekly")
|
||||||
|
LOG_PATTERN = logging.Formatter("%(asctime)s:%(levelname)s: [%(filename)s] %(message)s")
|
||||||
|
|
||||||
|
def setuplogger():
|
||||||
|
stream_handler = logging.StreamHandler()
|
||||||
|
stream_handler.setFormatter(LOG_PATTERN)
|
||||||
|
stream_handler.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
file_handler = RotatingFileHandler("bot_weekly.log", "a", 1_000_000, 1)
|
||||||
|
file_handler.setFormatter(LOG_PATTERN)
|
||||||
|
|
||||||
|
LOG.setLevel(logging.DEBUG)
|
||||||
|
LOG.addHandler(stream_handler)
|
||||||
|
LOG.addHandler(file_handler)
|
||||||
|
|
||||||
|
|
||||||
TZ = zoneinfo.ZoneInfo("Europe/Brussels")
|
TZ = zoneinfo.ZoneInfo("Europe/Brussels")
|
||||||
UA = {"User-Agent": "Mozilla/5.0 (compatible; weekly-games-roundup/1.0)"}
|
UA = {"User-Agent": "Mozilla/5.0 (compatible; weekly-games-roundup/1.0)"}
|
||||||
|
|
||||||
@@ -587,12 +604,16 @@ async def run_forever_sunday_noon():
|
|||||||
|
|
||||||
# -------------------- Entrypoint --------------------
|
# -------------------- Entrypoint --------------------
|
||||||
|
|
||||||
if __name__ == "__main__":
|
async def main():
|
||||||
import argparse
|
setuplogger()
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--runonce", action="store_true", help="Run now and exit (no scheduler)")
|
parser.add_argument("--runonce", action="store_true", help="Run now and exit (no scheduler)")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.runonce:
|
if args.runonce:
|
||||||
asyncio.run(run_weekly())
|
await run_weekly()
|
||||||
else:
|
else:
|
||||||
asyncio.run(run_forever_sunday_noon())
|
await run_forever_sunday_noon()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
Reference in New Issue
Block a user