aboutsummaryrefslogtreecommitdiff
path: root/exam_reminders/update.py
blob: 94074dd88cb3ad1aee4351024be217b3a301fb1e (plain) (blame)
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
import os
import datetime
from bs4 import BeautifulSoup


datetime_time = datetime.date.today() + datetime.timedelta(days=1)
formatted_time = datetime_time.strftime("%Y-%m-%d")
yesterday_datetime_time = datetime.date.today()
yesterday_formatted_time = yesterday_datetime_time.strftime("%Y-%m-%d")

if not os.path.isfile(yesterday_formatted_time + ".html"): 
    quit()

with open(yesterday_formatted_time + ".html") as file: 
    soup = BeautifulSoup(file, "html.parser")

today_trs = soup.find_all("tr", class_="today")
for tr in today_trs: 
    next_tr = tr.find_next("tr")
    if next_tr:
        try:
            if next_tr["class"] == ["not-today"]: 
                next_tr["class"] = "today"
                next_tr = next_tr.find_next("tr")
                while next_tr:
                    if next_tr.find("th"): 
                        break
                    next_tr["class"] = "today"
                    next_tr = next_tr.find_next("tr")
                tr.decompose()
            elif next_tr["class"] == ["today"]: 
                tr.decompose()
            else: 
                tr.parent.parent.decompose()
        except KeyError:
            tr.parent.parent.decompose()
    else: 
        tr.parent.parent.decompose()

with open(formatted_time + ".html", "w") as file: 
    file.write(str(soup))