From f3fb0fa2e248a8d9fe7b66cc1e5b3249f7d46d44 Mon Sep 17 00:00:00 2001 From: Casper Guo Date: Sun, 24 Nov 2024 23:48:19 -0500 Subject: [PATCH] Post submission working --- pyproject.toml | 2 +- reddit_machine.py | 82 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a055582..102b936 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ build-backend = "setuptools.build_meta" packages = ["f1_visualization"] [tool.ruff] -include = ["f1_visualization/*.py", "app.py"] +include = ["f1_visualization/*.py", "./*.py"] line-length = 96 indent-width = 4 diff --git a/reddit_machine.py b/reddit_machine.py index 39c32e0..5dbb5cb 100644 --- a/reddit_machine.py +++ b/reddit_machine.py @@ -1,10 +1,9 @@ """Automatically post to Reddit when new README graphics are made.""" import logging -from pathlib import Path +import time import fastf1 as f -import tomli import praw from f1_visualization._consts import CURRENT_SEASON, ROOT_PATH @@ -14,7 +13,11 @@ logger = logging.getLogger(__name__) +VISUALS_PATH = ROOT_PATH / "Docs" / "visuals" + + def main(): + """Submit posts and make one comment.""" reddit = praw.Reddit("armchair-strategist") r_formula1 = reddit.subreddit("formula1") r_f1technical = reddit.subreddit("f1technical") @@ -27,6 +30,81 @@ def main(): flair for flair in f1technical_flairs if "Strategy" in flair["flair_text"] )["flair_template_id"] + session = f.get_session(CURRENT_SEASON, get_last_round_number(), "R") + session.load(telemetry=False, weather=False, messages=False) + event_name = f"{session.event['EventName']} - {session.name}" + + images = [ + { + "image_path": VISUALS_PATH / "strategy.png", + "caption": "Tyre strategy recap. Check out more at armchair-strategist.dev!", + }, + { + "image_path": VISUALS_PATH / "podium_gap.png", + "caption": ( + "Podium finishers' gaps to winners. " + "Check out more at armchair-strategist.dev!" + ), + }, + { + "image_path": VISUALS_PATH / "position.png", + "caption": "Race position history. Check out more at armchair-strategist.dev!", + }, + { + "image_path": VISUALS_PATH / "laptime.png", + "caption": "Point finishers' lap times. Check out more at armchair-strategist.dev!", + }, + { + "image_path": VISUALS_PATH / "team_pace.png", + "caption": "Team pace ranking. Check out more at armchair-strategist.dev!", + }, + { + "image_path": VISUALS_PATH / "teammate_violin.png", + "caption": ( + "Driver pace ranking (teammates vs teammates). " + "Check out more at armchair-strategist.dev!" + ), + }, + { + "image_path": VISUALS_PATH / "driver_pace.png", + "caption": ( + "Driver pace ranking (finishing order). " + "Check out more at armchair-strategist.dev!" + ), + }, + ] + + formula1_post = r_formula1.submit_gallery( + title=f"{event_name} Strategy & Performance Recap", + images=images, + flair_id=formula1_flair_id, + ) + formula1_post.reply( + ( + "What other graphics do you want to see and " + "how can these existing graphics be improved, quesion." + ) + ) + logger.info("Finished posting to r/formula1") + + time.sleep(5) + + f1technical_post = r_f1technical.submit_gallery( + title=f"{event_name} Strategy & Performance Recap", + images=images, + flair_id=f1technical_flair_id, + ) + f1technical_post.reply( + ( + "Check out the interactive version of these graphics and more " + "at my [strategy dashboard](https://armchair-strategist.dev/)" + "\n\n" + "Please let me know if you have suggestions for improving these graphics " + "or ideas for other graphics!" + ) + ) + logger.info("Finished posting to r/f1technical") + if __name__ == "__main__": main()