diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ff136c3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "python.linting.pylintEnabled": true, + "python.linting.pydocstyleEnabled": true, + "python.linting.enabled": true +} \ No newline at end of file diff --git a/README.md b/README.md index e8f4e30..d5a24ac 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,10 @@ Client for [Lychee](https://github.com/LycheeOrg/Lychee), written in Python. -Lychee is a photo management system I've been using for years. I had the idea to make a « Lychee filesystem » with [FUSE](https://fr.wikipedia.org/wiki/Filesystem_in_Userspace), so I needed an API client. +Lychee is a photo management system I've been using for years. I had the idea to +make a « Lychee filesystem » with +[FUSE](https://fr.wikipedia.org/wiki/Filesystem_in_Userspace), so I needed an +API client. ## Installation @@ -13,10 +16,13 @@ python3 -m pip install pychee ## Notes My reference is [this documentation](https://lycheeorg.github.io/docs/api.html). -The API is partially implemented and focused on photo management, _i.e._ only `Albums`, `Photo`, `Frame`, `Sharing` and `Settings::setLogin`. Users can do whatever they want with their albums and photos and change their password. +The API is partially implemented and focused on photo management, _i.e._ only +`Albums`, `Photo`, `Frame`, `Sharing` and `Settings::setLogin`. Users can do +whatever they want with their albums and photos and change their password. Disclaimer : I usually suck at coding, so use with caution and at your own risks. -Tested with Lychee v4.7.0. The code probably won't be retrocompatible and should just work with the latest version. +Tested with Lychee v4.7.0. The code probably won't be retrocompatible and should +just work with the latest version. ## TODO @@ -24,7 +30,10 @@ Add tests ## Example usage -> ⚠️ `pychee` returns exactly what the API sends back, just parsing it to `dict` if necessary. As sample answers are not documented in the API and because answers tend to change over time, you should inspect requests in browser if your client code does not works anymore. +> ⚠️ `pychee` returns exactly what the API sends back, just parsing it to `dict` +if necessary. As sample answers are not documented in the API and because answers +tend to change over time, you should inspect requests in browser if your client +code does not works anymore. A sample of common API calls : @@ -65,4 +74,5 @@ client.logout() ## Documentation -Documentation is automatically published there : https://chostakovitch.github.io/pychee/index.html +Documentation is automatically published on GitHub: +https://chostakovitch.github.io/pychee/index.html diff --git a/pychee/pychee.py b/pychee/pychee.py index 78bb00d..246fc16 100644 --- a/pychee/pychee.py +++ b/pychee/pychee.py @@ -3,20 +3,21 @@ """ # pychee: Client for Lychee, written in Python. -For additonal information, visit: https://github.com/LycheeOrg/Lychee. +For additional information, visit: https://github.com/LycheeOrg/Lychee. """ from posixpath import join from typing import List -from requests import Session from urllib.parse import unquote -__version__ = '0.2.1' +from requests import Session + +__version__ = '0.2.2' class LycheeForbidden(Exception): """Raised when the Lychee request is unauthorized.""" class LycheeNotFound(Exception): - """Raised when the requested ressource was not found.""" + """Raised when the requested resource was not found.""" class LycheeError(Exception): """Raised for general Lychee errors.""" @@ -54,7 +55,7 @@ def __init__(self, prefix_url: str, *args, **kwargs): # Initial CSRF super().request('GET', self._prefix_url) self._set_csrf_header() - # Lychee now explicitely requires client to accept JSON, + # Lychee now explicitly requires client to accept JSON, # else throws exception self.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01' @@ -74,7 +75,7 @@ def request(self, method, url, *args, **kwargs): def _set_csrf_header(self) -> None: """ - Sets CSRF header from cookie for the whole session. + Set CSRF header from cookie for the whole session. CSRF generally prevents an attacker from forging a request sent from another website, e.g. in a JS script, by forcing @@ -86,7 +87,9 @@ def _set_csrf_header(self) -> None: csrf_token = self.cookies.get(self._CSRF_COOKIE) if csrf_token is not None: if csrf_token != self.headers.get(self._CSRF_HEADER): - self.headers[self._CSRF_HEADER] = unquote(csrf_token).replace('=', '') + self.headers[self._CSRF_HEADER] = unquote( + csrf_token + ).replace('=', '') class LycheeClient: """ @@ -120,6 +123,15 @@ def get_albums(self) -> dict: """ return self._session.post('Albums::get', json={}).json() + def get_albums_tree(self): + """ + Get List of Album Trees in Lychee. + + Returns a list of albums dictionaries or an informative message on + failure. + """ + return self._session.post('Albums::tree', json={}).json() + def get_albums_position_data(self) -> dict: """ Get List of Available Album Data. diff --git a/pyproject.toml b/pyproject.toml index 374b58c..63bda21 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,3 +4,39 @@ requires = [ "wheel" ] build-backend = "setuptools.build_meta" + +[project] +name = "pychee" +description = "Client for Lychee, written in Python." +readme = "README.md" +dynamic = ["version"] +license = {file = "LICENSE"} +maintainers = [ + {name = "Quentin Duchemin", email = "quentinduchemin@tuta.io"} +] +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Operating System :: OS Independent", + "Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries" +] +requires-python = ">=3.7" + +[project.optional-dependencies] +dev = [ + "pydocstyle", + "pylint", +] +test = [ + "pytest", +] + +dependencies = [ + "requests" +] + +[project.urls] +Home = "https://github.com/Chostakovitch/pychee" +Repository = "https://github.com/Chostakovitch/pychee" +Issues = "https://github.com/Chostakovitch/pychee/issues" +Documentation = "https://chostakovitch.github.io/pychee/index.html" diff --git a/setup.cfg b/setup.cfg index 6ae2513..dbc2b3f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,19 +1,3 @@ -[metadata] -name = pychee -version = attr: pychee.pychee.__version__ -author = Quentin Duchemin -author_email = quentinduchemin@tuta.io -description = Client for Lychee, written in Python. -long_description = file: README.md -long_description_content_type = text/markdown -url = https://github.com/Chostakovitch/pychee -keywords = lychee -license = AGPL-3.0 -classifiers = - License :: OSI Approved :: GNU Affero General Public License v3 - Programming Language :: Python :: 3 - Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries - [options] zip_safe = False include_package_data = True