added logging to file + fonts + .env file

This commit is contained in:
Louis Heredero 2024-09-14 12:50:58 +02:00
parent d9ae6527a1
commit 41d7dd066b
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
6 changed files with 17 additions and 3 deletions

1
.env.template Normal file
View File

@ -0,0 +1 @@
TELEGRAM_TOKEN=

View File

@ -14,13 +14,26 @@ from bs4 import BeautifulSoup
from telegram import Update from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
log_dir = os.getenv("BEEBOT_LOGS")
if not log_dir:
log_dir = "/mnt/logs"
if not os.path.exists(log_dir):
os.mkdir(log_dir)
logging.basicConfig( logging.basicConfig(
format="[%(asctime)s] %(name)s/%(levelname)s - %(message)s", format="[%(asctime)s] %(name)s/%(levelname)s - %(message)s",
level=logging.INFO level=logging.INFO,
handlers=[
logging.FileHandler(
os.path.join(
log_dir,
datetime.datetime.today().strftime("%Y%m%d-%H%M%S.log")
)
),
logging.StreamHandler()
]
) )
logging.getLogger("httpx").setLevel(logging.WARNING) logging.getLogger("httpx").setLevel(logging.WARNING)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
class BeeBot: class BeeBot:
MENU_URL = "https://www.epfl.ch/campus/restaurants-shops-hotels/fr/industrie21-epfl-valais-wallis/?date={date}" MENU_URL = "https://www.epfl.ch/campus/restaurants-shops-hotels/fr/industrie21-epfl-valais-wallis/?date={date}"
@ -142,7 +155,7 @@ class BeeBot:
def save_cache(self): def save_cache(self):
with open(self.CACHE_PATH, "w") as f: with open(self.CACHE_PATH, "w") as f:
json.dump(self.cache, f) json.dump(self.cache, f, indent=4)
@staticmethod @staticmethod
def get_img_id(today_only: bool, categories: set[str]) -> str: def get_img_id(today_only: bool, categories: set[str]) -> str:

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.