small improvements
This commit is contained in:
parent
1fe6cc24f4
commit
00a25fdad9
@ -60,7 +60,8 @@ cal_prop_datetimes = ["dtend", "due", "dtstart", "duration", "dtstamp", "last-mo
|
|||||||
now = datetime.now().astimezone()
|
now = datetime.now().astimezone()
|
||||||
|
|
||||||
image_suffixes = ["jpg", "jpeg", "png", "webp", "gif"]
|
image_suffixes = ["jpg", "jpeg", "png", "webp", "gif"]
|
||||||
internal_hosts = ["", "localhost", "127.0.0.1", "127.0.1.1", "tobias-radloff.de", "www.tobias-radloff.de"]
|
internal_hosts = ["", "localhost", "127.0.0.1", "127.0.1.1"]
|
||||||
|
image_link_prefix = "../images/termine/"
|
||||||
|
|
||||||
|
|
||||||
"""Returns an aware datetime.datetime object based on the given datetime or date. Conversion happens only if necessary, i.e. if d is of type datetime.date or a naive datetime.datetime object."""
|
"""Returns an aware datetime.datetime object based on the given datetime or date. Conversion happens only if necessary, i.e. if d is of type datetime.date or a naive datetime.datetime object."""
|
||||||
@ -132,17 +133,16 @@ def handleAttachments(events: list) -> list:
|
|||||||
for attachment in event["attach"]:
|
for attachment in event["attach"]:
|
||||||
parsed_url = urlparse(attachment)
|
parsed_url = urlparse(attachment)
|
||||||
isImage = True if parsed_url.path.split(".")[-1] in image_suffixes else False
|
isImage = True if parsed_url.path.split(".")[-1] in image_suffixes else False
|
||||||
print(f"attachment is {attachment}, parsed_url is {parsed_url} and isImage is {isImage}") #DEBUG
|
# print(f"attachment is {attachment}, parsed_url is {parsed_url} and isImage is {isImage}") #DEBUG
|
||||||
|
|
||||||
# handle image link
|
# handle image link
|
||||||
if isImage:
|
if isImage:
|
||||||
# make internal link relative to "/termine"
|
# make internal link relative to "/termine"
|
||||||
if parsed_url.hostname in internal_hosts:
|
if parsed_url.hostname in internal_hosts:
|
||||||
# make sure path starts with a slash
|
# isolate filename
|
||||||
if parsed_url.path[0] != "/":
|
filename = parsed_url.path.split("/")[-1]
|
||||||
parsed_url.path = "/" + parsed_url.path
|
# prefix filename with path and add it to the event as "image" property
|
||||||
# prefix path with ".." and add it to the event as "image" property
|
event["image"] = image_link_prefix + filename
|
||||||
event["image"] = ".." + parsed_url.path
|
|
||||||
# use external link as is
|
# use external link as is
|
||||||
else:
|
else:
|
||||||
event["image"] = attachment
|
event["image"] = attachment
|
||||||
@ -150,7 +150,7 @@ def handleAttachments(events: list) -> list:
|
|||||||
else:
|
else:
|
||||||
event["link"] = attachment
|
event["link"] = attachment
|
||||||
|
|
||||||
print(event)
|
# print(event) #DEBUG
|
||||||
return events
|
return events
|
||||||
|
|
||||||
# create vobject calendar
|
# create vobject calendar
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user