Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MortikCZ committed Sep 29, 2024
1 parent c3bc7c2 commit 1e6fd59
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ A do tašky si naopak dej:
Aplikační software

Přeji krásný den :)
```
```
## Changelog
- [**1.1**](https://github.com/MortikCZ/bakapi-bag-script/releases/tag/v1.1)
- V případě že je dnešní den pátek, sobota či neděle script vypíše co si vyndat na pondělí.
- [**1.0**](https://github.com/MortikCZ/bakapi-bag-script/releases/tag/v1.0)
- První verze scriptu.

49 changes: 34 additions & 15 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,63 @@
formatted_date = current_date.strftime("%d.%m.")
print("Dnešní datum:", formatted_date)

timetable = api.get_timetable_actual(date=current_date)

subject_id_to_name = {subject['Id']: subject['Name'] for subject in timetable['Subjects']}

def get_subjects_for_today_and_tomorrow(timetable):
def get_subjects_for_today_and_tomorrow(api):
today = datetime.now().date()
tomorrow = today + timedelta(days=1)

weekday = today.weekday()

if weekday == 4:
tomorrow = today + timedelta(days=3)
timetable_today = api.get_timetable_actual(date=today)
timetable_tomorrow = api.get_timetable_actual(date=tomorrow)
elif weekday == 5 or weekday == 6:
last_friday = today - timedelta(days=(weekday - 4))
next_monday = today + timedelta(days=(7 - weekday))
timetable_today = api.get_timetable_actual(date=last_friday)
timetable_tomorrow = api.get_timetable_actual(date=next_monday)
today = last_friday
tomorrow = next_monday
else:
tomorrow = today + timedelta(days=1)
timetable_today = api.get_timetable_actual(date=today)
timetable_tomorrow = api.get_timetable_actual(date=tomorrow)

subjects_today = []
subjects_tomorrow = []
subject_id_to_name_today = {subject['Id']: subject['Name'] for subject in timetable_today['Subjects']}
subject_id_to_name_tomorrow = {subject['Id']: subject['Name'] for subject in timetable_tomorrow['Subjects']}

for day in timetable['Days']:
for day in timetable_today['Days']:
day_date = datetime.fromisoformat(day['Date']).date()
if day_date == today:
subjects_today.extend(day['Atoms'])
elif day_date == tomorrow:

for day in timetable_tomorrow['Days']:
day_date = datetime.fromisoformat(day['Date']).date()
if day_date == tomorrow:
subjects_tomorrow.extend(day['Atoms'])

return {
'today': subjects_today,
'tomorrow': subjects_tomorrow
'tomorrow': subjects_tomorrow,
'subject_id_to_name_today': subject_id_to_name_today,
'subject_id_to_name_tomorrow': subject_id_to_name_tomorrow
}

def compare_subjects(today_subjects, tomorrow_subjects):
def compare_subjects(today_subjects, tomorrow_subjects, subject_id_to_name_today, subject_id_to_name_tomorrow):
today_subject_ids = {atom['SubjectId'] for atom in today_subjects if 'SubjectId' in atom and atom['SubjectId']}
tomorrow_subject_ids = {atom['SubjectId'] for atom in tomorrow_subjects if 'SubjectId' in atom and atom['SubjectId']}

subjects_to_take = tomorrow_subject_ids - today_subject_ids
subjects_to_remove = today_subject_ids - tomorrow_subject_ids

items_to_take = [subject_id_to_name[subject_id] for subject_id in subjects_to_take if subject_id in subject_id_to_name]
items_to_remove = [subject_id_to_name[subject_id] for subject_id in subjects_to_remove if subject_id in subject_id_to_name]
items_to_take = [subject_id_to_name_tomorrow.get(subject_id, f"Unknown Subject {subject_id}") for subject_id in subjects_to_take]
items_to_remove = [subject_id_to_name_today.get(subject_id, f"Unknown Subject {subject_id}") for subject_id in subjects_to_remove]

return items_to_take, items_to_remove

subjects = get_subjects_for_today_and_tomorrow(timetable)
subjects = get_subjects_for_today_and_tomorrow(api)

items_to_take, items_to_remove = compare_subjects(subjects['today'], subjects['tomorrow'])
items_to_take, items_to_remove = compare_subjects(subjects['today'], subjects['tomorrow'], subjects['subject_id_to_name_today'], subjects['subject_id_to_name_tomorrow'])

print("\nZ tašky si vyndej:")
for item in items_to_remove:
Expand Down

0 comments on commit 1e6fd59

Please sign in to comment.