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()
|
||||
|
||||
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."""
|
||||
@ -132,17 +133,16 @@ def handleAttachments(events: list) -> list:
|
||||
for attachment in event["attach"]:
|
||||
parsed_url = urlparse(attachment)
|
||||
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
|
||||
if isImage:
|
||||
# make internal link relative to "/termine"
|
||||
if parsed_url.hostname in internal_hosts:
|
||||
# make sure path starts with a slash
|
||||
if parsed_url.path[0] != "/":
|
||||
parsed_url.path = "/" + parsed_url.path
|
||||
# prefix path with ".." and add it to the event as "image" property
|
||||
event["image"] = ".." + parsed_url.path
|
||||
# isolate filename
|
||||
filename = parsed_url.path.split("/")[-1]
|
||||
# prefix filename with path and add it to the event as "image" property
|
||||
event["image"] = image_link_prefix + filename
|
||||
# use external link as is
|
||||
else:
|
||||
event["image"] = attachment
|
||||
@ -150,7 +150,7 @@ def handleAttachments(events: list) -> list:
|
||||
else:
|
||||
event["link"] = attachment
|
||||
|
||||
print(event)
|
||||
# print(event) #DEBUG
|
||||
return events
|
||||
|
||||
# create vobject calendar
|
||||
|
||||
Loading…
Reference in New Issue
Block a user