mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 17:54:15 +02:00
[appimage] downloading database files from the cloud
This commit is contained in:
@@ -16,14 +16,17 @@ class HttpClient:
|
|||||||
self.sleep = sleep
|
self.sleep = sleep
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
|
||||||
def get(self, url: str, headers: dict = None):
|
def get(self, url: str, params: dict = None, headers: dict = None, allow_redirects: bool = True):
|
||||||
cur_attempts = 1
|
cur_attempts = 1
|
||||||
|
|
||||||
while cur_attempts <= self.max_attempts:
|
while cur_attempts <= self.max_attempts:
|
||||||
cur_attempts += 1
|
cur_attempts += 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = {'timeout': self.timeout}
|
args = {'timeout': self.timeout, 'allow_redirects': allow_redirects}
|
||||||
|
|
||||||
|
if params:
|
||||||
|
args['params'] = params
|
||||||
|
|
||||||
if headers:
|
if headers:
|
||||||
args['headers'] = headers
|
args['headers'] = headers
|
||||||
@@ -46,8 +49,8 @@ class HttpClient:
|
|||||||
|
|
||||||
self.logger.warning("Could not retrieve data from '{}'".format(url))
|
self.logger.warning("Could not retrieve data from '{}'".format(url))
|
||||||
|
|
||||||
def get_json(self, url: str, headers: dict = None):
|
def get_json(self, url: str, params: dict = None, headers: dict = None, allow_redirects: bool = True):
|
||||||
res = self.get(url, headers=headers)
|
res = self.get(url, params=params, headers=headers, allow_redirects=allow_redirects)
|
||||||
return res.json() if res else None
|
return res.json() if res else None
|
||||||
|
|
||||||
def get_content_length(self, url: str) -> str:
|
def get_content_length(self, url: str) -> str:
|
||||||
|
|||||||
@@ -4,15 +4,16 @@ import time
|
|||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
|
from bauh.api.constants import HOME_PATH
|
||||||
from bauh.api.http import HttpClient
|
from bauh.api.http import HttpClient
|
||||||
|
|
||||||
|
|
||||||
class DatabaseUpdater(Thread if bool(int(os.getenv('BAUH_DEBUG', 0))) else Process):
|
class DatabaseUpdater(Thread if bool(int(os.getenv('BAUH_DEBUG', 0))) else Process):
|
||||||
|
|
||||||
URL_APPS = 'https://github.com/vinifmor/bauh-files/blob/master/appimage/apps.db?raw=true'
|
URL_APPS = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/appimage/apps.db'
|
||||||
URL_RELEASES = 'https://github.com/vinifmor/bauh-files/blob/master/appimage/releases.db?raw=true'
|
URL_RELEASES = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/appimage/releases.db'
|
||||||
APPS_PATH = '{}/.local/share/bauh/appimage/apps.db'
|
APPS_PATH = '{}/.local/share/bauh/appimage/apps.db'.format(HOME_PATH)
|
||||||
RELEASES_PATH = '{}/.local/share/bauh/appimage/releases.db'
|
RELEASES_PATH = '{}/.local/share/bauh/appimage/releases.db'.format(HOME_PATH)
|
||||||
|
|
||||||
def __init__(self, http_client: HttpClient, logger: logging.Logger):
|
def __init__(self, http_client: HttpClient, logger: logging.Logger):
|
||||||
super(DatabaseUpdater, self).__init__(daemon=True)
|
super(DatabaseUpdater, self).__init__(daemon=True)
|
||||||
@@ -30,7 +31,7 @@ class DatabaseUpdater(Thread if bool(int(os.getenv('BAUH_DEBUG', 0))) else Proce
|
|||||||
|
|
||||||
self.logger.info("Database file saved at {}".format(output))
|
self.logger.info("Database file saved at {}".format(output))
|
||||||
else:
|
else:
|
||||||
self.logger.warning('Could not download a database file from {}'.format(url))
|
self.logger.warning('Could not download the database file {}'.format(url))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.enabled:
|
if self.enabled:
|
||||||
|
|||||||
Reference in New Issue
Block a user