Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import praw
- import time
- import random
- import sys
- #Settings
- topcount=20 #Show top x posts
- subreddit="theredpill"
- post_subreddit="theredpill"
- #Bot information
- author="/u/lixaxil"
- botname="top20bot"
- version=0.01
- user_name="CHANGE_THIS_VALUE_TO_A_VALID_REDDIT_USERNAME"
- passwd="CHANGE_THIS_TO_THE_PASSWORD"
- user_agent="%s v%s by %s"%(botname,round(version,2),author)
- #Time constants
- t_min=60
- t_hour=60*t_min
- t_day=24*t_hour
- t_month=30*t_day
- #To prevent bot from spamming reddit
- returnlimit=1000
- max_age=t_month
- timestamp=time.time()
- r=praw.Reddit(user_agent=user_agent)
- r.login(username=user_name,password=passwd)
- sr=r.get_subreddit(subreddit)
- latest_posts=sr.get_new(limit=returnlimit)
- post_list=[]
- for post in latest_posts:
- if post.created+max_age > timestamp:
- score=post.ups-post.downs
- url=post.url
- title=post.title
- post_list.append((score,title,url))
- else:
- break
- body=""
- best_posts=sorted(post_list,key=lambda x:-x[0])[:topcount]
- for c,title,url in best_posts:
- body+="* [%s](%s)\n"%(title,url)
- body+=""
- body+="This post was automatically created at %i by %s"%(timestamp,user_agent)
- r.submit(post_subreddit,"Top %i posts this month (%i)"%(topcount,timestamp),text=body)
- print body
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement