This commit is contained in:
wassname
2020-04-10 13:26:39 +08:00
parent 3f614555d2
commit 7d4cdbf7e8
+8 -59
View File
@@ -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__":