-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodules.py
36 lines (33 loc) · 1.22 KB
/
modules.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
# functions to be used by the routes
# retrieve all the names from the dataset and put them into a list
def get_names(source):
names = []
for row in source:
# lowercase all the names for better searching
name = row["name"].lower()
names.append(name)
return sorted(names)
# find the row that matches the id in the URL, retrieve name and photo
def get_actor(source, id):
for row in source:
if id == str( row["id"] ):
name = row["name"]
photo = row["photo"]
# change number to string
id = str(id)
# return these if id is valid
return id, name, photo
# return these if id is not valid - not a great solution, but simple
return "Unknown", "Unknown", ""
# find the row that matches the name in the form and retrieve matching id
def get_id(source, name):
for row in source:
# lower() makes the string all lowercase
if name.lower() == row["name"].lower():
id = row["id"]
# change number to string
id = str(id)
# return id if name is valid
return id
# return these if id is not valid - not a great solution, but simple
return "Unknown"