-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.py
38 lines (28 loc) · 1.15 KB
/
library.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
import requests
from bs4 import BeautifulSoup
from firebase import firebase
bookstore_url = "https://ucsdbkst.ucsd.edu/wrtx/TextSearch?section="
def main():
database = firebase.FirebaseApplication("https://schedule-of-classes-8b222.firebaseio.com/", None)
result = database.get('/quarter/FA17', None)
term = "FA17"
urls = []
for key, value in result.items():
subject = value["department"]
course_num = value["course number"]
url = bookstore_url + str(key) + "&term=" + term + "&subject=" + subject + "&course=" + course_num
urls.append(url)
print(urls[5])
post = requests.get(urls[5])
soup = BeautifulSoup(post.content, 'lxml').findAll('td')
content = []
for index, value in enumerate(soup):
try:
if (value["align"] == "CENTER" and value.font is not None):
book = soup[index+2].text.partition(", ")
content.append({"isRequired": True if soup[index].text == "R" else False, "Author": soup[index+1].text, "Book Title" : book[0], "Book ISBN" : book[2]})
except:
pass
print(content)
if __name__ == '__main__':
main()