· 7 years ago · Jan 24, 2018, 09:32 PM
1# Importing the module
2from twython import Twython
3
4import os
5import glob
6import sys
7
8newest = max(glob.iglob('www/html/snaps/*'), key=os.path.getctime)
9
10#Setting these as variables will make them easier for future edits
11app_key = "[REDACTED]"
12app_secret = [REDACTED]"
13oauth_token = "[REDACTED]"
14oauth_token_secret = "[REDACTED]"
15
16#Prepare your twitter, you will need it for everything
17twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
18#The above should just be a single line, without the break
19
20#The obligatory first status update to test
21
22upl = open(newest, 'rb')
23
24if newest.endswith('.mp4'):
25 sys.stdout.write("Uploading Video - ")
26 response = twitter.upload_video(media=upl, media_type='video/mp4')
27else:
28 response = twitter.upload_media(media=upl)
29 sys.stdout.write("Uploading Image - ")
30
31twitter.update_status(status='', media_ids=[response['media_id']])
32sys.stdout.write("Posted " + newest)