Created
January 18, 2018 18:59
-
-
Save impshum/db01bd7b034fdc299d7a4e1dca6d5df2 to your computer and use it in GitHub Desktop.
Get recent images from Reddit and post to Twitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
consumer_key = 'xxxx' | |
consumer_secret = 'xxxx' | |
access_key = 'xxxx-xxxx' | |
access_secret = 'xxxx' | |
client_id = 'xxxx' | |
client_secret = 'xxxx' | |
user_agent = 'New image posts from Reddit to twiiter (by /u/impshum)' | |
subreddits = ['comics', 'xxxx', 'xxxx'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
import praw | |
import urllib.request | |
from config import * | |
import random | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_key, access_secret) | |
api = tweepy.API(auth) | |
def redditpic(): | |
reddit = praw.Reddit(client_id=client_id, | |
client_secret=client_secret, | |
user_agent=user_agent) | |
subs = subreddits | |
subs = random.choice(subs) | |
subs = reddit.subreddit(subs).new(limit=5) | |
try: | |
for sub in subs: | |
if sub.over_18: | |
print('NSFW - Skipping') | |
else: | |
if 'i.' in sub.url: | |
urllib.request.urlretrieve(sub.url, 'data/image.jpg') | |
picci = 'data/image.jpg' | |
print('Tweeting', sub.title) | |
api.update_with_media(picci, sub.title) | |
break | |
except: | |
print('Error') | |
redditpic() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment