-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter_utils.py
55 lines (38 loc) · 1.5 KB
/
twitter_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from twitter import Api
import yaml
import os
import sys
from dotenv import load_dotenv
def _get_api():
load_dotenv()
return Api(consumer_key = os.getenv('app_key'),
consumer_secret = os.getenv('app_secret'),
access_token_key = os.getenv('oauth_token'),
access_token_secret = os.getenv('oauth_token_secret') )
#print (api.VerifyCredentials())
def _post_misc_msg():
api = _get_api()
status = api.PostUpdate('testing from twitter_utils.py')
def _post_misc_img():
api = _get_api()
print("getapi done")
status = api.PostUpdate('testing photo post from twitter_utils.py', media = "bounded.jpg")
def _post_update(num_people, image_raw, image_bounded):
print ('uploading to twitter...')
#print ('image_raw-{:s}, bounded-{:s}'.format(image_raw, image_bounded))
api = _get_api()
# TODO - upload multiple photos
if(num_people == 0):
tweet_body = 'nobody taking selfies in #DUMBO right now :('
elif(num_people == 1):
tweet_body = '1 person taking a selfie in #DUMBO right now'
else:
tweet_body = ( str(num_people) + ' people taking selfies in #DUMBO right now' )
status = api.PostUpdate(tweet_body, media = image_bounded, latitude='40.7034973', longitude='-73.9898414')
# TODO - check status of upload
print ('upload complete!')
def main():
# main() is not intended to run directly, it's used to unit-test uploading to Twitter
_post_misc_msg()
if __name__== "__main__":
main()