I want to print out when a student has a free slot on their timetable what event is taking place at that time.
I have scraped both websites and are storing the events in a dictionary. I'm just wondering how do I print it so it tells the student what event is on during their breaks in the day.
import pandas as pd
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import Select
import datetime as dt
And this is for getting the events on during each day:
event_dates = {}
df = pd.read_html('https://www.dcu.ie/students/events')[0]['Event date']
df = df.str.replace('([a-zA-Z]+ \d+, |\s+(?=\s))', '')
df = df.str.split("-")
event_dates.update(df)
And for getting the students timetable:
print("Please enter course code and press enter:")
course_code = input()
s = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
driver.maximize_window()
driver.implicitly_wait(30)
driver.get('https://opentimetable.dcu.ie/')
select = Select(driver.find_element_by_tag_name("select"))
select.select_by_visible_text("Programmes of Study")
search = driver.find_element_by_id("textSearch")
search.send_keys(course_code)
time.sleep(3)
checkbox = driver.find_element_by_xpath('.//input[following-sibling::div[contains(text(), course_code)]]')
checkbox.click()
time.sleep(3)
html = driver.find_element_by_id("week-pdf-content").get_attribute('outerHTML')
df2 = pd.read_html(html)[0]
And for printing just the students free times:
df3 = df2.set_index('Unnamed: 0')
for column in df3:
print("You have free slots at the following times:")
print(f'{column}:{", ".join(df3[df3[column].isna()].index.drop_duplicates().to_list())}')
This is what I have come up with for checking if there is a free time that is the same in both:
free_times = {}
free_times.update(column)
print(free_times)
for key in event_dates.values():
key = key[0]
print(key)
for key2 in free_times.values():
key2 = key2[0]
print(key2)
if key == key2:
print("There is an event on ")
else:
print("There are no events on")
For example, if the student enters "CASE2" (a random course from my college) they would be returned with "You have a free slot on Tuesday at 4-5, there is an event taking place at this time" and show the user the event that is on. I have tried storing the timetable in a dictionary as well but can only store the entire thing, not sure how to just do the times.
What I have tried:
I have tried getting the dictionary for the timetable to work, but have been unable to add just the times that a student is free to the dictionary so I can compare it to times events are taking place.