# Tweepy-self
[](https://t.me/cum_insider)
[](https://pypi.python.org/pypi/tweepy-self)
[](https://pypi.python.org/pypi/tweepy-self)
[](https://pypi.python.org/pypi/tweepy-self)
A modern, easy to use, feature-rich, and async ready API wrapper for Twitter's user API written in Python.
_NEW!_ Менеджер аккаунтов с базой данных:
- [tweepy-manager](https://github.com/alenkimov/tweepy-manager)
More libraries of the family:
- [better-proxy](https://github.com/alenkimov/better_proxy)
- [better-web3](https://github.com/alenkimov/better_web3)
Отдельное спасибо [Кузнице Ботов](https://t.me/bots_forge) за код для авторизации и разморозки! Подписывайтесь на их Telegram :)
Похожие библиотеки:
- [twikit (sync and async)](https://github.com/d60/twikit)
- [twitter-api-client (sync)](https://github.com/trevorhobenshield/twitter-api-client)
## Key Features
- Modern Pythonic API using async and await.
- Prevents user account automation detection.
## Installing
```bash
pip install tweepy-self
```
## Example
```python
import asyncio
import twitter
twitter_account = twitter.Account(auth_token="auth_token")
async def main():
async with twitter.Client(twitter_account) as twitter_client:
print(f"Logged in as @{twitter_account.username} (id={twitter_account.id})")
tweet = await twitter_client.tweet("Hello tweepy-self! <3")
print(tweet)
if __name__ == "__main__":
asyncio.run(main())
```
## Документация
### Некоторые истины
Имена пользователей нужно передавать БЕЗ знака `@`.
Чтобы наверняка убрать этот знак можно передать имя пользователя в функцию `twitter.utils.remove_at_sign()`
Automating user accounts is against the Twitter ToS. This library is a proof of concept and I cannot recommend using it. Do so at your own risk
### Как включить логирование
```python
import sys
from loguru import logger
logger.remove()
logger.add(sys.stdout, level="INFO")
logger.enable("twitter")
```
`level="DEBUG"` позволяет увидеть информацию обо всех запросах.
### Аккаунт
`twitter.Account`
#### Статусы аккаунта
- `UNKNOWN` - Статус аккаунта не установлен. Это статус по умолчанию.
- `BAD_TOKEN` - Неверный или мертвый токен.
- `SUSPENDED` - Действие учетной записи приостановлено. Тем не менее возможен запрос данных, а также авторизация через OAuth и OAuth2.
- `LOCKED` - Учетная запись заморожена (лок). Для разморозки (анлок) требуется прохождение капчи (funcaptcha).
- `CONSENT_LOCKED` - Учетная запись заморожена (лок). Условия для разморозки неизвестны.
- `GOOD` - Аккаунт в порядке.
Метод `Client.establish_status()` устанавливает статус аккаунта.
Также статус аккаунта может изменить любое взаимодействие с Twitter.
Поэтому, во время работы может внезапно быть вызвано исключение семейства `twitter.errors.BadAccount`.
Не каждое взаимодействие с Twitter достоверно определяет статус аккаунта.
Например, простой запрос данных об аккаунте честно вернет данные и не изменит статус, даже если действие вашей учетной записи приостановлено (`SUSPENDED`).
### Клиент
`twitter.Client`
#### Настройка
Клиент может быть сконфигурирован перед работой. Он принимает в себя следующие параметры:
- `wait_on_rate_limit` Если включено, то при достижении Rate Limit будет ждать, вместо того, чтобы выбрасывать исключение. Включено по умолчанию.
- `capsolver_api_key` API ключ сервиса [CapSolver](https://dashboard.capsolver.com/passport/register?inviteCode=m-aE3NeBGZLU). Нужен для автоматической разморозки аккаунта.
- `max_unlock_attempts` Максимальное количество попыток разморозки аккаунта. По умолчанию: 5.
- `auto_relogin` Если включено, то при невалидном токене (`BAD_TOKEN`) и предоставленных данных для авторизации (имя пользователя, пароль и totp_secret) будет произведен автоматический релогин (замена токена). Включено по умолчанию.
- `update_account_info_on_startup` Если включено, то на старте будет автоматически запрошена информация об аккаунте, а также установлен его статус. Включено по умолчанию.
- `**session_kwargs` Любые параметры, которые может принимать сессия `curl_cffi.requests.AsyncSession`. Например, можно передать параметр `proxy`.
Пример настройки клиента:
```python
async with twitter.Client(
twitter_account,
capsolver_api_key="CAP-00000000000000000000000000000000",
proxy="http://login:password@ip:port", # Можно передавать в любом формате, так как используется библиотека better_proxy
) as twitter_client:
...
```
### Доступные методы
Список всех методов.
#### Запрос информации о собственном аккаунте
```python
twitter_client.update_account_info()
print(twitter_client.account)
```
#### Запрос пользователя по username или по ID
```python
bro = twitter_client.request_user_by_username(bro_username)
bro = twitter_client.request_user_by_id(bro_id)
bros = twitter_client.request_users_by_ids([bro1_id, bro2_id, ...])
```
#### Загрузка изображения на сервер, смена аватарки и баннера
```python
image = open("image.png", "rb").read()
media = await twitter_client.upload_image(image)
avatar_image_url = await twitter_client.update_profile_avatar(media.id)
banner_image_url = await twitter_client.update_profile_banner(media.id)
```
#### Изменения данных профиля
```python
await twitter_client.update_birthdate(day=1, month=12, year=2000)
await twitter_client.update_profile( # Locks account!
name="New Name",
description="New description",
location="New York",
website="https://github.com/alenkimov/tweepy-self",
)
```
#### Включение TOTP (2FA)
```python
if await twitter_client.totp_is_enabled():
print(f"TOTP уже включен.")
return
await twitter_client.enable_totp()
```
#### Логин, если включен TOTP (2FA)
```python
import twitter
twitter_account = twitter.Account(auth_token="...", username="...", password="...", totp_secret="...")
await twitter_client.login()
print(f"Logged in! New auth_token: {twitter_account.auth_token}")
```
#### Смена имени пользователя и пароля
```python
twitter_account = twitter.Account("auth_token", password="password")
...
await twitter_client.change_username("new_username")
await twitter_client.request_user()
print(f"New username: {twitter_account.username}")
await twitter_client.change_password("new_password")
print(f"New password: {twitter_account.password}")
print(f"New auth_token: {twitter_account.auth_token}")
```
#### Авторизация с OAuth
```python
auth_code = await twitter_client.oauth(oauth_token, **oauth_params)
```
#### Авторизация с OAuth2
```python
# Изучите запросы сервиса и найдите подобные данные для авторизации (привязки):
oauth2_data = {
'response_type': 'code',
'client_id': 'TjFVQm52ZDFGWEtNT0tKaktaSWU6MTpjaQ',
'redirect_uri': 'https://waitlist.lens.xyz/tw/',
'scope': 'users.read tweet.read offline.access',
'state': 'state', # Может быть как статичным, так и динамическим.
'code_challenge': 'challenge',
'code_challenge_method': 'plain'
}
auth_code = await twitter_client.oauth2(**oauth2_data)
# Передайте код авторизации (привязки) сервису.
# Сервис также может потребовать state, если он динамический.
```
#### Отправка сообщения:
```python
bro = await twitter_client.request_user("bro_username")
await twitter_client.send_message(bro.id, "I love you!")
```
#### Запрос входящих сообщений:
```python
messages = await twitter_client.request_messages()
for message in messages:
message_data = message["message_data"]
recipient_id = message_data["recipient_id"]
sender_id = message_data["sender_id"]
text = message_data["text"]
print(f"[id {sender_id}] -> [id {recipient_id}]: {text}")
```
Так как мне почти не приходилось работать с сообщениями, я еще не сделал для этого удобных моделей.
Поэтому приходится работать со словарем.
#### Пост (твит)
```python
tweet = await twitter_client.tweet("I love you tweepy-self! <3")
print(f"Любовь выражена! Tweet id: {tweet.id}")
```
#### Лайк, репост (ретвит), коммент (реплай)
```python
# Лайк
print(f"Tweet {tweet_id} is liked: {await twitter_client.like(tweet_id)}")
# Репост (ретвит)
print(f"Tweet {tweet_id} is retweeted. Tweet id: {await twitter_client.repost(tweet_id)}")
# Коммент (реплай)
print(f"Tweet {tweet_id} is replied. Reply id: {await twitter_client.reply(tweet_id, 'tem razão')}")
```
#### Цитата
```python
tweet_url = 'https://twitter.com/CreamIce_Cone/status/1691735090529976489'
# Цитата (Quote tweet)
quote_tweet_id = await twitter_client.quote(tweet_url, 'oh....')
print(f"Quoted! Tweet id: {quote_tweet_id}")
```
#### Подписка и отписка
```python
# Подписываемся на Илона Маска
print(f"@{elonmusk.username} is followed: {await twitter_client.follow(elonmusk.id)}")
# Отписываемся от Илона Маска
print(f"@{elonmusk.username} is unfollowed: {await twitter_client.unfollow(elonmusk.id)}")
```
#### Закрепление твита
```python
pinned = await twitter_client.pin_tweet(tweet_id)
print(f"Tweet is pined: {pinned}")
```
#### Запрос своих и чужих подписчиков
```python
followers = await twitter_client.request_followers()
print("Твои подписчики:")
for user in followers:
print(user)
followings = await twitter_client.request_followings()
print(f"Ты подписан на:")
for user in followings:
print(user)
bro_followers = await twitter_client.request_followers(bro_id)
print(f"Подписчики твоего бро (id={bro_id}):")
for user in bro_followers:
print(user)
bro_followings = await twitter_client.request_followings(bro_id)
print(f"На твоего бро (id={bro_id}) подписаны:")
for user in bro_followings:
print(user)
```
#### Голосование
```python
vote_data = await twitter_client.vote(tweet_id, card_id, choice_number)
votes_count = vote_data["card"]["binding_values"]["choice1_count"]["string_value"]
print(f"Votes: {votes_count}")
```
Так как мне почти не приходилось работать с голосованиями, я еще не сделал для этого удобных моделей.
Поэтому приходится работать со словарем.
Raw data
{
"_id": null,
"home_page": "https://github.com/alenkimov/tweepy-self",
"name": "tweepy-self",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": null,
"author": "Alen",
"author_email": "alen.kimov@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/74/ac/551c53776b6de299afd91372d57e3b4092ee26e050487918717942e1e083/tweepy_self-1.11.1.tar.gz",
"platform": null,
"description": "# Tweepy-self\n[](https://t.me/cum_insider)\n[](https://pypi.python.org/pypi/tweepy-self)\n[](https://pypi.python.org/pypi/tweepy-self)\n[](https://pypi.python.org/pypi/tweepy-self)\n\nA modern, easy to use, feature-rich, and async ready API wrapper for Twitter's user API written in Python.\n\n_NEW!_ \u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u043e\u0432 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445:\n- [tweepy-manager](https://github.com/alenkimov/tweepy-manager)\n\nMore libraries of the family:\n- [better-proxy](https://github.com/alenkimov/better_proxy)\n- [better-web3](https://github.com/alenkimov/better_web3)\n\n\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e [\u041a\u0443\u0437\u043d\u0438\u0446\u0435 \u0411\u043e\u0442\u043e\u0432](https://t.me/bots_forge) \u0437\u0430 \u043a\u043e\u0434 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0440\u0430\u0437\u043c\u043e\u0440\u043e\u0437\u043a\u0438! \u041f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u0438\u0445 Telegram :)\n\n\u041f\u043e\u0445\u043e\u0436\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:\n- [twikit (sync and async)](https://github.com/d60/twikit)\n- [twitter-api-client (sync)](https://github.com/trevorhobenshield/twitter-api-client)\n\n## Key Features\n- Modern Pythonic API using async and await.\n- Prevents user account automation detection.\n\n## Installing\n```bash\npip install tweepy-self\n```\n\n## Example\n```python\nimport asyncio\nimport twitter\n\ntwitter_account = twitter.Account(auth_token=\"auth_token\")\n\nasync def main():\n async with twitter.Client(twitter_account) as twitter_client:\n print(f\"Logged in as @{twitter_account.username} (id={twitter_account.id})\")\n tweet = await twitter_client.tweet(\"Hello tweepy-self! <3\")\n print(tweet)\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n## \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f\n### \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u0442\u0438\u043d\u044b\n\u0418\u043c\u0435\u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0411\u0415\u0417 \u0437\u043d\u0430\u043a\u0430 `@`.\n\u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0443\u0431\u0440\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0437\u043d\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e `twitter.utils.remove_at_sign()`\n\nAutomating user accounts is against the Twitter ToS. This library is a proof of concept and I cannot recommend using it. Do so at your own risk\n\n### \u041a\u0430\u043a \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\n```python\nimport sys\nfrom loguru import logger\n\nlogger.remove()\nlogger.add(sys.stdout, level=\"INFO\")\nlogger.enable(\"twitter\")\n```\n\n`level=\"DEBUG\"` \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431\u043e \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445.\n\n### \u0410\u043a\u043a\u0430\u0443\u043d\u0442\n`twitter.Account`\n\n#### \u0421\u0442\u0430\u0442\u0443\u0441\u044b \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430\n- `UNKNOWN` - \u0421\u0442\u0430\u0442\u0443\u0441 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d. \u042d\u0442\u043e \u0441\u0442\u0430\u0442\u0443\u0441 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.\n- `BAD_TOKEN` - \u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0438\u043b\u0438 \u043c\u0435\u0440\u0442\u0432\u044b\u0439 \u0442\u043e\u043a\u0435\u043d.\n- `SUSPENDED` - \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0443\u0447\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 OAuth \u0438 OAuth2.\n- `LOCKED` - \u0423\u0447\u0435\u0442\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0437\u0430\u043c\u043e\u0440\u043e\u0436\u0435\u043d\u0430 (\u043b\u043e\u043a). \u0414\u043b\u044f \u0440\u0430\u0437\u043c\u043e\u0440\u043e\u0437\u043a\u0438 (\u0430\u043d\u043b\u043e\u043a) \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043a\u0430\u043f\u0447\u0438 (funcaptcha).\n- `CONSENT_LOCKED` - \u0423\u0447\u0435\u0442\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0437\u0430\u043c\u043e\u0440\u043e\u0436\u0435\u043d\u0430 (\u043b\u043e\u043a). \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u043e\u0440\u043e\u0437\u043a\u0438 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b.\n- `GOOD` - \u0410\u043a\u043a\u0430\u0443\u043d\u0442 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435.\n\n\u041c\u0435\u0442\u043e\u0434 `Client.establish_status()` \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0443\u0441 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430.\n\u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u0430\u0442\u0443\u0441 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 Twitter.\n\u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0436\u0435\u0442 \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u0430 `twitter.errors.BadAccount`.\n\n\u041d\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 Twitter \u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0442\u0430\u0442\u0443\u0441 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430.\n\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0435 \u0447\u0435\u0441\u0442\u043d\u043e \u0432\u0435\u0440\u043d\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442 \u0441\u0442\u0430\u0442\u0443\u0441, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0432\u0430\u0448\u0435\u0439 \u0443\u0447\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e (`SUSPENDED`).\n\n### \u041a\u043b\u0438\u0435\u043d\u0442\n`twitter.Client`\n\n#### \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\n\u041a\u043b\u0438\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u043f\u0435\u0440\u0435\u0434 \u0440\u0430\u0431\u043e\u0442\u043e\u0439. \u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:\n- `wait_on_rate_limit` \u0415\u0441\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043e, \u0442\u043e \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0438 Rate Limit \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u0412\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.\n- `capsolver_api_key` API \u043a\u043b\u044e\u0447 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 [CapSolver](https://dashboard.capsolver.com/passport/register?inviteCode=m-aE3NeBGZLU). \u041d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0430\u0437\u043c\u043e\u0440\u043e\u0437\u043a\u0438 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430.\n- `max_unlock_attempts` \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u0440\u0430\u0437\u043c\u043e\u0440\u043e\u0437\u043a\u0438 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e: 5.\n- `auto_relogin` \u0415\u0441\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043e, \u0442\u043e \u043f\u0440\u0438 \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u043e\u043c \u0442\u043e\u043a\u0435\u043d\u0435 (`BAD_TOKEN`) \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (\u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u0430\u0440\u043e\u043b\u044c \u0438 totp_secret) \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0440\u0435\u043b\u043e\u0433\u0438\u043d (\u0437\u0430\u043c\u0435\u043d\u0430 \u0442\u043e\u043a\u0435\u043d\u0430). \u0412\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.\n- `update_account_info_on_startup` \u0415\u0441\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043e, \u0442\u043e \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435 \u0431\u0443\u0434\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u0431 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0443\u0441. \u0412\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.\n- `**session_kwargs` \u041b\u044e\u0431\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u044f `curl_cffi.requests.AsyncSession`. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 `proxy`.\n\n\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430:\n```python\nasync with twitter.Client(\n twitter_account,\n capsolver_api_key=\"CAP-00000000000000000000000000000000\",\n proxy=\"http://login:password@ip:port\", # \u041c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 better_proxy\n) as twitter_client:\n ...\n```\n\n### \u0414\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b\n\u0421\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432.\n\n#### \u0417\u0430\u043f\u0440\u043e\u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0435\n```python\ntwitter_client.update_account_info()\nprint(twitter_client.account)\n```\n\n#### \u0417\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e username \u0438\u043b\u0438 \u043f\u043e ID\n\n```python\nbro = twitter_client.request_user_by_username(bro_username)\nbro = twitter_client.request_user_by_id(bro_id)\nbros = twitter_client.request_users_by_ids([bro1_id, bro2_id, ...])\n```\n\n#### \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440, \u0441\u043c\u0435\u043d\u0430 \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0438 \u0438 \u0431\u0430\u043d\u043d\u0435\u0440\u0430\n```python\nimage = open(\"image.png\", \"rb\").read()\nmedia = await twitter_client.upload_image(image)\navatar_image_url = await twitter_client.update_profile_avatar(media.id)\nbanner_image_url = await twitter_client.update_profile_banner(media.id)\n```\n\n#### \u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u044f\n```python\nawait twitter_client.update_birthdate(day=1, month=12, year=2000)\nawait twitter_client.update_profile( # Locks account!\n name=\"New Name\",\n description=\"New description\",\n location=\"New York\",\n website=\"https://github.com/alenkimov/tweepy-self\",\n)\n```\n\n#### \u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 TOTP (2FA)\n```python\nif await twitter_client.totp_is_enabled():\n print(f\"TOTP \u0443\u0436\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d.\")\n return\n\nawait twitter_client.enable_totp()\n```\n\n#### \u041b\u043e\u0433\u0438\u043d, \u0435\u0441\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d TOTP (2FA)\n```python\nimport twitter\n\ntwitter_account = twitter.Account(auth_token=\"...\", username=\"...\", password=\"...\", totp_secret=\"...\")\nawait twitter_client.login()\nprint(f\"Logged in! New auth_token: {twitter_account.auth_token}\")\n```\n\n#### \u0421\u043c\u0435\u043d\u0430 \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0430\u0440\u043e\u043b\u044f\n```python\ntwitter_account = twitter.Account(\"auth_token\", password=\"password\")\n...\nawait twitter_client.change_username(\"new_username\")\nawait twitter_client.request_user()\nprint(f\"New username: {twitter_account.username}\")\n\nawait twitter_client.change_password(\"new_password\")\nprint(f\"New password: {twitter_account.password}\")\nprint(f\"New auth_token: {twitter_account.auth_token}\")\n```\n\n#### \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0441 OAuth\n```python\nauth_code = await twitter_client.oauth(oauth_token, **oauth_params)\n```\n\n#### \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0441 OAuth2\n```python\n# \u0418\u0437\u0443\u0447\u0438\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043d\u0430\u0439\u0434\u0438\u0442\u0435 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (\u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438):\noauth2_data = {\n 'response_type': 'code',\n 'client_id': 'TjFVQm52ZDFGWEtNT0tKaktaSWU6MTpjaQ',\n 'redirect_uri': 'https://waitlist.lens.xyz/tw/',\n 'scope': 'users.read tweet.read offline.access',\n 'state': 'state', # \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u043c, \u0442\u0430\u043a \u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c.\n 'code_challenge': 'challenge',\n 'code_challenge_method': 'plain'\n}\n\nauth_code = await twitter_client.oauth2(**oauth2_data)\n# \u041f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 \u043a\u043e\u0434 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (\u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438) \u0441\u0435\u0440\u0432\u0438\u0441\u0443.\n# \u0421\u0435\u0440\u0432\u0438\u0441 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c state, \u0435\u0441\u043b\u0438 \u043e\u043d \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439.\n```\n\n#### \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f:\n```python\nbro = await twitter_client.request_user(\"bro_username\")\nawait twitter_client.send_message(bro.id, \"I love you!\")\n```\n\n#### \u0417\u0430\u043f\u0440\u043e\u0441 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439:\n```python\nmessages = await twitter_client.request_messages()\nfor message in messages:\n message_data = message[\"message_data\"]\n recipient_id = message_data[\"recipient_id\"]\n sender_id = message_data[\"sender_id\"]\n text = message_data[\"text\"]\n print(f\"[id {sender_id}] -> [id {recipient_id}]: {text}\")\n```\n\n\u0422\u0430\u043a \u043a\u0430\u043a \u043c\u043d\u0435 \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438, \u044f \u0435\u0449\u0435 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u043b \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.\n\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u043c.\n\n#### \u041f\u043e\u0441\u0442 (\u0442\u0432\u0438\u0442)\n```python\ntweet = await twitter_client.tweet(\"I love you tweepy-self! <3\")\nprint(f\"\u041b\u044e\u0431\u043e\u0432\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0430! Tweet id: {tweet.id}\")\n```\n\n#### \u041b\u0430\u0439\u043a, \u0440\u0435\u043f\u043e\u0441\u0442 (\u0440\u0435\u0442\u0432\u0438\u0442), \u043a\u043e\u043c\u043c\u0435\u043d\u0442 (\u0440\u0435\u043f\u043b\u0430\u0439)\n```python\n# \u041b\u0430\u0439\u043a\nprint(f\"Tweet {tweet_id} is liked: {await twitter_client.like(tweet_id)}\")\n\n# \u0420\u0435\u043f\u043e\u0441\u0442 (\u0440\u0435\u0442\u0432\u0438\u0442)\nprint(f\"Tweet {tweet_id} is retweeted. Tweet id: {await twitter_client.repost(tweet_id)}\")\n\n# \u041a\u043e\u043c\u043c\u0435\u043d\u0442 (\u0440\u0435\u043f\u043b\u0430\u0439)\nprint(f\"Tweet {tweet_id} is replied. Reply id: {await twitter_client.reply(tweet_id, 'tem raz\u00e3o')}\")\n```\n\n#### \u0426\u0438\u0442\u0430\u0442\u0430\n```python\ntweet_url = 'https://twitter.com/CreamIce_Cone/status/1691735090529976489'\n# \u0426\u0438\u0442\u0430\u0442\u0430 (Quote tweet)\nquote_tweet_id = await twitter_client.quote(tweet_url, 'oh....')\nprint(f\"Quoted! Tweet id: {quote_tweet_id}\")\n```\n\n#### \u041f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u0438 \u043e\u0442\u043f\u0438\u0441\u043a\u0430\n```python\n# \u041f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0418\u043b\u043e\u043d\u0430 \u041c\u0430\u0441\u043a\u0430\nprint(f\"@{elonmusk.username} is followed: {await twitter_client.follow(elonmusk.id)}\")\n\n# \u041e\u0442\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043e\u0442 \u0418\u043b\u043e\u043d\u0430 \u041c\u0430\u0441\u043a\u0430\nprint(f\"@{elonmusk.username} is unfollowed: {await twitter_client.unfollow(elonmusk.id)}\")\n```\n\n#### \u0417\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u0435 \u0442\u0432\u0438\u0442\u0430\n```python\npinned = await twitter_client.pin_tweet(tweet_id)\nprint(f\"Tweet is pined: {pinned}\")\n```\n\n#### \u0417\u0430\u043f\u0440\u043e\u0441 \u0441\u0432\u043e\u0438\u0445 \u0438 \u0447\u0443\u0436\u0438\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432\n```python\n\nfollowers = await twitter_client.request_followers()\nprint(\"\u0422\u0432\u043e\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0438:\")\nfor user in followers:\n print(user)\n \nfollowings = await twitter_client.request_followings()\nprint(f\"\u0422\u044b \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d \u043d\u0430:\")\nfor user in followings:\n print(user)\n\nbro_followers = await twitter_client.request_followers(bro_id)\nprint(f\"\u041f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0438 \u0442\u0432\u043e\u0435\u0433\u043e \u0431\u0440\u043e (id={bro_id}):\")\nfor user in bro_followers:\n print(user)\n\nbro_followings = await twitter_client.request_followings(bro_id)\nprint(f\"\u041d\u0430 \u0442\u0432\u043e\u0435\u0433\u043e \u0431\u0440\u043e (id={bro_id}) \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u044b:\")\nfor user in bro_followings:\n print(user)\n```\n\n#### \u0413\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435\n```python\nvote_data = await twitter_client.vote(tweet_id, card_id, choice_number)\nvotes_count = vote_data[\"card\"][\"binding_values\"][\"choice1_count\"][\"string_value\"]\nprint(f\"Votes: {votes_count}\")\n```\n\n\u0422\u0430\u043a \u043a\u0430\u043a \u043c\u043d\u0435 \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u044f\u043c\u0438, \u044f \u0435\u0449\u0435 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u043b \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.\n\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u043c.\n",
"bugtrack_url": null,
"license": null,
"summary": "Twitter (selfbot) for Python!",
"version": "1.11.1",
"project_urls": {
"Homepage": "https://github.com/alenkimov/tweepy-self",
"Repository": "https://github.com/alenkimov/tweepy-self",
"Source": "https://github.com/alenkimov/tweepy-self"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "539c8ec89a36098178f889abb6f1a0a730f76f7703041725603147cb413e8c5d",
"md5": "2d5855c111991c5300bc82799e6474f4",
"sha256": "af4d65f608bf0cad3aa797a71f1c5b4e3d39d0b46ef2a0f04a00ebf47e4ee0fc"
},
"downloads": -1,
"filename": "tweepy_self-1.11.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2d5855c111991c5300bc82799e6474f4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 37398,
"upload_time": "2024-06-26T01:52:35",
"upload_time_iso_8601": "2024-06-26T01:52:35.316562Z",
"url": "https://files.pythonhosted.org/packages/53/9c/8ec89a36098178f889abb6f1a0a730f76f7703041725603147cb413e8c5d/tweepy_self-1.11.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "74ac551c53776b6de299afd91372d57e3b4092ee26e050487918717942e1e083",
"md5": "7e004b6569a961b3e446ba18c0ba56e4",
"sha256": "bf022799b938c61df4f4d9fd63c9876b85b6f3034c945aa528f4ed3bb1a30084"
},
"downloads": -1,
"filename": "tweepy_self-1.11.1.tar.gz",
"has_sig": false,
"md5_digest": "7e004b6569a961b3e446ba18c0ba56e4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 36535,
"upload_time": "2024-06-26T01:52:37",
"upload_time_iso_8601": "2024-06-26T01:52:37.073079Z",
"url": "https://files.pythonhosted.org/packages/74/ac/551c53776b6de299afd91372d57e3b4092ee26e050487918717942e1e083/tweepy_self-1.11.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-26 01:52:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "alenkimov",
"github_project": "tweepy-self",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "tweepy-self"
}