зеркало из
				https://github.com/viginum-datalab/twscrape.git
				synced 2025-10-31 14:06:12 +02:00 
			
		
		
		
	rename project; add retries
Этот коммит содержится в:
		
							родитель
							
								
									3555542009
								
							
						
					
					
						Коммит
						ae6eabe271
					
				
							
								
								
									
										13
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								Makefile
									
									
									
									
									
								
							| @ -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,15 +1,15 @@ | |||||||
| [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', | ||||||
| @ -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) | ||||||
		Загрузка…
	
	
			
			x
			
			
		
	
		Ссылка в новой задаче
	
	Block a user
	 Vlad Pronsky
						Vlad Pronsky