-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
110 lines (93 loc) · 3.52 KB
/
app.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
import random
import os
import re
import sys
import datetime
import tweepy
def create_insult(usernames=None):
nouns = ["team","bracket",
"strategy","free throw percent",
"point guard","mascot","t-shirt cannon","coach",
"basketball",
"shot clock","pair of tube socks",
"ability to jump","dribble"]
adjectives = ["stinky",
"dastardly",
"Machiavellian",
"serpentine",
"pseudorandom",
"outside the margin of error",
"full of eels",
"a hamster",
"the worst",
"chopped liver",
"a rampallion",
"a pile of deceased ferrets",
"a scurvy landlubber",
"as loathsome as a toad",
"a rotten banana",
"temporarily out of service",
"kaput",
"a shipment of improperly aged cheese",
"rotten in the state of Denmark",
"not going to space today",
"tripe",
"jello",
"a load of malarkey",
"so 1999",
"puce",
"actually 3 kindergarteners in a trenchcoat",
"Kafkaesque",
"not statistically significant",
"SAD",
"fake news",
"under investigation by the FBI",
"zeroed out in the budget",
"sorted into Slytherin"
]
noun = random.choice(nouns)
adj = random.choice(adjectives)
if usernames:
insult = "{names}, your {noun} is {adjective}. #marchmadness #trashtalk".format(names=usernames,noun=noun,adjective=adj)
else:
insult = "Your {noun} is {adjective}. #marchmadness #trashtalk".format(noun=noun,adjective=adj)
return insult
def get_mentions(api):
mentions = api.mentions_timeline(count=50)
return mentions
def get_usernames(tweet,botname):
usernames = [u.lower() for u in re.findall(r'@[a-zA-Z0-9_]*',tweet)]
if botname in usernames:
usernames.remove(botname)
return usernames
minutes_since_last_run = int(sys.argv[1])
now = datetime.datetime.utcnow()
time_of_last_run = now - datetime.timedelta(minutes=minutes_since_last_run)
CONSUMER_KEY = os.environ.get("CONSUMER_KEY")
CONSUMER_SECRET = os.environ.get("CONSUMER_SECRET")
ACCESS_KEY = os.environ.get("ACCESS_KEY")
ACCESS_SECRET = os.environ.get("ACCESS_SECRET")
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
mentions = get_mentions(api)
mention_ids = []
botname = "@trashtalkbot"
for m in mentions:
username = m.author.screen_name
if username.lower() != botname:
mention_id = m.id
mention_ids.append(m.id)
all_names = get_usernames(m.text,botname)
all_names.insert(0,"@"+username)
usernames = " ".join(all_names)
tweet_create_time = m.created_at
insult = create_insult(usernames)
#prevents tweeting if there's no start time
#to prevent repeated spamming
if tweet_create_time > time_of_last_run:
api.update_status(status = insult, in_reply_to_status_id=mention_id)
if random.random() < .2:
#randomly insult no one one out of 5 times
insult = create_insult()
api.update_status(status=insult)