Modernize runtime compatibility and initialize Bearhub fork

This commit is contained in:
Sebastian Palencsar
2026-05-26 08:35:29 +02:00
parent b1ea479a3a
commit d541a4cbcf
23 changed files with 132 additions and 96 deletions

View File

@@ -2,7 +2,7 @@ import logging
import os
import time
import traceback
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from pathlib import Path
from threading import Thread
from typing import Dict, List, Optional
@@ -93,7 +93,7 @@ class CategoriesDownloader(Thread):
self.logger.info(self._msg('Downloading category definitions from {}'.format(self.url_categories_file)))
try:
timestamp = datetime.utcnow().timestamp()
timestamp = datetime.now(timezone.utc).timestamp()
res = self.http_client.get(self.url_categories_file)
except requests.exceptions.ConnectionError:
self.logger.error(self._msg('[{}] Could not download categories. The internet connection seems to be off.'.format(self.id_)))
@@ -139,13 +139,13 @@ class CategoriesDownloader(Thread):
timestamp_str = f.read()
try:
categories_timestamp = datetime.fromtimestamp(float(timestamp_str))
categories_timestamp = datetime.fromtimestamp(float(timestamp_str), tz=timezone.utc)
except Exception:
self.logger.error(self._msg("An exception occurred when trying to parse the categories file timestamp from '{}'. The categories file should be re-downloaded.".format(categories_ts_path)))
traceback.print_exc()
return True
should_download = (categories_timestamp + timedelta(hours=self.expiration) <= datetime.utcnow())
should_download = (categories_timestamp + timedelta(hours=self.expiration) <= datetime.now(timezone.utc))
if should_download:
self.logger.info(self._msg("Cached categories file '{}' has expired. A new one should be downloaded.".format(self.categories_path)))

View File

@@ -1,7 +1,7 @@
import logging
import re
from abc import ABC
from datetime import datetime
from datetime import datetime, timezone
from logging import Logger
from typing import Optional, Union
@@ -66,7 +66,10 @@ def size_to_byte(size: Union[float, int, str], unit: str, logger: Optional[Logge
return final_size * (base ** 5)
def datetime_as_milis(date: datetime = datetime.utcnow()) -> int:
def datetime_as_milis(date: Optional[datetime] = None) -> int:
if date is None:
date = datetime.now(timezone.utc)
return int(round(date.timestamp() * 1000))