/
post.py
36 lines (28 loc) · 1.13 KB
/
post.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
import tweepy
# Get the twitter credentials from a (hidden) file
secrets = open(".logincas")
login = secrets.readlines()
# assign the values accordingly
# strip the linebreak from the values to prevent bad login errors
consumer_key = login[0].rstrip('\n')
consumer_secret = login[1].rstrip('\n')
access_token = login[2].rstrip('\n')
access_token_secret = login[3].rstrip('\n')
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
# set access to user's access key and access secret
auth.set_access_token(access_token, access_token_secret)
# calling the api
api = tweepy.API(auth)
def post_twitter(hashtag, counter):
text = f'#{hashtag} @HaddockIsBoos, de update van vandaag\n\n \
Aantal tweets: {counter}\n \
Top 10 posters en grafische historie in de plaatjes hieronder\n'
media_ids = []
png1 = f'{hashtag}_tweet_top10.png'
png2 = f'{hashtag}_tweet_graph.png'
filenames = [png1, png2]
for filename in filenames:
res = api.media_upload(filename)
media_ids.append(res.media_id)
api.update_status(status=text, media_ids=media_ids)