Skip to content

Instantly share code, notes, and snippets.

@joemsak
Last active August 29, 2015 14:03
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 joemsak/4e56adeeae0fb0ff5ca9 to your computer and use it in GitHub Desktop.
Save joemsak/4e56adeeae0fb0ff5ca9 to your computer and use it in GitHub Desktop.
from twython import Twython
import time
twitter = Twython('consumer_key', 'consumer_secret', 'oauth_key', 'oauth_secret')
img = open('album_artwork.jpeg', 'rb')
filepath = 'tmp/replied_status_ids.txt'
while True:
mention = twitter.get_mentions_timeline()[0]
status_id = mention['id']
statuses = open(filepath).read() # read the file here
if str(status_id) not in statuses:
screen_name = '@' + mention['user']['screen_name']
twitter.update_status_with_media(status = screen_name,
media = img,
in_reply_to_status_id = status_id)
with open(filepath, 'a') as database: # open the file a second time for writing
database.write(str(status_id) + "\n")
else:
print 'We replied to this one already!'
time.sleep(60) # 1 minute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment