Skip to content

Commit 4296c4f

Browse files
committed
iCal sample
1 parent f90a733 commit 4296c4f

File tree

6 files changed

+387
-0
lines changed

6 files changed

+387
-0
lines changed

20241027/python/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.venv/

20241027/python/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12.6

20241027/python/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# iCal sample
2+
3+
## uv
4+
5+
- <https://github.com/astral-sh/uv>
6+
- <https://docs.astral.sh/uv/>
7+
8+
## requests
9+
10+
- <https://github.com/psf/requests>
11+
- <https://requests.readthedocs.io/>
12+
13+
## ics.py
14+
15+
- <https://github.com/ics-py/ics-py>
16+
- <https://icspy.readthedocs.io/>
17+
18+
## Set up
19+
20+
```bash
21+
brew install uv
22+
```
23+
24+
```bash
25+
echo '3.12.6' > .python-version
26+
```
27+
28+
```bash
29+
uv init
30+
```
31+
32+
```bash
33+
uv venv .venv
34+
```
35+
36+
```bash
37+
uv add requests
38+
uv add ics
39+
40+
uv add --dev black
41+
uv add --dev isort
42+
```
43+
44+
## Run
45+
46+
```bash
47+
uv run main.py
48+
```
49+
50+
```bash
51+
uv run -- black .
52+
uv run -- isort .
53+
```

20241027/python/main.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from datetime import datetime, timedelta
2+
3+
import requests
4+
from ics import Calendar
5+
6+
CALENDAR_URL = (
7+
"https://calendar.google.com/calendar/ical/"
8+
"ko.south_korea%23holiday%40group.v.calendar.google.com"
9+
"/public/basic.ics"
10+
)
11+
12+
13+
def load_calendar():
14+
response = requests.get(CALENDAR_URL)
15+
response.raise_for_status()
16+
17+
return Calendar(response.text)
18+
19+
20+
def main():
21+
now = datetime.now()
22+
23+
calendar = load_calendar()
24+
25+
events = sorted(calendar.events, key=lambda event: event.begin)
26+
27+
for event in events:
28+
start_date = event.begin.date()
29+
end_date = event.end.date() - timedelta(days=1)
30+
if now.year in (start_date.year, end_date.year):
31+
print(f"{event.name}{start_date} ~ {end_date}")
32+
print(f"(UID: {event.uid})")
33+
if start_date.year != end_date.year:
34+
print("⚠ This event is spanning multiple years.")
35+
print()
36+
37+
38+
if __name__ == "__main__":
39+
main()

20241027/python/pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[project]
2+
name = "demo"
3+
version = "0.1.0"
4+
description = ""
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = [
8+
"requests>=2.32.3",
9+
"ics>=0.7.2",
10+
]
11+
12+
[dependency-groups]
13+
dev = [
14+
"black>=24.10.0",
15+
"isort>=5.13.2",
16+
]

0 commit comments

Comments
 (0)