From f9ac269b6977038fd56bd54625fabd0077bccdd4 Mon Sep 17 00:00:00 2001 From: hyugogirubato <65763543+hyugogirubato@users.noreply.github.com> Date: Thu, 18 May 2023 20:09:50 +0200 Subject: [PATCH] v1.0.3 --- .travis.yml | 23 ----------------------- CHANGELOG.md | 14 ++++++++++++++ README.md | 2 +- pyuptobox/__init__.py | 2 +- pyuptobox/client.py | 43 ++++++++++++++++++++++--------------------- pyuptobox/utils.py | 2 +- setup.py | 2 +- 7 files changed, 40 insertions(+), 48 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 238144d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -language: python -matrix: - include: - - python: 3.4 - dist: trusty - sudo: false - - python: 3.5 - dist: trusty - sudo: false - - python: 3.5-dev - dist: trusty - sudo: false - - python: 3.6 - dist: trusty - sudo: false - - python: 3.6-dev - dist: trusty - sudo: false - - python: 3.7 - dist: xenial - sudo: true -install: - - python setup.py -q install diff --git a/CHANGELOG.md b/CHANGELOG.md index 1af4d20..bfbadb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.3] - 2023-05-18 + +### Changed + +- Remove the `.yml` file. +- Null checking optimization. +- New header system for requests. + +### Fixed + +- Missing params args for `get_file_link`. +- Fixed `README.md`. + ## [1.0.2] - 2023-04-03 ### Added @@ -31,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Initial Release. +[1.0.3]: https://github.com/hyugogirubato/pyuptobox/releases/tag/v1.0.3 [1.0.2]: https://github.com/hyugogirubato/pyuptobox/releases/tag/v1.0.2 [1.0.1]: https://github.com/hyugogirubato/pyuptobox/releases/tag/v1.0.0 [1.0.0]: https://github.com/hyugogirubato/pyuptobox/releases/tag/v1.0.0 diff --git a/README.md b/README.md index 4bef5b1..eb6d923 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ if __name__ == "__main__": data = client.login(token="USER_TOKEN") # get file info - info = client.get_file_info(file_codes=file_code) + info = client.get_file_info(file_codes=[file_code]) # get file download link link = client.get_file_link(file_code=file_code) diff --git a/pyuptobox/__init__.py b/pyuptobox/__init__.py index c1695a4..de9ddac 100644 --- a/pyuptobox/__init__.py +++ b/pyuptobox/__init__.py @@ -1,4 +1,4 @@ from .client import Client from .utils import * -__version__ = "1.0.2" +__version__ = "1.0.3" diff --git a/pyuptobox/client.py b/pyuptobox/client.py index 3337848..5be7bcf 100644 --- a/pyuptobox/client.py +++ b/pyuptobox/client.py @@ -24,15 +24,18 @@ def __init__(self): def _request(self, **kwargs) -> dict: params = kwargs.get("params", {}) - if self._token is not None: + if self._token: params["token"] = self._token + headers = Client.HEADERS.copy() + headers.update(kwargs.get("headers", {})) + r = self._session.request( - method=kwargs.get("method", "GET").upper(), + method=kwargs.get("method", "GET"), url=kwargs.get("url", self._api), params=params, - data=kwargs.get("data", None), - headers=kwargs.get("headers", Client.HEADERS)) + data=kwargs.get("data"), + headers=headers) content = r.json() if content.get("statusCode", 0) in [0, 18, 22, 24, 39]: @@ -40,11 +43,11 @@ def _request(self, **kwargs) -> dict: raise Exception(r.text) def login(self, **kwargs) -> dict: - login = kwargs.get("login", None) - password = kwargs.get("password", None) - token = kwargs.get("token", None) - xfss = kwargs.get("xfss", None) - if login is not None and password is not None: + login = kwargs.get("login") + password = kwargs.get("password") + token = kwargs.get("token") + xfss = kwargs.get("xfss") + if login and password: r = self._session.request( method="POST", url=f"{self._web}/login", @@ -52,14 +55,14 @@ def login(self, **kwargs) -> dict: ) if "My account" not in r.text: raise InvalidCredentials("Invalid password/login") - elif token is not None: + elif token: self._token = token - elif xfss is not None: + elif xfss: self._session.cookies.set("xfss", xfss) else: raise InvalidCredentials("Invalid login credentials") - if token is None: + if not token: r = self._session.request(method="GET", url=f"{self._web}/my_account") soup = BeautifulSoup(r.content, "html.parser") content_wrapper_div = soup.find("div", {"id": "content-wrapper"}) @@ -100,9 +103,9 @@ def get_voucher(self, time: int = 30, quantity: int = 1) -> list: def get_file_link(self, file_code: str, waiting_token: str = None) -> dict: params = {"file_code": file_code} - if waiting_token is not None: + if waiting_token: params["waitingToken"] = waiting_token - return self._request(url=f"{self._api}/link")["data"] + return self._request(url=f"{self._api}/link", params=params)["data"] def get_file_info(self, file_codes: list) -> list: return self._request(url=f"{self._api}/link/info", params={"fileCodes": ",".join(file_codes)})["data"]["list"] @@ -131,13 +134,13 @@ def get_public_files(self, path: str, limit: int = 10, offset: int = 0, order: s def set_file_info(self, file_code: str, public: bool = None, name: str = None, description: str = None, password: str = None) -> bool: params = {"file_code": file_code} - if public is not None: + if public: params["public"] = int(public) - if name is not None: + if name: params["new_name"] = name - if description is not None: + if description: params["description"] = description - if password is not None: + if password: params["password"] = password return self._request(method="PATCH", url=f"{self._api}/user/files", params=params)["data"]["updated"] == 1 @@ -182,13 +185,11 @@ def delete_folder(self, folder: int) -> None: def upload(self, path: Path) -> dict: multi = MultipartEncoder(fields={"files": (path.name, open(path, "rb"))}) - headers = Client.HEADERS.copy() - headers["content-type"] = multi.content_type return self._request( method="POST", url="https:" + self._request(url=f"{self._api}/upload")["data"]["uploadLink"], data=multi, - headers=headers + headers={"content-type": multi.content_type} )["files"] def get_pin(self, file_code: str) -> dict: diff --git a/pyuptobox/utils.py b/pyuptobox/utils.py index c51d0dd..5b4f6f5 100644 --- a/pyuptobox/utils.py +++ b/pyuptobox/utils.py @@ -18,7 +18,7 @@ def get_size(bytes_size: int) -> str: def get_code(value: str) -> str: if value.startswith("https://"): value = re.search(r"\.com/(\w+)", value).group(1) - if value is None or len(value) != 12: + if not value or len(value) != 12: raise InvalidFileCode("The file code format is invalid") return value diff --git a/setup.py b/setup.py index bbffb73..12544ed 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name="pyuptobox", - version="1.0.2", + version="1.0.3", description="Python SDK to interact with Uptobox API.", long_description=LONG_DESCRIPTION, long_description_content_type="text/markdown",