-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOU_library_checker.py
More file actions
83 lines (71 loc) · 2.82 KB
/
OU_library_checker.py
File metadata and controls
83 lines (71 loc) · 2.82 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import requests
import time
from bs4 import BeautifulSoup
from selenium import webdriver
import streamlit as st
# sets up the webdriver
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--incognito')
options.add_argument('--headless')
driver = webdriver.Chrome('./chromedriver', chrome_options=options)
# link to the reservations for Bizzel's Library rooms
url = 'https://libcal.ou.edu/reserve/groupstudyrooms'
# retrieves the studyrooms bookings and returns it as a list
def getBooking(driver):
# goes to the link
driver.get(url)
# retrieves source code of the website
page_source = driver.page_source
# parses the source code into something interactable
soup = BeautifulSoup(page_source, 'xml')
# lists to store data in
rooms = []
times = []
# gets current booking status for every rooms
# each element in rooms is a list of times for each room
rows = soup.find_all('div', class_='fc-timeline-events fc-scrollgrid-sync-inner')
for row in rows:
times = []
time_slots = row.find_all('div', class_='fc-timeline-event-harness')
for time_slot in time_slots:
slot = time_slot.find('a')
times.append(slot.get('title', 'no'))
rooms.append(times)
return rooms
# determines whether library is busy or not and returns a list of of available rooms
def is_library_busy(reservations):
availableCount = 0
avialable_places = []
# loops through the previously retrieved list to check for available rooms and time slots
for i in range (len(reservations)):
for j in range(3):
try:
if " Available" in reservations[i][j]:
avialable_places.append(reservations[i][j])
availableCount += 1
except:
pass
# not busy if there are 3 or more 30 minute time slots available in the next 1 and a half hours
if availableCount > 2:
return "Not Busy", avialable_places
return "Busy", avialable_places
# homepage = 'https://sites.google.com/d/1d4ciRnNkLIREEqSyKLK17wt8hy_KaqRU/p/1G0PwWL8LhKhYEe_2HUjWKM-NXLsgAGug/'
t = st.empty()
n = st.empty()
while True:
t.empty()
n.empty()
reservations = getBooking(driver)
is_busy, places = is_library_busy(reservations)
t.write(is_busy + "\n\n")
printString = ""
for i in places:
printString += "\n" + i + "\n\t\t "
try:
n.write(printString)
except:
n.write("Little to no space available")
# link = '[Back to homepage](https://sites.google.com/d/1d4ciRnNkLIREEqSyKLK17wt8hy_KaqRU/p/1G0PwWL8LhKhYEe_2HUjWKM-NXLsgAGug/)'
# st.markdown(link, unsafe_allow_html=True)
time.sleep(60)