Skip to content

Commit

Permalink
Fix dependencies, user agent, upload URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ftruzzi committed Jun 20, 2023
1 parent 7d81b57 commit 61d1ad8
Show file tree
Hide file tree
Showing 6 changed files with 764 additions and 472 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ jobs:

- name: Install poetry
run: |
curl -sSL \
"https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py" | python
curl -sSL "https://install.python-poetry.org" | python
# Adding `poetry` to `$PATH`:
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Set up cache
Expand All @@ -37,7 +36,6 @@ jobs:
- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
poetry config experimental.new-installer false
poetry install
- name: Run tests
run: |
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ jobs:

- name: Install poetry
run: |
curl -sSL \
"https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py" | python
curl -sSL "https://install.python-poetry.org" | python
# Adding `poetry` to `$PATH`:
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
poetry config experimental.new-installer false
poetry install
- name: Config PyPI token
Expand Down
1 change: 0 additions & 1 deletion libgen_uploader/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def check_upload_form_response(response: BeautifulSoup) -> bool:
def check_metadata_form_response(
response: BeautifulSoup,
) -> str:

if error_el := response.select_one(".error") or response.select_one(".form_error"):
error_text = error_el.text.strip()
raise LibgenUploadException(f"File save failed: {error_text}")
Expand Down
11 changes: 6 additions & 5 deletions libgen_uploader/libgen_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# https://github.com/jmcarp/robobrowser/issues/93
import werkzeug

werkzeug.cached_property = werkzeug.utils.cached_property
werkzeug.cached_property = werkzeug.utils.cached_property # type: ignore

from bs4 import BeautifulSoup
from cerberus import schema
Expand Down Expand Up @@ -96,7 +96,6 @@ def __init__(
def _init_browser(self):
self._browser = RoboBrowser(
parser="html.parser",
user_agent=f"libgen_uploader-v{LIBGEN_UPLOADER_VERSION} github.com/ftruzzi/libgen_uploader",
)
self._browser.session.auth = (UPLOAD_USERNAME, UPLOAD_PASSWORD)

Expand Down Expand Up @@ -138,13 +137,15 @@ def _validate_file(file: Union[str, bytes]) -> Union[str, bytes]:
def _upload_file(self, file: Union[str, bytes], library: str) -> BeautifulSoup:
if library == "scitech":
self._init_browser()
self._browser.open(SCITECH_UPLOAD_URL)
upload_url = SCITECH_UPLOAD_URL
elif library == "fiction":
self._init_browser()
self._browser.open(FICTION_UPLOAD_URL)
upload_url = FICTION_UPLOAD_URL
else:
raise ValueError(f"Unknown library to upload to: {library}")

self._browser.open(upload_url)

if isinstance(file, str):
encoder = MultipartEncoder(
fields={"file": (basename(file), open(file, "rb"))}
Expand All @@ -169,7 +170,7 @@ def _upload_file(self, file: Union[str, bytes], library: str) -> BeautifulSoup:
)
session = self._browser.session
response = session.post(
"https://library.bz/fiction/upload/",
upload_url,
data=monitor,
headers={"Content-Type": monitor.content_type},
)
Expand Down
Loading

0 comments on commit 61d1ad8

Please sign in to comment.