Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

Python
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:

Python
event_dates = {} #dictionary to store event dates and time
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:

Python
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") # goes to programmes of study

search = driver.find_element_by_id("textSearch")
search.send_keys(course_code) #types course code into search box

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:

Python
df3 = df2.set_index('Unnamed: 0')
#print(df3.head(10).to_dict()) #for checking dataframe
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:

Python
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.
Posted
Updated 4-Mar-22 7:33am
v2
Comments
Richard MacCutchan 3-Mar-22 5:55am    
"have been unable to add just the times that a student is free"
You need to explain what the problem is. Assuming you have the end time of one lecture and the start time of the next, you should be able to create an item that identifies free time. That information should allow you to find events of interest.
clarkj49 3-Mar-22 5:59am    
Ok, the problem I am facing right now is that the times I have gotten aren't being compared against each other. Yes I do have the end time and start time of each lecture. But how I am doing it is i have the start time of an event and the start time of a students break so I am trying to see if they match but can not seem to get it to work.
Richard MacCutchan 3-Mar-22 6:26am    
Maybe they don't match. You need to use a calculation to find out if the event occurs inside the student's free time. So it needs to start at or after the beginning, and finish at or before the end of the free time. If it overflows those times then you can either ignore it or add a message to that effect. You should start by printing out some of your sets to see exactly what values you have to deal with.
clarkj49 3-Mar-22 6:53am    
ok thanks will do

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900