-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Reddit auto posting and commenting
- Loading branch information
1 parent
9639c51
commit 72d4e89
Showing
3 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# secrets | ||
*.pem* | ||
.password | ||
*.log | ||
praw.ini | ||
aws_login.sh | ||
|
||
# playground notebooks | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
"""Automatically post to Reddit when new README graphics are made.""" | ||
|
||
import logging | ||
import time | ||
|
||
import fastf1 as f | ||
import praw | ||
|
||
from f1_visualization._consts import CURRENT_SEASON, ROOT_PATH | ||
from f1_visualization.preprocess import get_last_round_number | ||
|
||
logging.basicConfig(level=logging.INFO, format="%(levelname)s\t%(filename)s\t%(message)s") | ||
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") | ||
formula1_flairs = r_formula1.flair.link_templates.user_selectable() | ||
f1technical_flairs = r_f1technical.flair.link_templates.user_selectable() | ||
formula1_flair_id = next( | ||
flair for flair in formula1_flairs if "Statistics" in flair["flair_text"] | ||
)["flair_template_id"] | ||
f1technical_flair_id = next( | ||
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() |