/
drawMeBot.py
executable file
·57 lines (37 loc) · 1.39 KB
/
drawMeBot.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
56
57
#!/usr/bin/python3.8
import tweepy
import logging
from config import create_api
from resources.drawImage import drawImage
import matplotlib.pyplot as plot
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
def tweet_image(api):
tweet_message = "Tweet message goes here!!"
image_path = get_profile_picture_path(api)
image = drawImage(image_path)
# save image to temp file
plot.imsave('temp.png', image, cmap='gray', vmin=0, vmax=255)
media_list = get_image(api)
# send tweet with image
#api.update_status(status=tweet_message, media_ids=media_list)
logger.info("Tweet sent successfully! :) ")
def get_profile_picture_path(api):
user = api.me()
# should we use profile_image_url or profile_image_url_https?
image_path = user.profile_image_url_https
# original image path is the above with "_normal" removed from the url
original_image_path = image_path.replace('_normal', '')
logger.info(f"image url: {original_image_path}")
return original_image_path
def get_image(api):
media_list = list()
# read image from temp file (probably a better way to do this)
response = api.media_upload("temp.png")
media_list.append(response.media_id_string)
return media_list
def main():
api = create_api()
tweet_image(api)
if __name__ == "__main__":
main()