mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 00:04:15 +02:00
Modernize runtime compatibility and initialize Bearhub fork
This commit is contained in:
@@ -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)))
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user