Steven Smith revised this gist . Go to revision
1 file changed, 27 insertions
megathread.py(file created)
| @@ -0,0 +1,27 @@ | |||
| 1 | + | #!/var/www/html/gdq/newpraw/bin/python | |
| 2 | + | import praw, json | |
| 3 | + | with open("/home/steven/gdqauth.json") as f: | |
| 4 | + | auth = json.load(f) | |
| 5 | + | ||
| 6 | + | r = praw.Reddit(user_agent='GDQ thread autoupdater by /u/suudo', refresh_token=auth["token"], **auth["login"]) | |
| 7 | + | with open("/var/www/html/gdq/schedule.json") as f: | |
| 8 | + | data = json.load(f) | |
| 9 | + | ||
| 10 | + | if not hasattr(__builtins__, "raw_input"): | |
| 11 | + | raw_input = input | |
| 12 | + | ||
| 13 | + | s = r.submission(raw_input("Enter submission ID: ")) | |
| 14 | + | comments = [] | |
| 15 | + | ||
| 16 | + | for d in data["schedule"]: | |
| 17 | + | while True: | |
| 18 | + | try: | |
| 19 | + | _ = s.reply("""**{}** run by {} [[1]]({})""".format(d["game"], ", ".join("[{}]({})".format(k,v) for k,v in d["runners"].items()), d["vod"])) | |
| 20 | + | except praw.exceptions.APIException: | |
| 21 | + | traceback.print_exc() | |
| 22 | + | continue | |
| 23 | + | break | |
| 24 | + | print("Posted {} {}".format(d["game"], _.id)) | |
| 25 | + | comments.append(("**{}** run by {}".format(d["game"], ", ".join("[{}]({})".format(k,v) for k,v in d["runners"].items())), _)) | |
| 26 | + | ||
| 27 | + | s.edit("Apologies for the false start before, we've fixed the issue!\r\n\r\nFind your favorite run below and upvote it!\r\n\r\n" + "\n".join("* {} [-->](https://reddit.com/r/{}/comments/{}/_/{})".format(d, s.subreddit.display_name, s.id, c.id) for d,c in comments )) | |
Newer
Older