post id within icalendar output

main
Bob Mottram 2022-02-21 19:01:19 +00:00
parent 1effb9b15a
commit 0b4c260364
2 changed files with 24 additions and 12 deletions

View File

@ -274,7 +274,8 @@ def _ical_date_string(date_str: str) -> str:
def _icalendar_day(base_dir: str, nickname: str, domain: str, def _icalendar_day(base_dir: str, nickname: str, domain: str,
day_events: [], person_cache: {}) -> str: day_events: [], person_cache: {},
http_prefix: str) -> str:
"""Returns a day's events in icalendar format """Returns a day's events in icalendar format
""" """
ical_str = '' ical_str = ''
@ -292,13 +293,17 @@ def _icalendar_day(base_dir: str, nickname: str, domain: str,
for evnt in event_post: for evnt in event_post:
if evnt['type'] == 'Event': if evnt['type'] == 'Event':
if evnt.get('post_id'): if evnt.get('post_id'):
post_id = evnt['post_id'] post_id = \
http_prefix + '://' + domain + \
'/users/' + nickname + '/statuses/' + evnt['post_id']
if evnt.get('startTime'): if evnt.get('startTime'):
event_start = \ event_start = \
datetime.strptime(evnt['startTime'], datetime.strptime(evnt['startTime'],
"%Y-%m-%dT%H:%M:%S%z") "%Y-%m-%dT%H:%M:%S%z")
evnt_end = event_start + timedelta(hours=1) if evnt.get('endTime'):
event_end = evnt_end.strftime("%Y-%m-%dT%H:%M:%S%z") event_end = \
datetime.strptime(evnt['startTime'],
"%Y-%m-%dT%H:%M:%S%z")
if 'public' in evnt: if 'public' in evnt:
if evnt['public'] is True: if evnt['public'] is True:
event_is_public = True event_is_public = True
@ -323,7 +328,7 @@ def _icalendar_day(base_dir: str, nickname: str, domain: str,
str(event_start) + ' ' + str(event_description) + ' ' + str(event_start) + ' ' + str(event_description) + ' ' +
str(sender_actor)) str(sender_actor))
if not post_id or not event_start or \ if not post_id or not event_start or not event_end or \
not event_description or not sender_actor: not event_description or not sender_actor:
continue continue
@ -350,7 +355,8 @@ def _icalendar_day(base_dir: str, nickname: str, domain: str,
event_start = \ event_start = \
_ical_date_string(event_start.strftime("%Y-%m-%dT%H:%M:%SZ")) _ical_date_string(event_start.strftime("%Y-%m-%dT%H:%M:%SZ"))
event_end = _ical_date_string(event_end) event_end = \
_ical_date_string(event_end.strftime("%Y-%m-%dT%H:%M:%SZ"))
ical_str += \ ical_str += \
'BEGIN:VEVENT\n' + \ 'BEGIN:VEVENT\n' + \
@ -390,7 +396,8 @@ def _icalendar_day(base_dir: str, nickname: str, domain: str,
def get_todays_events_icalendar(base_dir: str, nickname: str, domain: str, def get_todays_events_icalendar(base_dir: str, nickname: str, domain: str,
year: int, month_number: int, year: int, month_number: int,
day_number: int, person_cache: {}) -> str: day_number: int, person_cache: {},
http_prefix: str) -> str:
"""Returns today's events in icalendar format """Returns today's events in icalendar format
""" """
day_events = None day_events = None
@ -413,7 +420,8 @@ def get_todays_events_icalendar(base_dir: str, nickname: str, domain: str,
return ical_str return ical_str
ical_str += \ ical_str += \
_icalendar_day(base_dir, nickname, domain, day_events, person_cache) _icalendar_day(base_dir, nickname, domain, day_events, person_cache,
http_prefix)
ical_str += 'END:VCALENDAR\n' ical_str += 'END:VCALENDAR\n'
return ical_str return ical_str
@ -422,7 +430,8 @@ def get_todays_events_icalendar(base_dir: str, nickname: str, domain: str,
def get_month_events_icalendar(base_dir: str, nickname: str, domain: str, def get_month_events_icalendar(base_dir: str, nickname: str, domain: str,
year: int, year: int,
month_number: int, month_number: int,
person_cache: {}) -> str: person_cache: {},
http_prefix: str) -> str:
"""Returns today's events in icalendar format """Returns today's events in icalendar format
""" """
month_events = \ month_events = \
@ -444,7 +453,8 @@ def get_month_events_icalendar(base_dir: str, nickname: str, domain: str,
day_events = month_events[str(day_of_month)] day_events = month_events[str(day_of_month)]
ical_str += \ ical_str += \
_icalendar_day(base_dir, nickname, domain, _icalendar_day(base_dir, nickname, domain,
day_events, person_cache) day_events, person_cache,
http_prefix)
ical_str += 'END:VCALENDAR\n' ical_str += 'END:VCALENDAR\n'
return ical_str return ical_str

View File

@ -319,7 +319,8 @@ def html_calendar(person_cache: {}, css_cache: {}, translate: {},
nickname, domain, nickname, domain,
year, month_number, year, month_number,
day_number, day_number,
person_cache) person_cache,
http_prefix)
day_events = None day_events = None
events = \ events = \
get_todays_events(base_dir, nickname, domain, get_todays_events(base_dir, nickname, domain,
@ -335,7 +336,8 @@ def html_calendar(person_cache: {}, css_cache: {}, translate: {},
if icalendar: if icalendar:
return get_month_events_icalendar(base_dir, nickname, domain, return get_month_events_icalendar(base_dir, nickname, domain,
year, month_number, person_cache) year, month_number, person_cache,
http_prefix)
events = \ events = \
get_calendar_events(base_dir, nickname, domain, year, month_number) get_calendar_events(base_dir, nickname, domain, year, month_number)