-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.py
119 lines (72 loc) · 3.13 KB
/
search.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
111
112
113
114
115
116
117
118
119
import json
import pprint
from get_dynamodb import get_dynamodb
def search_all(search_input,event_types):
data = get_dynamodb("event_details")
data = json.loads(data)
list_of_related_events = []
for each_event in data:
if event_types == each_event['Type']:
if search_input in each_event['Event Title'] or search_input in each_event['Description']:
list_of_related_events.append(each_event)
return list_of_related_events
def search_title_and_description(search_input):
data = get_dynamodb("event_details")
data = json.loads(data)
list_of_related_events = []
search_input = search_input.lower() # Compare all strings with lowercases
for each_event in data:
if search_input in each_event['Event Title'].lower():
list_of_related_events.append(each_event)
elif search_input in each_event['Description'].lower():
list_of_related_events.append(each_event)
elif search_input in each_event['Type'].lower():
list_of_related_events.append(each_event)
return list_of_related_events
def filter_event_types(event_type):
data = get_dynamodb("event_details")
data = json.loads(data)
list_of_related_events = []
for each_event in data:
if event_type == each_event['Type']:
list_of_related_events.append(each_event)
return list_of_related_events
def search_by_location(search_input):
if search_input.isnumeric():
events_data = search_by_postcode(search_input)
else:
events_data = search_by_suburb(search_input)
return events_data
def search_by_postcode(search_input):
postcode_integer = int(search_input)
min_event_postcode = postcode_integer - 15
max_event_postcode = postcode_integer + 15
events_data = get_dynamodb("event_details")
events_data = json.loads(events_data)
list_of_related_events = []
for event in events_data:
event_postcode = int(event['Postcode'])
if event_postcode >= min_event_postcode and event_postcode <= max_event_postcode:
list_of_related_events.append(event)
return list_of_related_events
def search_by_suburb(search_input):
f = open('au_postcodes.json')
postcode_data = json.load(f)
# Find the postcode of the search_input
for each_suburb in postcode_data:
if each_suburb['place_name'].lower() == search_input.lower() and each_suburb['state_code'] == "NSW":
suburb_postcode = each_suburb['postcode']
if suburb_postcode is None:
return []
# Find the nearest suburbs
postcode_integer = int(suburb_postcode)
min_event_postcode = postcode_integer - 15
max_event_postcode = postcode_integer + 15
events_data = get_dynamodb("event_details")
events_data = json.loads(events_data)
list_of_related_events = []
for event in events_data:
event_postcode = int(event['Postcode'])
if event_postcode >= min_event_postcode and event_postcode <= max_event_postcode:
list_of_related_events.append(event)
return list_of_related_events