Skip to content

Commit d2314f6

Browse files
committed
Implementation
1 parent 9b3f1c9 commit d2314f6

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Eventor
2+
=======
3+
4+
A simple tool to convert EuroPython's json files to an ICS file.
5+
6+
Clone EuroPython's [website repo](https://github.com/EuroPython/website/).
7+
Then install and use this tool:
8+
9+
```bash
10+
python3 -m venv venv
11+
source venv/bin/activate
12+
pip install ./eventor
13+
eventor -j '~/path/to/europython/website/src/content/days/*.json'
14+
```
15+
16+
This will write a calendar.ics file in the current directory that you can then import to your favorite calendar app.

eventor/pyproject.toml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "eventor"
7+
version = "0.1.0"
8+
dependencies = [
9+
"icalendar",
10+
]
11+
authors = [{"name" = "Erik Heeren", "email" = "[email protected]"}]
12+
maintainers = [{"name" = "Erik Heeren", "email" = "[email protected]"}]
13+
classifiers = [
14+
"Development Status :: 4 - Beta",
15+
"Programming Language :: Python",
16+
"Programming Language :: Python :: 3",
17+
"Topic :: Scientific/Engineering",
18+
"License :: OSI Approved :: Apache Software License",
19+
]
20+
21+
#[project.optional-dependencies]
22+
#test = ["pytest", "pytest-cov"]
23+
24+
[project.scripts]
25+
eventor = "eventor.eventor:main"
26+
27+
[tool.ruff]
28+
line-length = 100
29+
30+
[tool.ruff.lint]
31+
select = ["E", # pycodestyle
32+
"F", # pyflakes
33+
"I", # isort
34+
"PL", # pylint
35+
]
36+
37+
#[tool.pytest.ini_options]
38+
#addopts = ["--import-mode=importlib", "-vv", "--disable-warnings", "--cov=hpc_provisioner", "--cov-report", "term", "--cov-report", "xml:coverage.xml", "--junitxml", "unittests.xml"]

eventor/src/eventor/eventor.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import json
2+
from argparse import ArgumentParser
3+
from datetime import datetime, timezone
4+
from pathlib import Path
5+
from uuid import uuid4
6+
7+
from icalendar import Calendar, Event
8+
9+
10+
def convert_event(json_event: dict) -> Event:
11+
start = (
12+
datetime.strptime(json_event["start"], "%Y-%m-%dT%H:%M:%S%z")
13+
.astimezone(timezone.utc)
14+
.strftime("%Y%m%dT%H%M%SZ")
15+
)
16+
summary = json_event["title"]
17+
description = json_event.get("website_url", "")
18+
dtstart = start
19+
duration = f"PT{json_event['duration']}M"
20+
dtstamp = start
21+
uid = str(uuid4())
22+
location = ", ".join(json_event["rooms"])
23+
24+
return Event(
25+
summary=summary,
26+
description=description,
27+
dtstart=dtstart,
28+
duration=duration,
29+
dtstamp=dtstamp,
30+
uid=uid,
31+
location=location,
32+
)
33+
34+
35+
def create_calendar() -> Calendar:
36+
cal = Calendar()
37+
cal.add("prodid", "-//Erik//Europython2024Calendar//EN")
38+
cal.add("version", "2.0")
39+
return cal
40+
41+
42+
def main():
43+
parser = ArgumentParser()
44+
parser.add_argument(
45+
"-j",
46+
"--json-files",
47+
help="Path to the json file to process, supports globs in the filename",
48+
)
49+
args = parser.parse_args()
50+
51+
calendar = create_calendar()
52+
path = Path(args.json_files)
53+
json_files = Path(path.parent).expanduser().glob(path.name)
54+
55+
for json_file in json_files:
56+
with open(json_file, "r") as fp:
57+
events = json.load(fp)
58+
59+
for json_event in events["events"]:
60+
event = convert_event(json_event)
61+
calendar.add_component(event)
62+
63+
with open("calendar.ics", "wb") as fp:
64+
fp.write(calendar.to_ical())
65+
66+
67+
if __name__ == "__main__":
68+
main()

0 commit comments

Comments
 (0)