Compare commits

...

2 commits
v1.1.0 ... main

Author SHA1 Message Date
cbb311a0a2
fix(nix): Remove unnecessary package group, use python 3.11
All checks were successful
Mirror to Forgejo / mirror-to-codeberg (push) Successful in 2s
2025-01-19 07:45:53 +01:00
251e7a8ef5
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
2025-01-19 07:45:12 +01:00
2 changed files with 16 additions and 15 deletions

View file

@ -5,12 +5,13 @@ let
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/cf8cc1201be8bc71b7cbbbdaf349b22f4f99c7ae.tar.gz") {}; pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/cf8cc1201be8bc71b7cbbbdaf349b22f4f99c7ae.tar.gz") {};
in pkgs.mkShell { in pkgs.mkShell {
packages = [ packages = [
(pkgs.python3.withPackages (python-pkgs: with python-pkgs; [ (pkgs.python311.withPackages (python-pkgs: with python-pkgs; [
# select Python packages here # select Python packages here
python-pkgs.python-lsp-server python-lsp-server
python-pkgs.python-lsp-ruff python-lsp-ruff
python-pkgs.pylsp-mypy pylsp-mypy
python-pkgs.pylsp-rope pylsp-rope
requests
])) ]))
]; ];
} }

View file

@ -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.")