Skip to content

Instantly share code, notes, and snippets.

@scottythered
Last active February 18, 2018 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottythered/3f4f2aa553c914eb1b50b24b23da886b to your computer and use it in GitHub Desktop.
Save scottythered/3f4f2aa553c914eb1b50b24b23da886b to your computer and use it in GitHub Desktop.
from tweepy import OAuthHandler
from tweepy import API
import urllib.request
import os
import json
consumer_key = "XXXXXXXXXXX"
consumer_secret = "XXXXXXXXXXX"
access_token = "XXXXXXXXXXX"
access_token_secret = "XXXXXXXXXXX"
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = API(auth)
with open('index.txt', 'r') as indexNmr:
vari = int(indexNmr.read().strip())
json_input = open('[JSON file]')
data = json.load(json_input)
urllib.request.urlretrieve(data['tweets'][vari]['img'], 'image-temp.jpg')
filename = ('image-temp.jpg')
try:
api.update_with_media(filename, status=data['tweets'][vari]['text'])
os.remove(filename)
except:
print('Error, baby.')
with open('index.txt', 'w') as indexNew:
indexNew.write("%d" % (vari + 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment