daily pastebin goal
71%
SHARE
TWEET

Untitled

a guest Mar 20th, 2017 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from apscheduler.schedulers.blocking import BlockingScheduler
  2. import praw
  3. from datetime import datetime,date
  4.  
  5. sched = BlockingScheduler()
  6.  
  7. def postit():
  8.     reddit = praw.Reddit(client_id='reddit_app_id',
  9.                         client_secret='reddit_client_secret',
  10.                         password='reddit_password',
  11.                         user_agent='your custom user agent',
  12.                         username='reddit_username')
  13.     reditor = reddit.redditor('target_redditor')
  14.     file = open('response.txt', 'r')
  15.     for submission in reditor.submissions.hot(limit=5):
  16.         post_date=datetime.fromtimestamp(submission.created).strftime('%Y-%m-%d')
  17.         current_date=date.today()
  18.         if str(post_date) == str(current_date):
  19.             print "Commenting...."
  20.             submission.reply(file.read())
  21.             print "Commented!"
  22.             break
  23.            
  24. def testit():
  25.     reddit = praw.Reddit(client_id='reddit_app_id',
  26.                         client_secret='reddit_app_secret',
  27.                         password='reddit_password',
  28.                         user_agent='your custom user agent',
  29.                         username='reddit_username')
  30.     subredit = reddit.subreddit('target_subreddit')
  31.     file = open('response.txt', 'r')
  32.     for submission in subredit.hot(limit=15):
  33.         submission.reply(file.read())
  34.         print "commented"
  35.         break
  36.                        
  37. '''@sched.scheduled_job('interval', seconds=60)
  38. def timed_job():
  39.     print "testing"
  40.     testit()'''
  41.  
  42. @sched.scheduled_job('cron', hour='9,21')
  43. def scheduled_job():
  44.     postit()
  45.  
  46. sched.start()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top