Skip to content

Commit

Permalink
Post submission working
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper-Guo committed Nov 25, 2024
1 parent 290352b commit f3fb0fa
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
82 changes: 80 additions & 2 deletions reddit_machine.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand All @@ -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()

0 comments on commit f3fb0fa

Please sign in to comment.