-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_actors.py
More file actions
54 lines (40 loc) · 1.5 KB
/
insert_actors.py
File metadata and controls
54 lines (40 loc) · 1.5 KB
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
import downloader
import insert
import time
all_actor_ids = set()
all_actors = []
all_people_popularity = []
START = 1
PAGES = 500
start_time = time.time()
for i in range(START, PAGES + 1):
print(f"Page {i} of {PAGES} started")
for actor in downloader.get_popular_people(i).results:
all_actor_ids.add(actor.id)
all_actors.insert(i, actor)
print(f"Page {i} of {PAGES} finished")
end_time = time.time()
print(f"Iterating through pages took {end_time - start_time} seconds to complete")
start_time = time.time()
print("Downloading popularity details")
for i, actor_ids in enumerate(all_actor_ids):
try:
all_people_popularity.append(downloader.get_person_details(actor_ids))
except Exception as e:
print(f"Could not load actor with id {actor_ids}")
print(e)
if i % 25 == 0:
print(f"{i} of {len(all_actor_ids)} loaded from API")
end_time = time.time()
print(f"Downloading details took {end_time - start_time} seconds to complete")
start_time = time.time()
print("Inserting actors into database")
insert.insert_person(all_actors)
end_time = time.time()
print(f"Inserting actors took {end_time - start_time} seconds to complete")
start_time = time.time()
print("Inserting popularity into database")
people_popularity = [PersonPopularity(person.id, person.popularity) for person in all_people_popularity]
insert.insert_person_popularity(people_popularity)
end_time = time.time()
print(f"Inserting popularity took {end_time - start_time} seconds to complete")