Skip to content

Commit

Permalink
πŸ›  Move to github actions ci
Browse files Browse the repository at this point in the history
  • Loading branch information
sudoguy committed Dec 23, 2022
1 parent 1ffa9cd commit 7e14b10
Show file tree
Hide file tree
Showing 11 changed files with 947 additions and 941 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
47 changes: 12 additions & 35 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: debug-statements
Expand All @@ -11,49 +11,26 @@ repos:
- id: mixed-line-ending
args: ["--fix=lf"]

- repo: https://github.com/PyCQA/autoflake
rev: v1.4
hooks:
- id: autoflake
args:
[
"--in-place",
"--remove-all-unused-imports",
"--remove-unused-variable",
]

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--py37-plus"]

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.192
hooks:
- id: ruff
# Respect `exclude` and `extend-exclude` settings.
args: ["--force-exclude", "--fix"]

- repo: https://github.com/PyCQA/isort
rev: 5.11.4
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.12.0
hooks:
- id: black
files: '\.py$'

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies:
[
"flake8-blind-except",
"flake8-commas",
"flake8-comprehensions",
"flake8-deprecated",
"flake8-broken-line",
"flake8-bugbear",
"flake8-mutable",
"flake8-tidy-imports",
"flake8-print",
"flake8-logging-format",
"flake8-pytest-style",
]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ and then after you login run

```shell
python quickstart.py
```
```
1,737 changes: 862 additions & 875 deletions poetry.lock

Large diffs are not rendered by default.

44 changes: 37 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ html = ["parsel"]
[tool.poetry.dev-dependencies]
pytest = "^7.0.0"
black = "^22.1.0"
pytest-cov = "^3.0.0"
pytest-cov = "^4.0.0"
pytest-mock = "^3.2.0"
pre-commit = "^2.6.0"
flake8 = "^4.0.1"
flake8 = "^5.0.0"
flake8-blind-except = "^0.2.1"
flake8-commas = "^2.0.0"
flake8-comprehensions = "^3.2.0"
flake8-deprecated = "^1.3"
flake8-deprecated = "^2.0.1"
flake8-mutable = "^1.2.0"
flake8-tidy-imports = "^4.0.0"
flake8-print = "^4.0.0"
flake8-print = "^5.0.0"
isort = "^5.1.4"
mypy = "*"
bump2version = "^1.0.0"
pytest-asyncio = "^0.18.2"
flake8-broken-line = "^0.4.0"
pytest-asyncio = "^0.20.2"
flake8-broken-line = "^0.6.0"
flake8-bugbear = "^22.7.1"
flake8-logging-format = "^0.6.0"
flake8-logging-format = "^0.9.0"
flake8-pytest-style = "^1.4.0"
pylint = "^2.7.2"

Expand All @@ -88,3 +88,33 @@ exclude = '''
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

[tool.isort]
profile = "black"
line_length = 100


[tool.ruff]
exclude = [
'.git',
'__pycache__',
'.venv',
'.eggs',
'*.egg',
]
ignore = [
"E501", # line too long, handled by black
"C901", # too complex
]
line-length = 100
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
# "I", # isort
"C", # flake8-comprehensions
"B", # flake8-bugbear
]

[tool.ruff.mccabe]
max-complexity = 6
5 changes: 4 additions & 1 deletion quicklogin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import asyncio

from tiktokpy import TikTokPy


async def main():
async with TikTokPy() as bot:
# Login to TikTok
await bot.login_session()

asyncio.run(main())

asyncio.run(main())
3 changes: 3 additions & 0 deletions quickstart.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio

from tiktokpy import TikTokPy


async def main():
async with TikTokPy() as bot:
# Do you want to get trending videos? You can!
Expand Down Expand Up @@ -32,4 +34,5 @@ async def main():

# and many other things πŸ˜‰


asyncio.run(main())
11 changes: 0 additions & 11 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ replace = version = "{new_version}"

[bumpversion:file:tests/test_tiktokpy.py]

[flake8]
max-line-length = 100
max-complexity = 6
exclude = .git,__pycache__,.venv,.eggs,*.egg

[isort]
include_trailing_comma = true
use_parentheses = true
multi_line_output = 3
line_length = 100
known_first_party = tiktokpy

[tool:pytest]
norecursedirs = *.egg .eggs dist build docs .tox .git __pycache__
Expand Down
5 changes: 3 additions & 2 deletions tiktokpy/bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, settings_path: Optional[str] = None):
logger.info("πŸ›‘ Cookies not found, anonymous mode")

self.headless: bool = settings.get("HEADLESS", True)
self.lang: str = settings.get("LANG", "en")

async def __aenter__(self):
await self.init_bot()
Expand Down Expand Up @@ -68,14 +69,14 @@ async def __aexit__(
humanize.naturaldelta(datetime.now() - self.started_at),
)

async def trending(self, amount: int = 50, lang: str = settings.get("LANG")) -> List[FeedItem]:
async def trending(self, amount: int = 50) -> List[FeedItem]:
logger.info("πŸ“ˆ Getting trending items")

if amount <= 0:
logger.warning("⚠️ Wrong amount! Return nothing")
return []

items = await Trending(client=self.client).feed(amount=amount, lang=lang)
items = await Trending(client=self.client).feed(amount=amount)

logger.info(f"πŸ“Ή Found {len(items)} videos")
_trending = FeedItems(__root__=items)
Expand Down
13 changes: 7 additions & 6 deletions tiktokpy/client/trending.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import asyncio
import random
from typing import List
from typing import List, Optional

from tqdm import tqdm
from dynaconf import settings
from tqdm import tqdm

from tiktokpy.client import Client
from tiktokpy.utils.client import catch_response_and_store
Expand All @@ -14,10 +14,11 @@


class Trending:
def __init__(self, client: Client):
def __init__(self, client: Client, lang: Optional[str] = None):
self.client = client
self.lang = lang or settings.get("LANG")

async def feed(self, amount: int, lang: str = settings.get("LANG")):
async def feed(self, amount: int):
page = await self.client.new_page(blocked_resources=["media", "image", "font"])

logger.debug('πŸ“¨ Request "Trending" page')
Expand All @@ -30,13 +31,13 @@ async def feed(self, amount: int, lang: str = settings.get("LANG")):
)
_ = await self.client.goto(
"/foryou",
query_params={"lang": lang},
query_params={"lang": self.lang},
page=page,
wait_until="networkidle",
)
logger.debug('πŸ“­ Got response from "Trending" page')

pbar = tqdm(total=amount, desc=f"πŸ“ˆ Getting trending {lang}")
pbar = tqdm(total=amount, desc=f"πŸ“ˆ Getting trending {self.lang}")
pbar.n = min(len(result), amount)
pbar.refresh()

Expand Down
7 changes: 4 additions & 3 deletions tiktokpy/client/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from typing import Callable, List
from typing import List

from playwright.async_api import Page, TimeoutError
from tqdm import tqdm
Expand Down Expand Up @@ -45,7 +45,7 @@ async def like(self, username: str, video_id: str):
wait_until="networkidle",
)

like_selector = f'span[data-e2e="like-icon"]'
like_selector = 'span[data-e2e="like-icon"]'
is_liked = await page.query_selector(f"{like_selector} > div > svg")

if is_liked:
Expand Down Expand Up @@ -250,7 +250,8 @@ async def _paginate_feed_list(
result: List[dict],
amount: int,
):
result_unique_amount: Callable = lambda: len(unique_dicts_by_key(result, "id"))
def result_unique_amount():
return len(unique_dicts_by_key(result, "id"))

pbar = tqdm(total=amount, desc=f"πŸ“ˆ Getting {username} feed")
pbar.n = min(result_unique_amount(), amount)
Expand Down

0 comments on commit 7e14b10

Please sign in to comment.