Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tweepy
- import requests
- from datetime import datetime
- import time
- import functools
- import praw
- import random
- count = 1
- memenumber = random.randint(1, 99999999999)
- CONSUMER_KEY = "***"
- CONSUMER_SECRET = "***"
- ACCESS_KEY = "***"
- ACCESS_SECRET = "***"
- reddit = praw.Reddit(
- client_id='***',
- client_secret='***',
- username='***',
- password='***',
- user_agent='Dank Memes Bot 0.1')
- def download_image():
- while True:
- try:
- image = requests.get(newmeme).content
- except requests.RequestError:
- print("Retrying downloading")
- time.sleep(2 * 60)
- else:
- break
- with open('image.jpg', 'wb') as f:
- f.write(image)
- print("Download done.")
- def upload_image():
- while True:
- try:
- twitter_API.update_with_media(
- "image.jpg", status="dankmeme #dank #memes #{}".format(memenumber))
- except tweepy.TweepError:
- print("Retrying uploading")
- time.sleep(2 * 60)
- else:
- break
- newmeme = "null"
- while True:
- subreddit = reddit.subreddit('dankmemes')
- for submission in subreddit.rising(limit=1):
- temp = submission.url
- if temp != newmeme:
- newmeme = temp
- auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
- auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
- twitter_API = tweepy.API(auth)
- download_image()
- upload_image()
- print("Image #{} successfully uploaded at {:%H:%M}".format(count, datetime.now()))
- count = count + 1
- time.sleep(1800)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement