Issues (3)

nixibot.py (1 issue)

1
#!/usr/bin/env python
2
"""
3
Find examples of "X is not/isn't/ain't a word" on Twitter and
4
add them to Wordnik word lists.
5
"""
6
import word_tools
7
8
# Optional, http://stackoverflow.com/a/1557906/724176
9
try:
10
    import timing
11
    assert timing  # silence warnings
12
except ImportError:
13
    pass
14
15
# Twitter: create an app at https://dev.twitter.com/apps/new
16
CONSUMER_KEY = "TODO_ENTER_YOURS_HERE"
17
CONSUMER_SECRET = "TODO_ENTER_YOURS_HERE"
18
OAUTH_TOKEN = "TODO_ENTER_YOURS_HERE"
19
OAUTH_SECRET = "TODO_ENTER_YOURS_HERE"
20
21
isnot_max_id, isnt_max_id, aint_max_id = 0, 0, 0
22
STUFF = [
23
    ["ain't a word", "isn't a word", "is not a word"],  # search term
24
    [aint_max_id, isnt_max_id, isnot_max_id],
25
    # Wordnik word list permalink:
26
    ["twitter-aints", "twitter-isnts", "twitter-isnots", ]
27
    ]
28
29
# e.g. "I love the word X" (True) or "X is my favourite new word" (False)?
30
TARGET_WORD_FOLLOWS_SEARCH_TERM = False
31
32
# Test mode doesn't actually save csv, ini or update Wordnik
33
TEST_MODE = True
34
35 View Code Duplication
if __name__ == '__main__':
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
36
    # args = word_tools.do_argparse()
37
    parser = word_tools.do_argparse(
38
        "Find examples of \"X is not/isn't/ain't "
39
        "a word\" on Twitter and add them to Wordnik word lists.")
40
    parser.add_argument(
41
        '-i', '--ini',
42
        default='/Users/hugo/Dropbox/bin/data/nixibot.ini',
43
        help='INI file location for storing last Twitter ID checked')
44
    parser.add_argument(
45
        '-c', '--csv',
46
        default='/Users/hugo/Dropbox/bin/data/nixibot.csv',
47
        help='CSV file location for storing matching tweets')
48
    args = parser.parse_args()
49
50
    word_tools.init_twitter(
51
        OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET)
52
    STUFF = word_tools.load_ini(args.ini, STUFF)  # updates STUFF[1]
53
54
    for i, search_term in enumerate(STUFF[0]):
55
        STUFF[1][i], results = word_tools.get_words_from_twitter(
56
            search_term, STUFF[1][i])
57
        words = word_tools.find_words(
58
            search_term, TARGET_WORD_FOLLOWS_SEARCH_TERM, results, args.csv)
59
60
        if not TEST_MODE:
61
            word_tools.add_to_wordnik(words, STUFF[2][i])
62
63
        tweet_prefix = STUFF[0][i]
64
        tweet_prefix = u"\u2260 " + tweet_prefix  # not equal to
65
66
        if args.tweet == "random":
67
            from random import choice
68
            # exclude none and random:
69
            args.tweet = choice(word_tools.TWEET_CHOICES[1:-2])
70
            print("Random tweet type:" + args.tweet)
71
72
        word_tools.tweet_those(
73
            words, tweet_prefix, args.csv, search_term, args.tweet)
74
75
        word_tools.save_ini(args.ini, STUFF)
76
77
# End of file
78