add: schedule for today and tomorrow; update: showing data

This commit is contained in:
mnjx
2023-04-14 20:14:18 +02:00
parent e2e970b7ff
commit 93fe4ff01c
5 changed files with 321 additions and 62 deletions
+17 -34
View File
@@ -2,16 +2,14 @@ from lib import networking as nw
from bs4 import BeautifulSoup
not_login = 0
F_not_anymore = 0
def fetch_locally() -> list:
global not_login, F_not_anymore
global not_login
if not_login == 1 and F_not_anymore == 0:
F_not_anymore = 1
if not_login == 1:
not_login = 0
print("Could not sign in (you may have entered invalid login credentials)")
print("Fetching locally\n")
#print("Could not sign in (you may have entered invalid login credentials)")
#print("Fetching the schedule for this week locally\n")
schedule_week = schedule_week_from_file()
return schedule_week
@@ -181,6 +179,8 @@ def show_schedule_week():
else:
schedule = schedule_week_from_file()
print("")
print("----------------")
print(" Týdenní rozvrh ")
print("----------------\n")
@@ -216,7 +216,6 @@ def show_schedule_week():
print("| " + schedule[i]["WHERES"][j] + whitespace, end=" ")
print("")
print("")
def schedule_week_to_file(schedule=None):
import csv
@@ -232,24 +231,16 @@ def schedule_week_to_file(schedule=None):
for i in range(len(schedule)):
temp = []
try:
temp.append(schedule[i]["DAY"])
for j in range(len(schedule[i]["SUBJECTS"])):
temp.append(schedule[i]["SUBJECTS"][j])
data.append(temp)
temp = []
temp.append(schedule[i]["DATE"])
for j in range(len(schedule[i]["WHERES"])):
temp.append(schedule[i]["WHERES"][j])
data.append(temp)
temp = []
for j in range(len(schedule[i]["WHOS"])):
temp.append(schedule[i]["WHOS"][j])
data.append(temp)
except KeyError:
pass
temp.append(schedule[i]["DAY"])
for j in range(len(schedule[i]["SUBJECTS"])):
temp.append(schedule[i]["SUBJECTS"][j])
data.append(temp)
temp = []
temp.append(schedule[i]["DATE"])
for j in range(len(schedule[i]["WHERES"])):
temp.append(schedule[i]["WHERES"][j])
data.append(temp)
writer = csv.writer(f)
for row in data:
@@ -266,7 +257,7 @@ def schedule_week_from_file() -> list:
for row in reader:
rows.append(row)
for row in range(0, len(rows), 3):
for row in range(0, len(rows), 2):
temp = {}
temp["DAY"] = rows[row][0]
@@ -289,14 +280,6 @@ def schedule_week_from_file() -> list:
pass
temp["WHERES"] = wheres
whos = []
try:
for i in range(len(rows[row+2])):
whos.append(rows[row+2][i])
except IndexError:
pass
temp["WHOS"] = whos
schedule.append(temp)
except FileNotFoundError:
print("No schedule_week.csv file found\n")