NEW: script to add theAlt Events to calendar

This commit is contained in:
Jean-Claude 2022-09-21 18:28:38 +02:00
parent 74a7bef12d
commit c852120a4c
Signed by: jeanclaude
GPG Key ID: 8A300F57CBB9F63E
2 changed files with 82 additions and 0 deletions

View File

@ -39,3 +39,14 @@ Contains core functionality of the Study Manager. Namely it can:
- [Rofi](https://github.com/davatorium/rofi)
- [python-rofi](https://pypi.org/project/python-rofi/)
- [Khal](https://github.com/pimutils/khal) (optional)
## theAltEvent.py
> Create calendar entries for courses of [theAlternative](https://thealternative.ch/)
### Usage
- Clone [theAlternative Website](https://gitlab.ethz.ch/thealternative/website)
- Run `./theAltEvent.py` and pass as arguments all `.yml` files of the events located in `events` that you want to create an empty for. E.g. `theAltEvent.py ./events/*.yml`
### Requirements
- [Python3](https://www.python.org/)
- [Khal](https://github.com/pimutils/khal) (optional)

71
theAltEvent.py Executable file
View File

@ -0,0 +1,71 @@
#!/bin/python
# Iterate over all files passed as arguments and create an calendar entry for each of them.
# Directories and non-yaml (must end with `.yaml` or `.yml`) are ignored.
import sys
from pathlib import Path
import yaml
from datetime import datetime
import subprocess
CALENDAR = "TheAlt"
if len(sys.argv) <= 1:
print("Provide some file to extract the event from.")
sys.exit(1)
cmds = []
for e in sys.argv[1:]:
e = Path(e)
if e.is_dir() or e.suffix.lower() not in [".yaml", ".yml"]:
continue
assert e.is_file()
with open(e, "r") as f:
content = yaml.safe_load(f)
fileName = e.stem
eventDate = datetime.strptime(fileName[0:10], "%Y-%m-%d").strftime("%d/%m/%Y")
calendar = CALENDAR
location = content["location"]
categories = ""
startDate = eventDate
startTime = content["startTime"]
endTime = content["endTime"]
title = fileName[11:]
cmd = [
"khal",
"new",
f"--calendar={calendar}",
f"--location='{location}'",
f"--categories='{categories}'",
startDate,
startTime,
endTime,
title,
]
cmds.append(cmd)
while True:
commandList = "\n".join([" ".join(c) for c in cmds]) ## Prepare for printing
choice = input(
"Do you want to execute the following commands? YES/NO:\n" + commandList + "\n"
).lower()
if choice in ["yes", "y"]:
for c in cmds:
subprocess.call(c)
print("Done")
sys.exit(0)
elif choice in ["no", "n"]:
print("Noting to do. Exiting.")
sys.exit(0)
else:
print("Please respond with 'yes' or 'no'\n")