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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#!/run/current-system/sw/bin/python
import os
import json
import datetime
import copy
import dataclasses
input_file_path = './program.json'
title_max_length = 34
@dataclasses.dataclass
class Event:
title: str = None
room: str = None
day: str = None
start_date: datetime.datetime = None
end_date: datetime.datetime = None
icon: str = '?'
time: str = None
duration: datetime.timedelta = None
pretty: str = None
progress: int = None
icons = {
'Startent at Info Desk' : "⭐",
'Speakers Tent': "🏕",
'Workshop Room': "🛠️",
'Bar Meetup Area': "🍺",
'Bar Area': "🍺",
'External': "🚗",
'Pyjam.as Village in Party Area': "🐍",
'Workshop Room (possibly outside of it)': "🛠️(🏞️)",
'Workshop Room (sofa area)': "🛠️(🛋️)",
'NWWC Village in Party Area': "🔊",
'Wellness area': "🛀",
'Online': "🌐",
}
def get_program() -> list[Event]:
program: list[Event] = []
# Parse program into data format (interpret datetime, and such)
with open(input_file_path, "r") as json_file:
program_raw = json.load(json_file)
for event_raw in program_raw:
event = Event()
#print(event_raw["title"])
for d in ["title", "room"]: # 1 to 1 mapping
setattr(event, d, event_raw[d])
event.start_date = datetime.datetime.strptime(event_raw["date"], "%Y-%m-%dT%H:%M:%S+00:00")
event.start_date += datetime.timedelta(hours=2) # Hvad er vinter tid?
end_bogus = datetime.datetime.strptime(event_raw["duration"],"%H:%M:%S")
event.duration = datetime.timedelta(hours=end_bogus.hour, minutes=end_bogus.minute, seconds=end_bogus.second)
event.end_date = event.start_date + event.duration
#print('Start date: ', event["start_date"])
#print("End date: ", event["end_date"])
#print()
program.append(event)
program = sorted(program, key=lambda x: x.start_date)
return program
def get_events_to_show(program: list[Event], programs_to_show_count=4) -> list[Event]:
current_datetime = datetime.datetime.now()
#current_datetime = datetime.datetime(year=2025, month=7, day=18, hour=15, minute=30) # DEBUG
# Get events to show
events_to_show = []
for event in program:
if len(events_to_show) >= programs_to_show_count:
break
if event.end_date > current_datetime:
events_to_show.append(event)
def format_program(event: Event, cli=False) -> str:
if len(event.title) > title_max_length:
event.title = f'{event.title[:title_max_length - 3]}...' # Truncate title by deleting was 1-3 chars and putting ...
else:
event.title += " " * (title_max_length - len(event.title)) # Pad title
event.day = event.start_date.strftime('%a')
start_time = event.start_date.strftime('%H:%M')
end_time = event.end_date.strftime('%H:%M')
event.icon = icons.get(event.room)
if event.icon == None:
event.icon = '?'
print(f"NEW ICON NEEDED!!! for {event.room}")
event.time = f"{start_time}-{end_time}"
return f"{event.title} {event.day} {start_time}-{end_time} {event.icon}"
for event_to_show in events_to_show:
event_to_show.pretty = format_program(event_to_show)
duration_sec = (event_to_show.end_date - event_to_show.start_date).total_seconds()
progress_sec = (current_datetime - event_to_show.end_date).total_seconds()
event_to_show.progress = 100 + (progress_sec / duration_sec) * 100
return events_to_show
program: list[Event] = get_program()
events_to_show: list[Event] = get_events_to_show(program)
'''
# Convert to the output string
events_to_show_string = '\n'.join([a.pretty for a in events_to_show])
print(f"{events_to_show_string}\n")
# Write to output file
with open(tmp_file_path, 'w') as tmp_file:
tmp_file.write(events_to_show_string)
os.rename(tmp_file_path, output_file_path)
print(f'Written to {output_file_path} length: {len(events_to_show_string)}')
'''
|