-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.py
67 lines (53 loc) · 1.99 KB
/
actions.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
58
59
60
61
62
63
64
65
66
67
# Import auxiliary functions
from utils import *
from random import choice
BOT = "kuvbot"
REPLY = "kuvrep"
def action_like_tweet():
"""Likes a random recent Tweet that contains the word(s) specified inside
the function. Prints the confirmation of action."""
api = authenticate(BOT)
search = choice(["#photograph", "#photography"])
tweet_url = like_tweet_contains(api, search, "recent")
print(
"[LIKE]:\n"
+ "Containing: "
+ search
+ "\nTweet URL: "
+ tweet_url
+ "\n=========="
)
def action_tweet_image():
"""Tweets an edited image from Unsplash with an alt text containing the
author, tag guess, confidence percentage and url. It also replies to the
Tweet with the image author's Twitter handle, if known. Prints the
confirmation of action."""
api = authenticate(BOT)
[id, color, download, url, author, handle] = get_random_image_unsplash()
[tag, confidence] = tag_url_image_imagga(download)
image_path = download_image(download, id)
edit_path = edit_image(image_path, (2000, 2000), color)
alt = (
"Author: "
+ author
+ "\nTag: "
+ tag
+ "\nConfidence: "
+ confidence
+ "\n\n"
+ url[8:]
)
tweet_id = tweet_media_metadata(api, edit_path, alt)
tweet_url = "https://twitter.com/" + BOT + "/status/" + str(tweet_id)
if isinstance(handle, str):
user_id = get_twitter_user_id(api, handle)
if isinstance(user_id, int):
text = "@" + handle
api = authenticate(REPLY)
reply_to_tweet(api, tweet_id, text)
message = (
"Hi there!\n Congratulations! A photo of yours was featured on our page and credited to you. Thank you for being part of the photography world! ❤️\n If you want us to remove your work, please let us know. "
+ tweet_url
)
dm_user(api, user_id, message)
print("[TWEET]:\n" + alt + "\n==========")