-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate_lectures.py
More file actions
31 lines (25 loc) · 931 Bytes
/
update_lectures.py
File metadata and controls
31 lines (25 loc) · 931 Bytes
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
import os.path
import requests
import sys
import time
import util
DRIVE_URL = "https://drive.google.com/uc?export=download&id={file_id}"
PATH = "lectures/{year_name}/{file_name}"
lectures = util.get_lectures_by_year()
for year in lectures:
for lecture in lectures[year]:
if "link" not in lecture or len(lecture["link"]) == 0:
continue
file_name = lecture["link"][lecture["link"].rfind("/")+1:]
x, y = lecture["year"].split("-")[-2:]
year_name = x[-2:]+y[-2:]
os.makedirs(PATH.format(year_name=year_name, file_name=''), exist_ok=True)
my_path = PATH.format(year_name=year_name, file_name=file_name)
if not os.path.isfile(my_path):
time.sleep(2)
print("Downloading {} ".format(file_name), end='')
sys.stdout.flush()
r = requests.get(DRIVE_URL.format(file_id=lecture["google_drive_id"]))
with open(my_path, "wb") as f:
f.write(r.content)
print("-- OK")