-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
117 lines (105 loc) · 3.83 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import tweepy
from os.path import join, dirname
from dotenv import load_dotenv
import os
from deta import Deta
load_dotenv(join(dirname(__file__), '.env'))
twitter_auth_keys = {
"consumer_key" : os.environ.get("TSHIRT_BOT_CONSUMER_KEY"),
"consumer_secret" : os.environ.get("TSHIRT_BOT_CONSUMER_SECRET"),
"access_token" : os.environ.get("TSHIRT_BOT_ACCESS_TOKEN"),
"access_token_secret" : os.environ.get("TSHIRT_BOT_ACCESS_TOKEN_SECRET")
}
auth = tweepy.OAuthHandler(
twitter_auth_keys['consumer_key'],
twitter_auth_keys['consumer_secret']
)
auth.set_access_token(
twitter_auth_keys['access_token'],
twitter_auth_keys['access_token_secret']
)
api = tweepy.API(auth)
deta = Deta(os.environ.get("DETA_KEY"))
done_comments = deta.Base("done_comments")
statuses = api.mentions_timeline(count = 200)
statuses.reverse()
comment_id = ""
status_id = ""
comment_screen_name = ""
product_type = "tshirt"
tweet_it = False
for status in statuses:
p = done_comments.fetch({"value": status.id_str})
if p.count != 0:
continue
try:
if status.in_reply_to_screen_name =="TurnTweetInto" or status.in_reply_to_screen_name == "abdou_hll":
done_comments.put(status.id_str)
continue
full_status = api.get_status(id=status.id_str, tweet_mode = "extended" )
full_in_replay_status = api.get_status(id=status.in_reply_to_status_id_str, tweet_mode = "extended" )
except:
done_comments.put(status.id_str)
continue
op = full_status.full_text[full_status.display_text_range[0]:full_status.display_text_range[1]]
if '@turntweetinto' not in op.lower():
done_comments.put(status.id_str)
continue
#t-shirt | mug | totebag | hoodie | sweatshirt | hat | image
if 'tshirt' in op or 't-shirt' in op:
product_type = "tshirt"
elif 'hoodie' in op:
product_type = "hoodie"
elif 'sweatshirt' in op:
product_type = "sweatshirt"
elif 'mug' in op:
product_type = "mug"
elif 'totebag' in op:
product_type = "totebag"
elif 'hat' in op:
product_type = "hat"
comment_id = status.id_str
status_id = status.in_reply_to_status_id_str
comment_screen_name = status.author.screen_name
tweet_it = True
break
if not tweet_it:
statuses = api.search_tweets("@MakeItAQuote",result_type = "recent",count=200)
statuses.reverse()
for status in statuses:
p = done_comments.fetch({"value": status.id_str})
if p.count != 0:
continue
try:
if status.in_reply_to_screen_name =="TurnTweetInto" or status.in_reply_to_screen_name == "abdou_hll":
done_comments.put(status.id_str)
continue
full_status = api.get_status(id=status.id_str, tweet_mode = "extended" )
full_in_replay_status = api.get_status(id=status.in_reply_to_status_id_str, tweet_mode = "extended" )
except:
done_comments.put(status.id_str)
continue
if '@MakeItAQuote' not in full_status.full_text[full_status.display_text_range[0]:full_status.display_text_range[1]]:
done_comments.put(status.id_str)
continue
comment_id = status.id_str
status_id = status.in_reply_to_status_id_str
comment_screen_name = status.author.screen_name
tweet_it = True
break
query = ""
if 'tshirt' == product_type:
urll = f"https://www.turntweetinto.com/clothes/{status_id}?type=t_shirt"
elif 'hoodie' == product_type:
urll = f"https://www.turntweetinto.com/clothes/{status_id}?type=hoodie"
elif 'sweatshirt' == product_type:
urll = f"https://www.turntweetinto.com/clothes/{status_id}?type=s_shirt"
elif 'mug' == product_type:
urll = f"https://www.turntweetinto.com/accessories/{status_id}?type=mug"
elif 'totebag' == product_type:
urll = f"https://www.turntweetinto.com/accessories/{status_id}?type=totebag"
elif 'hat' == product_type:
urll = f"https://www.turntweetinto.com/clothes/{status_id}?type=hat"
if tweet_it :
api.update_status(status=f'@{comment_screen_name}\n{urll}', in_reply_to_status_id = comment_id)
done_comments.put(comment_id)