-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccess.py
62 lines (53 loc) · 1.49 KB
/
access.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
from bs4 import BeautifulSoup as parse
from requests import get
import json
access = {}
skip = [
"Heffner Alumni House",
"Linac/NES",
"Off Campus Commons",
"Playhouse",
"Student Transition Building",
"Admissions Building",
"1516 People\u2019s Ave",
"41 9th Street",
"Commons Dining Hall",
"Bar-H Dining Hall",
"Sage Dining Hall",
"Blitman Dining",
]
rename = {
"87 Gym": "'87 Gym",
"Academy Hall": "Academy",
"AS&RC": "Armory",
"Greene Building": "Greene",
"Carnegie Building": "Carnegie",
"Pittsburgh Building": "Pittsburgh",
"Sage Lab": "Sage",
"Ricketts Building": "Ricketts",
"Troy Building": "Troy",
"J-Building": "J Complex",
"Jonsson Engineering Center": "JEC",
"Walker Lab": "Walker",
"Science Center": "JROWL",
"Folsom Library": "Folsom",
"Student Union": "Union",
"Cogswell Laboratory": "Cogswell",
"West Hall": "West",
"Biotech": "CBIS",
}
# url = "https://publicsafety.rpi.edu/campus-security/card-access-schedule"
# raw = get(url).content
# html = parse(raw, "html.parser")
# table = html.find_all("tbody")[0]
with open("test.html", "r") as raw:
table = parse(raw, "html.parser")
for tr in table.find_all("tr"):
building, _, times = [('?' if td.string == None else td.string) for td in tr.find_all("td")]
if building not in skip:
if building in rename: building = rename[building]
if times == "24/7": times = "1-7: 0000-2400"
access[building] = times
# print(access)
with open("access.json", "w") as output:
json.dump(access, output, indent = 4)