forked from speedyg0nz/MagInkCal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.py
More file actions
executable file
·72 lines (65 loc) · 2.38 KB
/
debug.py
File metadata and controls
executable file
·72 lines (65 loc) · 2.38 KB
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
#!/usr/bin/env python3
import logging
import sys
from datetime import datetime
from pytz import timezone
from modules.calendar import Calendar, get_months_preview
from modules.config import ConfigLoader
from modules.logger import log_setup
from modules.power import Power
from modules.render import TemplateRenderer
from modules.schedule import Scheduler
from modules.weather import ForecastConditionEnum, Weather
assert len(sys.argv) == 2, f"Expected 1 argument, {len(sys.argv) - 1} given"
cmd = sys.argv[1]
log_setup("debug.log")
logger = logging.getLogger('debug')
logger.info(f"Debug {cmd}")
config = ConfigLoader().config
if cmd == "config":
print(config.json(ensure_ascii=False, indent=4))
elif cmd == "events":
calendar = Calendar(config)
calendar.load_events()
for date, day in calendar.days.items():
print(date)
for event in day.events:
if event.all_day:
print(f" {event.summary}")
else:
print(f" {event.start_time} {event.summary}")
elif cmd == "months":
for month in get_months_preview(2):
print(f"{config.i18n.preview_months[month.number - 1]} {month.year}")
for index, day in enumerate(month.days):
print(f" {day.number}", end="\n" if index % 7 == 6 else " ")
elif cmd == "battery":
power = Power()
print(power.battery_status)
elif cmd == "render":
renderer = TemplateRenderer(config)
calendar = Calendar(config)
calendar.load_events()
weather_forecast = None
if config.weather.is_enabled:
weather_forecast = Weather(config).forecast
renderer.render(calendar, weather_forecast=weather_forecast)
elif cmd == "weather":
forecast = Weather(config).forecast
print(forecast.day)
for hour in forecast.hours:
print(f" {hour.hour}: {hour.condition.name} - {hour.temperature}°C")
elif cmd == "scheduler_times":
scheduler = Scheduler(config)
now = datetime.now().astimezone(timezone(config.timezone))
next_wakeup = scheduler.get_next_wakeup_time()
print(f"Current time: {now.isoformat()}")
if next_wakeup:
print(f"Configured wake up times: {', '.join(scheduler.wakeup_hours)}")
print(f"Next wake up time: {next_wakeup.isoformat()}")
else:
print("No wake up time configured")
elif cmd == "scheduler":
Scheduler(config).schedule_next_wakeup()
else:
print(f"Unknown '{cmd}' command")