-
Notifications
You must be signed in to change notification settings - Fork 47
/
tweetcounter.py
67 lines (51 loc) · 1.33 KB
/
tweetcounter.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 argparse
import tweets
from tweets import Tweet
def main(term):
"""Main function to start the program."""
print(f"The terms: {term}")
def counttweets(filename):
"""Count all the unique tweets in a file."""
count = 0
with open(filename) as file:
for line in file:
count += 1
return count
def searchterms(filename, terms=None):
"""
Search the file for a list of terms.
Parameters
----------
filename : str
The file name that points to a json file containing tweets.
terms : list
A list of strings containing search terms
Returns
-------
tweets
A list of tweet objects that have text that matches the terms
TODO
----
- Only searches the first listed term
"""
# Make terms a list if it is not
if type(terms) != list:
terms = [terms]
tweets = []
with open(filename) as file:
for line in file:
tweet = Tweet(line)
if terms[0] in tweet:
tweets.append(tweet)
return tweets
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--term",
type=str,
required=True,
help="The term to look up in theset of tweets",
)
args = parser.parse_args()
print(args)
main(args.term)