-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_keywords.py
executable file
·56 lines (45 loc) · 1.56 KB
/
search_keywords.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
#!/usr/bin/python
import sys
import time
# ------------------------------------------------------------------------------------
# Args
# type (string) : people, events, or places
# search_term (string) : search term that we're looking for in the keywords
# keyword_file (string) : filename on the web server where can find find a list of keywords
#
# Limit our search to sub-category of keywords based on "type" argument. Within that subset,
# return a list of all keywords that contain the search term somewhere within the keyword.
# The search is case-insenstive
def search_keywords(type, search_term, keyword_file):
PlacesList = [];
EventsList = [];
PeopleList = [];
ArtistsList = [];
matching_keywords = [];
f=open(keyword_file, 'r');
for keyword in f:
keyword = keyword.rstrip();
if (keyword.startswith("L:")):
PlacesList.append(keyword);
elif (keyword.startswith("E:")):
EventsList.append(keyword);
elif (keyword.startswith("A:")):
ArtistsList.append(keyword);
else:
PeopleList.append(keyword);
f.close();
if (type == "people"):
all_keywords = PeopleList
elif (type == "events"):
all_keywords = EventsList
elif (type == "places"):
all_keywords = PlacesList
elif (type == "artists"):
all_keywords = ArtistsList;
for keyword in all_keywords:
sys.stderr.write('Keyword = ' + keyword + '\n');
if (keyword.lower().find(search_term.lower()) > -1):
matching_keywords.append(keyword)
sys.stderr.write('\n');
return matching_keywords
# -------------------------------------- End -----------------------------------------