SHARE
TWEET

Untitled

a guest Apr 24th, 2019 141 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import tweepy
  2. import requests
  3. from datetime import datetime
  4. import time
  5. import functools
  6. import praw
  7. import random
  8.  
  9. count = 1
  10. memenumber = random.randint(1, 99999999999)
  11.  
  12. CONSUMER_KEY = "***"
  13. CONSUMER_SECRET = "***"
  14. ACCESS_KEY = "***"
  15. ACCESS_SECRET = "***"
  16.  
  17. reddit = praw.Reddit(
  18.     client_id='***',
  19.     client_secret='***',
  20.     username='***',
  21.     password='***',
  22.     user_agent='Dank Memes Bot 0.1')
  23.  
  24. def download_image():
  25.         while True:
  26.             try:
  27.                 image = requests.get(newmeme).content
  28.             except requests.RequestError:
  29.                 print("Retrying downloading")
  30.                 time.sleep(2 * 60)
  31.             else:
  32.                 break
  33.         with open('image.jpg', 'wb') as f:
  34.             f.write(image)
  35.         print("Download done.")
  36.  
  37. def upload_image():
  38.     while True:
  39.         try:
  40.             twitter_API.update_with_media(
  41.                 "image.jpg", status="dankmeme #dank #memes #{}".format(memenumber))
  42.         except tweepy.TweepError:
  43.             print("Retrying uploading")
  44.             time.sleep(2 * 60)
  45.         else:
  46.             break
  47.  
  48. newmeme = "null"
  49.  
  50. while True:
  51.     subreddit = reddit.subreddit('dankmemes')
  52.     for submission in subreddit.rising(limit=1):
  53.         temp = submission.url
  54.         if temp != newmeme:
  55.             newmeme = temp
  56.  
  57.     auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
  58.     auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
  59.     twitter_API = tweepy.API(auth)
  60.     download_image()
  61.     upload_image()
  62.     print("Image #{} successfully uploaded at {:%H:%M}".format(count, datetime.now()))
  63.     count = count + 1
  64.     time.sleep(1800)
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