calendar
lr + dicos description + cleanup
This commit is contained in:
@@ -56,6 +56,7 @@
|
|||||||
|
|
||||||
./system-modules/calendar-publish.nix
|
./system-modules/calendar-publish.nix
|
||||||
./system-modules/calendar-lec.nix
|
./system-modules/calendar-lec.nix
|
||||||
|
./system-modules/calendar-lr.nix
|
||||||
./system-modules/calendar-dicos.nix
|
./system-modules/calendar-dicos.nix
|
||||||
] else []);
|
] else []);
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ def modify_event(event):
|
|||||||
global latest_week
|
global latest_week
|
||||||
global deficit
|
global deficit
|
||||||
|
|
||||||
if event.name and "DICOS" in event.name:
|
if event.name is not None and "DICOS" in event.name:
|
||||||
length = (event.end - event.begin).seconds / 3600
|
length = (event.end - event.begin).seconds / 3600
|
||||||
money_made = divmod(length * NETTO_STUNDE, 1)
|
money_made = divmod(length * NETTO_STUNDE, 1)
|
||||||
|
|
||||||
@@ -78,9 +78,14 @@ def modify_event(event):
|
|||||||
latest_goal = goal
|
latest_goal = goal
|
||||||
latest_week = week
|
latest_week = week
|
||||||
|
|
||||||
progress_line = f"({fraction_to_unicode(progress)}/{fraction_to_unicode(goal)})"
|
new_description = [event.description.split("\n")[0] or "::"]
|
||||||
|
new_description.append("")
|
||||||
|
new_description.append(f"Netto: {money_made[0]:.0f},{int(money_made[1] * 10):02d}€")
|
||||||
|
new_description.append(f"This weeks porgress: ({fraction_to_unicode(progress)}/{fraction_to_unicode(goal)})")
|
||||||
|
new_description.append(f"This weeks deficit: {fraction_to_unicode(deficit)}")
|
||||||
|
|
||||||
|
event.description = "\n".join(new_description)
|
||||||
|
|
||||||
event.description = f"Netto: {money_made[0]:.0f},{int(money_made[1] * 10):02d}€\nThis weeks porgress: {progress_line}\nThis weeks deficit: {fraction_to_unicode(deficit)}"
|
|
||||||
event.name = f"DICOS {fraction_to_unicode(length)}"
|
event.name = f"DICOS {fraction_to_unicode(length)}"
|
||||||
return event
|
return event
|
||||||
|
|
||||||
@@ -92,7 +97,7 @@ def process_ics_file(filepath):
|
|||||||
modified = False
|
modified = False
|
||||||
|
|
||||||
for event in calendar.events:
|
for event in calendar.events:
|
||||||
if 'DICOS' in event.name:
|
if event.name is not None and 'DICOS' in event.name:
|
||||||
event = modify_event(event)
|
event = modify_event(event)
|
||||||
modified = True
|
modified = True
|
||||||
|
|
||||||
|
|||||||
@@ -21,18 +21,10 @@
|
|||||||
];
|
];
|
||||||
flakeIgnore = [ "E302" "E305" "E226" "E501" ];
|
flakeIgnore = [ "E302" "E305" "E226" "E501" ];
|
||||||
} /*python */ ''
|
} /*python */ ''
|
||||||
import hashlib
|
|
||||||
from ics import Calendar
|
from ics import Calendar
|
||||||
import requests
|
import requests
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
def get_event_hash(event):
|
|
||||||
"""
|
|
||||||
Generate a unique hash for an event based on its details.
|
|
||||||
"""
|
|
||||||
event_data = f"{event.name}{event.begin}{event.end}{event.description}"
|
|
||||||
return hashlib.md5(event_data.encode('utf-8')).hexdigest()
|
|
||||||
|
|
||||||
def adjust_events(events):
|
def adjust_events(events):
|
||||||
"""
|
"""
|
||||||
Adjust overlapping events to ensure they do not conflict.
|
Adjust overlapping events to ensure they do not conflict.
|
||||||
|
|||||||
74
system-modules/calendar-lr.nix
Normal file
74
system-modules/calendar-lr.nix
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
{ config, pkgs, domain, ... }:
|
||||||
|
{
|
||||||
|
systemd.timers."nx_cal_lr" = {
|
||||||
|
enable = true;
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnBootSec = "41m";
|
||||||
|
OnUnitActiveSec = "24h";
|
||||||
|
Unit = "nx_cal_lr.service";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services."nx_cal_lr" = {
|
||||||
|
script = let
|
||||||
|
nx_cal_lr = (pkgs.writers.writePython3Bin "nx_cal_lr" {
|
||||||
|
libraries = with pkgs.python3Packages; [
|
||||||
|
ics
|
||||||
|
requests
|
||||||
|
];
|
||||||
|
flakeIgnore = [ "E302" "E305" "E226" "E501" ];
|
||||||
|
} /*python */ ''
|
||||||
|
from ics import Calendar
|
||||||
|
import requests
|
||||||
|
|
||||||
|
def filter_events(events):
|
||||||
|
return [event for event in events if ("LR" in event.name) or ("TBD" in event.name)]
|
||||||
|
|
||||||
|
def fetch_and_save_ical_events(ical_url, save_path):
|
||||||
|
"""
|
||||||
|
Fetch events from an iCal URL and save them as a single combined calendar.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Fetch the iCal data
|
||||||
|
response = requests.get(ical_url)
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
|
# Parse the iCal data
|
||||||
|
calendar = Calendar(response.text)
|
||||||
|
|
||||||
|
# Adjust events
|
||||||
|
adjusted_events = filter_events(list(calendar.events))
|
||||||
|
|
||||||
|
# Create a new combined calendar
|
||||||
|
combined_calendar = Calendar()
|
||||||
|
for event in adjusted_events:
|
||||||
|
combined_calendar.events.add(event)
|
||||||
|
|
||||||
|
# Save the combined calendar to a single .ics file
|
||||||
|
with open(save_path, 'w') as file:
|
||||||
|
file.writelines(combined_calendar.serialize_iter())
|
||||||
|
|
||||||
|
print(f"Saved combined calendar to {save_path}")
|
||||||
|
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"Error fetching iCal data: {e}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error processing iCal data: {e}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Replace with your iCal URL and target file path
|
||||||
|
ICAL_URL = "https://zlypher.github.io/lol-events/cal/league-of-legends-nlc.ical"
|
||||||
|
SAVE_PATH = "${config.services.nginx.virtualHosts."${domain}".root}/lr.ics"
|
||||||
|
|
||||||
|
fetch_and_save_ical_events(ICAL_URL, SAVE_PATH)
|
||||||
|
'');
|
||||||
|
in ''
|
||||||
|
${nx_cal_lr}/bin/nx_cal_lr
|
||||||
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
User = "nx2";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user