Skip to content

Commit 01089fb

Browse files
Rutger RauwsRutgerRauws
authored andcommitted
Initial version of Event API wrapper
1 parent 96985ca commit 01089fb

File tree

3 files changed

+8907
-0
lines changed

3 files changed

+8907
-0
lines changed

examples/get_event.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Add the notubiz folder to the path
2+
import sys, os
3+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
4+
5+
import notubiz
6+
import notubiz.api.event
7+
8+
configuration = notubiz.Configuration(organisation_id = 686) # Gemeente Eindhoven
9+
10+
api_client = notubiz.ApiClient(configuration)
11+
12+
event_client = notubiz.api.event.EventApi(api_client)
13+
14+
event = event_client.get(1229974)
15+
16+
print(event.title)
17+
# for event. in meeting.agenda_items:
18+
# print(" {} - {}".format(agenda_item.start_date, agenda_item.title))

notubiz/api/event.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from attrs import define
2+
import cattrs
3+
from cattrs import transform_error
4+
from cattrs.gen import make_dict_structure_fn, override
5+
6+
from datetime import datetime
7+
8+
from notubiz.api.meeting import Meeting, meeting_structure_hook
9+
from notubiz.api.agenda_item import AgendaItem, agenda_item_structure_hook
10+
from notubiz import ApiClient
11+
12+
@define
13+
class Event:
14+
title : str
15+
description : str
16+
location : str
17+
chairman : str
18+
clerk : str
19+
secretary : str
20+
21+
# TODO: media
22+
# TODO: speakers
23+
24+
agenda : list[AgendaItem]
25+
26+
# meeting_id : int
27+
# type : str
28+
# start_date : datetime
29+
# end_date : datetime
30+
31+
# meetings : list[Meeting]
32+
33+
@staticmethod
34+
def from_json(json_object : any) -> 'Event':
35+
c = cattrs.Converter()
36+
c.register_structure_hook(Meeting, meeting_structure_hook)
37+
# c.register_structure_hook(AgendaItem, agenda_item_structure_hook)
38+
st_hook = make_dict_structure_fn(
39+
AgendaItem, c, agenda=override(struct_hook=lambda v, _: agenda_item_structure_hook(v["agendaitem"])))
40+
c.register_structure_hook(AgendaItem, st_hook)
41+
42+
try:
43+
meeting = c.structure(json_object["event"][0], Event)
44+
except Exception as exc:
45+
print("\n".join(transform_error(exc)))
46+
quit()
47+
48+
return meeting
49+
50+
class EventApi:
51+
api_client : ApiClient
52+
53+
54+
def __init__(self, api_client : ApiClient):
55+
self.api_client = api_client
56+
57+
def get(self, event_id : int) -> Event:
58+
json_object = self.api_client.get("events/{}".format(event_id))
59+
return Event.from_json(json_object)
60+

0 commit comments

Comments
 (0)