Skip to content

Instantly share code, notes, and snippets.

@git2samus
Created August 10, 2020 16:30
Show Gist options
  • Save git2samus/20b1e8291ce2c6b9ae85ea9244e87999 to your computer and use it in GitHub Desktop.
Save git2samus/20b1e8291ce2c6b9ae85ea9244e87999 to your computer and use it in GitHub Desktop.
import os
from datetime import datetime
from praw import Reddit
reddit = Reddit(**{
key: os.getenv(f"REDDIT_{key.upper()}")
for key in (
"client_id", "client_secret", "username", "password", "user_agent"
)
})
with open("reference_url.txt") as f:
reference_url = f.read()
reference_comment = reddit.comment(url=reference_url)
delta = datetime.utcnow() - datetime.fromtimestamp(reference_comment.created_utc)
with open("flair_tpl.txt") as f:
flair_tpl = f.read()
flair = flair_tpl.format(delta.days)
subreddit = reddit.subreddit("Uruguay")
for template in subreddit.flair.templates:
if template["text_editable"]:
subreddit.flair.set("Samus_", flair, flair_template_id=template["id"])
break
print(datetime.now().isoformat())
print(flair)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment