From 71a2a3fd8b13f6c3e942df5e68bb56e5aad50c2f Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Tue, 14 Jun 2022 17:55:01 -0500 Subject: AƱadido lector de config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ampache/ampache.py | 11 +++++------ src/config.py | 27 +++++++++++++++++++++++++++ src/test.py | 5 ----- 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 src/config.py delete mode 100644 src/test.py (limited to 'src') diff --git a/src/ampache/ampache.py b/src/ampache/ampache.py index e74029d..b58ba36 100644 --- a/src/ampache/ampache.py +++ b/src/ampache/ampache.py @@ -3,7 +3,6 @@ The main file. The AmpacheClient class allows us to make requests to the API. """ from datetime import datetime -from sys import version from ampache import models, exceptions import requests @@ -61,7 +60,7 @@ class AmpacheClient: def request(self, params, headers): """ - All in one function to pass JSON requests to the API. + All in one function to pass requests to the API. """ response = requests.get(self._host + self._endpoint, params=params, headers=headers) @@ -71,9 +70,9 @@ class AmpacheClient: if headers['Content-type'] == 'application/json': response = response.json() - if 'error' in response: - self.raise_by_status(models.Error(int(response['error']['errorCode']), - response['error']['errorMessage'])) + if 'error' in response: + self.raise_by_status(models.Error(int(response['error']['errorCode']), + response['error']['errorMessage'])) return response @@ -160,7 +159,7 @@ class AmpacheClient: } data = self.request(params, headers) - with open(destination, 'wb') as song: + with open(destination, 'wb') as song: song.write(data.content) def renew_token(self): diff --git a/src/config.py b/src/config.py new file mode 100644 index 0000000..4191c4d --- /dev/null +++ b/src/config.py @@ -0,0 +1,27 @@ +import configparser + +class Config: + """ + A cconfig reader class. + """ + def __init__(self, config_file): + self._parser = configparser.ConfigParser() + self._parser.read(config_file) + + def get_server_config(self): + host = self._parser['Server']['host'] + version = self._parser['Server']['api_version'] + + return (host, version) + + def get_auth(self): + auth = self._parser['Auth']['key'] + + return auth + + def get_directories(self): + download = self._parser['Directories']['download_folder'] + delete_after_playing = bool(self._parser['Directories'] + ['delete_after_playing']) + + return (download, delete_after_playing) diff --git a/src/test.py b/src/test.py deleted file mode 100644 index e75baa3..0000000 --- a/src/test.py +++ /dev/null @@ -1,5 +0,0 @@ -from ampache.ampache import AmpacheClient - -my_ampache = AmpacheClient('https://music.silosneeded.com', '4dee7fe5554cf581a3f69ea023ea378a', '532000') -album = my_ampache.get_album(4724) -print(album) -- cgit v1.2.3