Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
hyugogirubato committed May 18, 2023
1 parent 7d5af2b commit f9ac269
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 48 deletions.
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyuptobox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .client import Client
from .utils import *

__version__ = "1.0.2"
__version__ = "1.0.3"
43 changes: 22 additions & 21 deletions pyuptobox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,45 @@ 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]:
return content
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",
data={"login": login, "password": password}
)
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"})
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyuptobox/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f9ac269

Please sign in to comment.