fix: Nested f
strings don't work on Python < 3.12
All checks were successful
Mirror to Forgejo / mirror-to-codeberg (push) Successful in 2s
All checks were successful
Mirror to Forgejo / mirror-to-codeberg (push) Successful in 2s
This commit is contained in:
parent
5b5351a831
commit
251e7a8ef5
1 changed files with 10 additions and 10 deletions
|
@ -200,7 +200,7 @@ def main():
|
||||||
heartbeat.start()
|
heartbeat.start()
|
||||||
|
|
||||||
last_datetime = datetime.fromisoformat("1970-01-01T00:00:00Z")
|
last_datetime = datetime.fromisoformat("1970-01-01T00:00:00Z")
|
||||||
nextcloud_auth_header = f"Basic {base64.b64encode(f"{config["nextcloud_username"]}:{config["nextcloud_password"]}".encode("utf-8")).decode("utf-8")}"
|
nextcloud_auth_header = f"Basic {base64.b64encode('{}:{}'.format(config['nextcloud_username'], config['nextcloud_password']).encode('utf-8')).decode('utf-8')}"
|
||||||
nextcloud_request_headers = {
|
nextcloud_request_headers = {
|
||||||
"Authorization": f"{nextcloud_auth_header}",
|
"Authorization": f"{nextcloud_auth_header}",
|
||||||
"OCS-APIREQUEST": "true",
|
"OCS-APIREQUEST": "true",
|
||||||
|
@ -210,7 +210,7 @@ def main():
|
||||||
log.debug("Fetching notifications.")
|
log.debug("Fetching notifications.")
|
||||||
try:
|
try:
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
f"{config["nextcloud_base_url"]}{config["nextcloud_notification_path"]}",
|
f"{config['nextcloud_base_url']}{config['nextcloud_notification_path']}",
|
||||||
headers=nextcloud_request_headers,
|
headers=nextcloud_request_headers,
|
||||||
)
|
)
|
||||||
except requests.exceptions.SSLError as e:
|
except requests.exceptions.SSLError as e:
|
||||||
|
@ -220,14 +220,14 @@ def main():
|
||||||
f"Error while fetching notifications. Response code: {response.status_code}."
|
f"Error while fetching notifications. Response code: {response.status_code}."
|
||||||
)
|
)
|
||||||
log.warning(
|
log.warning(
|
||||||
f"Sleeping for {config["nextcloud_error_sleep_seconds"]} seconds."
|
f"Sleeping for {config['nextcloud_error_sleep_seconds']} seconds."
|
||||||
)
|
)
|
||||||
sleep(config["nextcloud_error_sleep_seconds"])
|
sleep(config["nextcloud_error_sleep_seconds"])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
elif response.status_code == 204:
|
elif response.status_code == 204:
|
||||||
log.debug(
|
log.debug(
|
||||||
f"Got code 204 while fetching notifications. Sleeping for {config["nextcloud_204_sleep_seconds"]/60/60} hour(s)."
|
f"Got code 204 while fetching notifications. Sleeping for {config['nextcloud_204_sleep_seconds']/60/60} hour(s)."
|
||||||
)
|
)
|
||||||
|
|
||||||
log.debug(f"Got resonse code: {response.status_code}")
|
log.debug(f"Got resonse code: {response.status_code}")
|
||||||
|
@ -251,9 +251,9 @@ def main():
|
||||||
|
|
||||||
title = ""
|
title = ""
|
||||||
if notification["app"] == "admin_notifications":
|
if notification["app"] == "admin_notifications":
|
||||||
title = f"Nextcloud: {notification["subject"]}"
|
title = f"Nextcloud: {notification['subject']}"
|
||||||
else:
|
else:
|
||||||
title = f"Nextcloud - {translate_app_name(notification["app"])}: {notification["subject"]}"
|
title = f"Nextcloud - {translate_app_name(notification['app'])}: {notification['subject']}"
|
||||||
log.debug(f"Notification title: {title}")
|
log.debug(f"Notification title: {title}")
|
||||||
|
|
||||||
message = notification["message"]
|
message = notification["message"]
|
||||||
|
@ -264,7 +264,7 @@ def main():
|
||||||
{
|
{
|
||||||
"action": "http",
|
"action": "http",
|
||||||
"label": "Dismiss",
|
"label": "Dismiss",
|
||||||
"url": f"{config["nextcloud_base_url"]}{config["nextcloud_notification_path"]}/{notification["notification_id"]}",
|
"url": f"{config['nextcloud_base_url']}{config['nextcloud_notification_path']}/{notification['notification_id']}",
|
||||||
"method": "DELETE",
|
"method": "DELETE",
|
||||||
"headers": {
|
"headers": {
|
||||||
"Authorization": f"{nextcloud_auth_header}",
|
"Authorization": f"{nextcloud_auth_header}",
|
||||||
|
@ -288,14 +288,14 @@ def main():
|
||||||
)
|
)
|
||||||
if response.status_code == 429:
|
if response.status_code == 429:
|
||||||
log.error(
|
log.error(
|
||||||
f"Error pushing notification to {config["ntfy_base_url"]}: Too Many Requests."
|
f"Error pushing notification to {config['ntfy_base_url']}: Too Many Requests."
|
||||||
)
|
)
|
||||||
log.warning(
|
log.warning(
|
||||||
f"Sleeping for {config["rate_limit_sleep_seconds"]} seconds."
|
f"Sleeping for {config['rate_limit_sleep_seconds']} seconds."
|
||||||
)
|
)
|
||||||
elif not response.ok:
|
elif not response.ok:
|
||||||
log.critical(
|
log.critical(
|
||||||
f"Unknown erroro while pushing notification to {config["ntfy_base_url"]}. Error code: {response.status_code}."
|
f"Unknown erroro while pushing notification to {config['ntfy_base_url']}. Error code: {response.status_code}."
|
||||||
)
|
)
|
||||||
log.critical(f"Response: {response.text}")
|
log.critical(f"Response: {response.text}")
|
||||||
log.error("Stopping.")
|
log.error("Stopping.")
|
||||||
|
|
Loading…
Reference in a new issue