From 7d4cdbf7e8b9cbd3f196df5ad62564ce0ec2b755 Mon Sep 17 00:00:00 2001 From: wassname Date: Fri, 10 Apr 2020 13:26:39 +0800 Subject: [PATCH] tidy --- arxiv_ml_xpost_bot.py | 67 ++++++------------------------------------- 1 file changed, 8 insertions(+), 59 deletions(-) diff --git a/arxiv_ml_xpost_bot.py b/arxiv_ml_xpost_bot.py index 2d916b1..c557604 100644 --- a/arxiv_ml_xpost_bot.py +++ b/arxiv_ml_xpost_bot.py @@ -31,8 +31,8 @@ subreddits = [ # target_subreddit = r.subreddit('mlresearch') # target_subreddit = r.subreddit('testingground4bots') -SLEEP = 600 -LIMIT_CHECK = 20 +SLEEP = 60*10 +LIMIT_CHECK = 120 MIN_SECONDS = 60 * 60 MIN_SCORE = 5 @@ -43,80 +43,29 @@ if r.read_only == False: def comment(): with shelve.open('.arxiv_bot') as cache: - for subreddit in subreddits: + for j, subreddit in enumerate(subreddits): try: all_posts = subreddit.new(limit=LIMIT_CHECK) - for post in all_posts: + for i, post in enumerate(all_posts): match = ARXIV_URL_RE.search(post.url) or OPENREVIEW_URL_RE.search(post.url) ts = time.time() - post.created_utc if match and (post.score > MIN_SCORE) and (ts > MIN_SECONDS): - # arxiv_id = match.group(1) - - # crosspost - # print('found', arxiv_id) if cache.get(post.id) and cache.get(post.id) is 'T': - print("Parsed this post already: %s. %s" % (post.permalink, post.id, post.url)) + print(j, i, "Parsed this post already: %s. %s. %s" % (post.permalink, post.id, post.url)) continue else: - print("posting", post, post.url, post.permalink, post.id, post.score, ts) + print(j, i, "posting", post, post.url, post.permalink, post.id, post.score, ts) post.crosspost('researchml') # xpost(['r/researchml'], post) - cache[post.id]='T' + cache[post.id] = 'T' time.sleep(60) + time.sleep(1) except Exception as error: logger.error("Failed to scrape") print(error) -# def xpost(subs, originalpost): -# # TODO native xport -# # originalpost = where.submission -# newtitle = "(X-Post r/" + str(originalpost.subreddit.display_name) + ") " + originalpost.title -# print("New post: " + str(newtitle)) -# link = "https://www.reddit.com" + str(originalpost.permalink) -# workedsubs = [] -# failedsubs = [] -# wasError = False -# for workingsub in subs: -# exists = True -# try: -# r.subreddits.search_by_name(workingsub[2:], exact=True) -# except NotFound: -# logging.error("Failed to post") -# exists = False -# if exists == True: -# subreddit = r.subreddit(workingsub[2:]) -# try: -# submission.crosspost(subreddit) -# subreddit.submit(newtitle, url=link, resubmit=True, send_replies=False) -# workedsubs.append(str(workingsub)) -# print("Posting: " + str(newtitle) + " to " + str(workingsub)) -# except praw.exceptions.APIException: -# logging.error("Failed to post") -# wasError = True -# break -# else: -# failedsubs.append(str(workingsub)) -# if not wasError: -# print(workedsubs,failedsubs) -# # reply(workedsubs,failedsubs,where) -# pass -# else: -# response = "" -# if workedsubs: -# response = "I was able to crosspost in " -# for i in workedsubs: -# response = response + str(i) + " and " -# response = response[:-5] + ", but I was rate-limited on the others." -# print(response) -# else: -# response = "Sorry, I was rate-limited, and I couldn't post." -# print(response) -# # where.reply(str(response) + " Make sure to give me karma to prevent that in the future.") - - - if __name__ == "__main__":