-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
lovihatibot.py
85 lines (70 loc) · 2.54 KB
/
lovihatibot.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
#!/usr/bin/env python
"""
Find examples of "I love/hate the word X" on Twitter and
add them to Wordnik word lists.
"""
import word_tools
from lovihatibot_secrets import CONSUMER_KEY, CONSUMER_SECRET, OAUTH_SECRET, OAUTH_TOKEN
# Optional, http://stackoverflow.com/a/1557906/724176
try:
import timing
assert timing # silence warnings
except ImportError:
pass
love_max_id, hate_max_id = 0, 0
STUFF = [
["I love the word", "I hate the word"], # search term
[love_max_id, hate_max_id],
["twitter-loves", "twitter-hates"], # Wordnik word list permalink
]
# "I love the word X" or "X is my favourite new word"?
TARGET_WORD_FOLLOWS_SEARCH_TERM = True
if __name__ == "__main__":
parser = word_tools.do_argparse(
'Find examples of "I love/hate the word X" '
"on Twitter and add them to Wordnik word lists."
)
parser.add_argument(
"-i",
"--ini",
default="/Users/hugo/Dropbox/bin/data/lovihatibot.ini",
help="INI file location for storing last Twitter ID checked",
)
parser.add_argument(
"-c",
"--csv",
default="/Users/hugo/Dropbox/bin/data/lovihatibot.csv",
help="CSV file location for storing matching tweets",
)
parser.add_argument(
"-n",
"--dry-run",
action="store_true",
help="Don't save CSV, INI or update Wordnik",
)
args = parser.parse_args()
word_tools.TEST_MODE = args.dry_run
word_tools.init_twitter(OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET)
STUFF = word_tools.load_ini(args.ini, STUFF) # updates STUFF[1]
for i, search_term in enumerate(STUFF[0]):
STUFF[1][i], results = word_tools.get_words_from_twitter(
search_term, STUFF[1][i]
)
words = word_tools.find_words(
search_term, TARGET_WORD_FOLLOWS_SEARCH_TERM, results, args.csv
)
if not args.dry_run:
word_tools.add_to_wordnik(words, STUFF[2][i])
tweet_prefix = STUFF[0][i].replace("I ", "Tweeters ")
if "love" in STUFF[0][i]:
tweet_prefix = "\u2665 " + tweet_prefix # heart
else:
tweet_prefix = "\u2020 " + tweet_prefix # dagger
if args.tweet == "random":
from random import choice
# exclude none and random:
args.tweet = choice(word_tools.TWEET_CHOICES[1:-2])
print("Random tweet type:" + args.tweet)
word_tools.tweet_those(words, tweet_prefix, args.csv, search_term, args.tweet)
word_tools.save_ini(args.ini, STUFF)
# End of file