Configure Redis with every morning 6 AM execution

This commit is contained in:
Carlos 2024-09-30 23:02:18 -07:00
parent e5c176af7d
commit 65283fc7f9

24
app.py
View file

@ -1,15 +1,17 @@
from argparse import ArgumentParser
from config import Config as cfg
from datetime import datetime
from espn_api.football import League
from gspread_dataframe import set_with_dataframe
from huey import crontab, RedisHuey
from service import gc
from tabulate import tabulate
from time import strftime
import pandas as pd
huey = RedisHuey('report-generator', host='redis')
def check_int(s):
if s is None:
return s
@ -51,13 +53,8 @@ def write_to_google_spreadsheet(df: pd.DataFrame):
set_with_dataframe(worksheet, df)
if __name__ == "__main__":
parser = ArgumentParser(description='Weekly Report Generator for Fantasy Football')
parser.add_argument('-csv', action='store_true')
parser.add_argument('-gs', action='store_true')
args = vars(parser.parse_args())
timestamp = strftime("%Y%m%d_%H%M%S")
@huey.periodic_task(crontab(hour='6'))
def process_daily_report():
league = League(league_id=cfg.LEAGUE_ID,
year=datetime.now().year,
espn_s2=cfg.ESPN_S2,
@ -67,11 +64,4 @@ if __name__ == "__main__":
matchup = extract_matchup_box_scores(league=league)
df = pd.DataFrame.from_dict(matchup)
print(tabulate(df, headers='keys', tablefmt='psql', showindex=False))
if args['csv']:
print("Saving to CSV...")
df.to_csv(f'espn_fantasy_football_weekly_report_{timestamp}.csv', index=False, float_format='%.2f')
if args['gs']:
print("Saving to Google Sheets...")
write_to_google_spreadsheet(df=df)
write_to_google_spreadsheet(df=df)