Skip to content

Commit

Permalink
style: check code format style
Browse files Browse the repository at this point in the history
  • Loading branch information
ReaJason committed Jan 13, 2024
1 parent 67cb8cd commit 45a7188
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 47 deletions.
18 changes: 11 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ $ python -m pip install git+https://github.com/ReaJason/xhs
> maybe now is more complex, Thanks [@NanmiCoder](https://github.com/NanmiCoder)
Please find in the [document](https://reajason.github.io/xhs/basic)

1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@
basic
crawl
creator

5 changes: 3 additions & 2 deletions example/basic_sign_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import time

from flask import Flask, request
from playwright.sync_api import sync_playwright
from gevent import monkey
import time
from playwright.sync_api import sync_playwright

monkey.patch_all()

Expand Down
4 changes: 3 additions & 1 deletion example/basic_usage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import datetime
import json
from time import sleep
from xhs import XhsClient, DataFetchError, help

from playwright.sync_api import sync_playwright

from xhs import DataFetchError, XhsClient, help


def sign(uri, data=None, a1="", web_session=""):
for _ in range(10):
Expand Down
4 changes: 3 additions & 1 deletion example/login_phone.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import datetime
import json
from time import sleep
from xhs import XhsClient, DataFetchError

from playwright.sync_api import sync_playwright

from xhs import DataFetchError, XhsClient


def sign(uri, data=None, a1="", web_session=""):
for _ in range(10):
Expand Down
6 changes: 4 additions & 2 deletions example/login_qrcode.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import datetime
import json
import qrcode
from time import sleep
from xhs import XhsClient, DataFetchError

import qrcode
from playwright.sync_api import sync_playwright

from xhs import XhsClient


def sign(uri, data=None, a1="", web_session=""):
for _ in range(10):
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ license_files = LICENSE
addopts = -v --cov=xhs --cov-report term --cov-report xml

[flake8]
ignore = E501
exclude =
tests/**,
per-file-ignores =
xhs/__init__.py: F401
xhs/help.py: E501
xhs/core.py: E501
tests/__init__.py: E501
docs/conf.py: E402
4 changes: 2 additions & 2 deletions xhs-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ docker buildx create --name mybuilder --driver docker-container

docker buildx use mybuilder

docker buildx build --platform linux/arm64,linux/amd64 -t reajason/xhs-api . --push
```
docker buildx build --platform linux/arm64,linux/amd64 -t reajason/xhs-api . --push
```
5 changes: 3 additions & 2 deletions xhs-api/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import time

from flask import Flask, request
from playwright.sync_api import sync_playwright
from gevent import monkey
import time
from playwright.sync_api import sync_playwright

monkey.patch_all()

Expand Down
2 changes: 1 addition & 1 deletion xhs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
from .__version__ import __author__, __copyright__, __title__, __version__
from .core import (FeedType, Note, NoteType, SearchNoteType, SearchSortType,
XhsClient)
from .exception import DataFetchError, IPBlockError, SignError, ErrorEnum
from .exception import DataFetchError, ErrorEnum, IPBlockError, SignError

logging.getLogger(__name__).addHandler(NullHandler())
30 changes: 12 additions & 18 deletions xhs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@
import requests
from lxml import etree

from xhs.exception import DataFetchError, IPBlockError, SignError, ErrorEnum
from .help import (
cookie_jar_to_cookie_str,
download_file,
get_imgs_url_from_note,
get_search_id,
get_valid_path_name,
get_video_url_from_note,
sign,
update_session_cookies_from_cookie, parse_xml,
)
from xhs.exception import DataFetchError, ErrorEnum, IPBlockError, SignError

from .help import (cookie_jar_to_cookie_str, download_file,
get_imgs_url_from_note, get_search_id, get_valid_path_name,
get_video_url_from_note, parse_xml, sign,
update_session_cookies_from_cookie)


class FeedType(Enum):
Expand Down Expand Up @@ -438,8 +433,7 @@ def get_user_all_notes(self, user_id: str, crawl_interval: int = 1):
try:
note = self.get_note_by_id(note_id)
except DataFetchError as e:
if (ErrorEnum.NOTE_ABNORMAL.value.msg in e.__repr__()
or ErrorEnum.NOTE_SECRETE_FAULT.value.msg in e.__repr__()):
if ErrorEnum.NOTE_ABNORMAL.value.msg in e.__repr__() or ErrorEnum.NOTE_SECRETE_FAULT.value.msg in e.__repr__():
continue
else:
raise
Expand Down Expand Up @@ -523,8 +517,7 @@ def get_note_all_comments(self, note_id: str, crawl_interval: int = 1):
cur_sub_comments = comment["sub_comments"]
result.extend(cur_sub_comments)
sub_comments_has_more = (
comment["sub_comment_has_more"]
and len(cur_sub_comments) < cur_sub_comment_count
comment["sub_comment_has_more"] and len(cur_sub_comments) < cur_sub_comment_count
)
sub_comment_cursor = comment["sub_comment_cursor"]
while sub_comments_has_more:
Expand All @@ -534,7 +527,7 @@ def get_note_all_comments(self, note_id: str, crawl_interval: int = 1):
)
sub_comments = sub_comments_res["comments"]
sub_comments_has_more = (
sub_comments_res["has_more"] and len(sub_comments) == page_num
sub_comments_res["has_more"] and len(sub_comments) == page_num
)
sub_comment_cursor = sub_comments_res["cursor"]
result.extend(sub_comments)
Expand Down Expand Up @@ -710,8 +703,9 @@ def create_complete_multipart_upload(self, file_id: str, token: str, upload_id:
etag_elem.text = part['ETag'].replace('"', '&quot;')
part_elem.append(etag_elem)
root.append(part_elem)
xml_string = ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ etree.tostring(root, encoding='UTF-8').decode("UTF-8").replace("&amp;", "&"))
xml_string = ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + etree.tostring(root,
encoding='UTF-8').decode(
"UTF-8").replace("&amp;", "&"))
print(xml_string)
print(file_id)
print(token)
Expand Down
1 change: 1 addition & 0 deletions xhs/exception.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum
from typing import NamedTuple

from requests import RequestException


Expand Down
8 changes: 2 additions & 6 deletions xhs/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,7 @@ def right_without_sign(num, bit=0) -> int:

def tripletToBase64(e):
return (
lookup[63 & (e >> 18)] +
lookup[63 & (e >> 12)] +
lookup[(e >> 6) & 63] +
lookup[e & 63]
lookup[63 & (e >> 18)] + lookup[63 & (e >> 12)] + lookup[(e >> 6) & 63] + lookup[e & 63]
)


Expand Down Expand Up @@ -311,8 +308,7 @@ def b64Encode(e):
U.append(lookup[F >> 2] + lookup[(F << 4) & 63] + "==")
elif 2 == W:
F = (e[P - 2] << 8) + e[P - 1]
U.append(lookup[F >> 10] + lookup[63 & (F >> 4)] +
lookup[(F << 2) & 63] + "=")
U.append(lookup[F >> 10] + lookup[63 & (F >> 4)] + lookup[(F << 2) & 63] + "=")
return "".join(U)


Expand Down

0 comments on commit 45a7188

Please sign in to comment.