Этот коммит содержится в:
Vlad Pronsky 2023-05-06 15:48:03 +03:00
родитель 3555542009
Коммит ae6eabe271
16 изменённых файлов: 31 добавлений и 26 удалений

Просмотреть файл

@ -1,17 +1,22 @@
.PHONY: all build
all: all:
@echo "hi" @echo "hi"
build:
python -m build
lint: lint:
ruff check twapi ruff check twscrape
lint-fix: lint-fix:
ruff check --fix twapi ruff check --fix twscrape
pylint: pylint:
pylint --errors-only twapi pylint --errors-only twscrape
test: test:
pytest --cov=twapi tests/ pytest --cov=twscrape tests/
act: act:
act --container-architecture linux/amd64 act --container-architecture linux/amd64

Просмотреть файл

@ -1,21 +1,21 @@
[build-system] [build-system]
requires = ['setuptools>=61', 'setuptools_scm>=6.2'] requires = ["hatchling"]
build-backend = "setuptools.build_meta" build-backend = "hatchling.build"
[project] [project]
name = "tw-api" name = "twscrape"
version = "0.1.0" version = "0.1.0"
authors = [{name = "vladkens"}] authors = [{name = "vladkens", email = "v.pronsky@gmail.com"}]
description = "Twitter GraphQL and Search API implementation with SNScrape data models" description = "Twitter GraphQL and Search API implementation with SNScrape data models"
readme = "readme.md" readme = "readme.md"
requires-python = ">=3.10" requires-python = ">=3.10"
keywords = ["twitter", "api", "scrape", "snscrape", "tw-api", "twapi"] keywords = ["twitter", "scrape", "scrapper", "api", "snscrape"]
license = {text = "MIT"} license = {text = "MIT"}
classifiers = [ classifiers = [
'Development Status :: 4 - Beta', 'Development Status :: 4 - Beta',
'License :: OSI Approved :: MIT License', 'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3.11',
] ]
dependencies = [ dependencies = [
"aiosqlite==0.17.0", "aiosqlite==0.17.0",
@ -34,10 +34,10 @@ dev = [
] ]
[project.urls] [project.urls]
repository = "https://github.com/vladkens/tw-api" repository = "https://github.com/vladkens/twscrape"
[tool.setuptools] [tool.setuptools]
packages = ['twapi'] packages = ['twscrape']
[tool.pylint] [tool.pylint]
max-line-length = 99 max-line-length = 99

Просмотреть файл

@ -18,8 +18,8 @@ pip install https://github.com/vladkens/tw-api
```python ```python
import asyncio import asyncio
from twapi import AccountsPool, API, gather from twscrape import AccountsPool, API, gather
from twapi.logger import set_log_level from twscrape.logger import set_log_level
async def main(): async def main():
pool = AccountsPool() # or pool = AccountsPool("path-to.db") - default is `accounts.db` pool = AccountsPool() # or pool = AccountsPool("path-to.db") - default is `accounts.db`

Просмотреть файл

@ -2,8 +2,8 @@ import asyncio
import json import json
import os import os
from twapi import API, AccountsPool, gather from twscrape import API, AccountsPool, gather
from twapi.logger import set_log_level from twscrape.logger import set_log_level
BASE_DIR = os.path.dirname(__file__) BASE_DIR = os.path.dirname(__file__)
DATA_DIR = os.path.join(BASE_DIR, "mocked-data") DATA_DIR = os.path.join(BASE_DIR, "mocked-data")
@ -247,10 +247,9 @@ async def test_user_tweets_and_replies():
async def main(): async def main():
# prepare mock files from real twitter replies # prepare mock files from real twitter replies
# you need to have some account to perform this # you need to have some account to perform this
FRESH = False
pool = AccountsPool() pool = AccountsPool()
pool.restore()
api = API(pool) api = API(pool)
jobs = [ jobs = [
@ -269,7 +268,7 @@ async def main():
for filename, fn in jobs: for filename, fn in jobs:
filename = os.path.join(DATA_DIR, f"{filename}") filename = os.path.join(DATA_DIR, f"{filename}")
print("-" * 20) print("-" * 20)
if os.path.exists(filename): if os.path.exists(filename) and FRESH is False:
print(f"File {filename} already exists") print(f"File {filename} already exists")
continue continue

Просмотреть файл

@ -1,7 +1,7 @@
import os import os
from twapi.accounts_pool import AccountsPool from twscrape.accounts_pool import AccountsPool
from twapi.db import DB from twscrape.db import DB
DB_FILE = "/tmp/twapi_test.db" DB_FILE = "/tmp/twapi_test.db"

Просмотреть файл

Просмотреть файл

@ -3,7 +3,7 @@ import sqlite3
from dataclasses import asdict, dataclass from dataclasses import asdict, dataclass
from datetime import datetime from datetime import datetime
from httpx import AsyncClient from httpx import AsyncClient, AsyncHTTPTransport
from .constants import TOKEN from .constants import TOKEN
@ -57,7 +57,8 @@ class Account:
return rs return rs
def make_client(self) -> AsyncClient: def make_client(self) -> AsyncClient:
client = AsyncClient(proxies=self.proxy) transport = AsyncHTTPTransport(retries=2)
client = AsyncClient(proxies=self.proxy, follow_redirects=True, transport=transport)
# saved from previous usage # saved from previous usage
client.cookies.update(self.cookies) client.cookies.update(self.cookies)

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл