twifork 2.3.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.4
2
+ Name: twifork
3
+ Version: 2.3.3
4
+ Summary: A maintained fork of twikit — Twitter/X API scraper for Python, no API key required.
5
+ Home-page: https://github.com/PawiX25/twifork
6
+ Author: PawiX25
7
+ License: MIT
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: httpx[socks]
12
+ Requires-Dist: filetype
13
+ Requires-Dist: beautifulsoup4
14
+ Requires-Dist: pyotp
15
+ Requires-Dist: lxml
16
+ Requires-Dist: webvtt-py
17
+ Requires-Dist: m3u8
18
+ Requires-Dist: Js2Py-3.13
19
+ Provides-Extra: impersonate
20
+ Requires-Dist: curl_cffi<0.8,>=0.7; extra == "impersonate"
21
+ Dynamic: author
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: home-page
25
+ Dynamic: license
26
+ Dynamic: license-file
27
+ Dynamic: provides-extra
28
+ Dynamic: requires-dist
29
+ Dynamic: requires-python
30
+ Dynamic: summary
31
+
32
+ <p align="center">
33
+ <img src="https://raw.githubusercontent.com/PawiX25/twifork/main/assets/banner.png" width="640" alt="twifork">
34
+ </p>
35
+
36
+ <p align="center">
37
+ A <b>Twitter / X</b> API scraper for Python — <b>no API key required</b>.<br>
38
+ A maintained fork of <a href="https://github.com/d60/twikit">d60/twikit</a>, fixed for the 2026 breakages that make the upstream release unusable.
39
+ </p>
40
+
41
+ <p align="center">
42
+ <img src="https://img.shields.io/badge/python-3.8%2B-blue" alt="Python 3.8+">
43
+ <img src="https://img.shields.io/badge/license-MIT-green" alt="MIT License">
44
+ <img src="https://img.shields.io/github/stars/PawiX25/twifork?style=flat&color=yellow" alt="Stars">
45
+ </p>
46
+
47
+ > **Drop-in replacement** — the package still imports as `twikit`, so existing code (`from twikit import Client`) keeps working unchanged.
48
+
49
+ ---
50
+
51
+ ## Install
52
+
53
+ ```bash
54
+ pip install git+https://github.com/PawiX25/twifork.git
55
+ ```
56
+
57
+ Optional browser-TLS impersonation (gets past some `403` walls):
58
+
59
+ ```bash
60
+ pip install "twikit[impersonate] @ git+https://github.com/PawiX25/twifork.git"
61
+ ```
62
+
63
+ ## Why this fork?
64
+
65
+ The upstream PyPI release (`twikit==2.3.3`) is broken in several ways as of 2026. **twifork** fixes them — each item links to the upstream issue it resolves:
66
+
67
+ - **ClientTransaction / `Couldn't get KEY_BYTE indices`** — updated `ondemand.s.js` parsing for the new X webpack bundle, so GraphQL requests work again. ([#408](https://github.com/d60/twikit/issues/408), [#409](https://github.com/d60/twikit/issues/409), [#304](https://github.com/d60/twikit/issues/304))
68
+ - **Intermittent / sticky `404` on `SearchTimeline` and `friends/list`** — the `x-client-transaction-id` animation key was missing X's `frame_time` rounding step, so on some `Client` sessions every strict request 404'd until the client was recreated. Restored, so the semi-random 404s are gone. ([#357](https://github.com/d60/twikit/issues/357), [#397](https://github.com/d60/twikit/issues/397))
69
+ - **`KeyError` on missing optional fields** in `User.__init__` and `Client.request` — defensive `.get()` parsing. ([#417](https://github.com/d60/twikit/issues/417))
70
+ - **Empty user `name` / `screen_name`** (e.g. in search results) — X moved `name`, `screen_name`, `created_at`, avatar, location, and more out of `legacy` into new sub-objects; these are now read with a legacy fallback.
71
+ - **`get_tweet_by_id` `KeyError: 'itemContent'`** — handles both the legacy and the new trailing-cursor shapes. ([#332](https://github.com/d60/twikit/issues/332), [#363](https://github.com/d60/twikit/issues/363))
72
+ - **`KeyError: 'entries'` / `IndexError` on `get_user_tweets`** for accounts with no visible tweets — empty / cursor-less timelines return an empty result instead of crashing. ([#361](https://github.com/d60/twikit/issues/361), [#216](https://github.com/d60/twikit/issues/216))
73
+ - **`get_trends` deprecated / returns nothing** — rebuilt on top of `GenericTimelineById`; also adds `get_explore_page()`. ([#389](https://github.com/d60/twikit/issues/389))
74
+ - **`RecursionError` on rate-limit** — the 429 recovery path no longer recurses.
75
+ - **`GuestClient.activate()` 404** — the guest client now sends a `User-Agent` header and parses user fields defensively. ([#402](https://github.com/d60/twikit/issues/402), [#385](https://github.com/d60/twikit/issues/385))
76
+ - **`get_latest_friends` 404** — routed through the GraphQL `Following` endpoint after the v1.1 endpoint was retired. ([#397](https://github.com/d60/twikit/issues/397))
77
+ - **`'Client' object has no attribute '_ui_metrix'`** — fixed the captcha unlock path. ([#333](https://github.com/d60/twikit/issues/333))
78
+ - **`get_bookmark_folders().next()` infinite loop** — fixed malformed pagination variables. ([#334](https://github.com/d60/twikit/issues/334), [#335](https://github.com/d60/twikit/issues/335))
79
+ - **`get_latest_timeline` / `get_list_tweets` dropping conversation entries** — home- and list-conversation entries are now unpacked. ([#336](https://github.com/d60/twikit/issues/336), [#337](https://github.com/d60/twikit/issues/337), [#340](https://github.com/d60/twikit/issues/340))
80
+ - **`Media.source_url`** for the full-resolution image ([#376](https://github.com/d60/twikit/issues/376)), and **`Tweet.quoted_status_id`** for the quoted tweet id ([#222](https://github.com/d60/twikit/issues/222)).
81
+
82
+ Issues that stem from X-side restrictions (account suspension, Cloudflare/IP blocks, captcha, automation limits) aren't fixable in the library and are out of scope.
83
+
84
+ ### Browser TLS impersonation (optional)
85
+
86
+ Some X endpoints reject the default `httpx` TLS fingerprint with a `403` (HTML) response even when the request is valid. Installing the optional `curl_cffi` backend and passing `impersonate=` routes requests through a real browser TLS fingerprint, which avoids those 403s:
87
+
88
+ ```python
89
+ client = Client('en-US', impersonate='chrome124')
90
+ ```
91
+
92
+ ## Quick start
93
+
94
+ **Define a client and log in.**
95
+
96
+ ```python
97
+ import asyncio
98
+ from twikit import Client
99
+
100
+ client = Client('en-US')
101
+
102
+ async def main():
103
+ await client.login(
104
+ auth_info_1='example_user',
105
+ auth_info_2='email@example.com',
106
+ password='password0000',
107
+ cookies_file='cookies.json'
108
+ )
109
+
110
+ asyncio.run(main())
111
+ ```
112
+
113
+ **Post a tweet with media attached.**
114
+
115
+ ```python
116
+ media_ids = [
117
+ await client.upload_media('media1.jpg'),
118
+ await client.upload_media('media2.jpg'),
119
+ ]
120
+ await client.create_tweet(text='Example Tweet', media_ids=media_ids)
121
+ ```
122
+
123
+ **Search the latest tweets for a keyword.**
124
+
125
+ ```python
126
+ tweets = await client.search_tweet('python', 'Latest')
127
+ for tweet in tweets:
128
+ print(tweet.user.name, tweet.text, tweet.created_at)
129
+ ```
130
+
131
+ **A few more common calls.**
132
+
133
+ ```python
134
+ await client.get_user_tweets('123456', 'Tweets') # a user's tweets
135
+ await client.send_dm('123456789', 'Hello') # send a DM
136
+ await client.get_trends('trending') # trending topics
137
+ ```
138
+
139
+ More examples (upstream, still apply): https://github.com/d60/twikit/tree/main/examples
140
+
141
+ ## Features
142
+
143
+ - **No API key** — works by scraping the web client.
144
+ - **Free & open source** (MIT).
145
+ - **Drop-in `twikit` replacement** — same import, your code doesn't change.
146
+ - Tweets, search, timelines, trends, users, DMs, media, bookmarks, and more.
147
+
148
+ ## Documentation
149
+
150
+ Full API reference (upstream — the package surface is the same): https://twikit.readthedocs.io/en/latest/twikit.html
151
+
152
+ ## Community
153
+
154
+ [![Discord](https://img.shields.io/badge/Discord-%235865F2.svg?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/nCrByrr8cX)
155
+
156
+ ## Contributing
157
+
158
+ Found a bug or have a fix? Open an issue or PR on **[twifork issues](https://github.com/PawiX25/twifork/issues)**.
159
+
160
+ If twifork saved you a headache, consider leaving a ⭐.
161
+
162
+ ## Credits
163
+
164
+ twifork is a fork of **[d60/twikit](https://github.com/d60/twikit)** by [@d60](https://github.com/d60) — all upstream credit goes to the original authors. Licensed under the **MIT License**.
165
+
166
+ ## Disclaimer
167
+
168
+ twifork is an independent, unofficial project. It is **not affiliated with, endorsed by, or sponsored by X Corp.** "X" and "Twitter" are trademarks of X Corp. Use it in accordance with applicable terms and laws.
@@ -0,0 +1,36 @@
1
+ twifork-2.3.3.dist-info/licenses/LICENSE,sha256=pWuwPHbS3iaDH9EjOP8Sa-CK_NBHrXqRKnSfCHcdm0U,1079
2
+ twikit/__init__.py,sha256=fI69blfEYcqV5wtr20JFfmjhTKYAVYwvnMc0EDRPDVQ,855
3
+ twikit/bookmark.py,sha256=rTFsAPc-L8f_nfV2chAPmW4MEScdq59BW8FbaHLZJQ4,1765
4
+ twikit/community.py,sha256=p3yAaFaBdPsJQvcMRGuhclFvPcv9SjzKXjQFKIyLdv4,8756
5
+ twikit/constants.py,sha256=y7IKM73rV2p-HqClXjxMAa0b6hG4lE180oWEoUXLgRM,19875
6
+ twikit/errors.py,sha256=_AFs57-MZwjrtAy20Dm19EbJm3ZnRGHTxil842iKl9M,2925
7
+ twikit/geo.py,sha256=ddXJ626WkKsb1BiBpEldXjKB0gpdlKQPbw3CllxnRuQ,2758
8
+ twikit/group.py,sha256=RVx45grXgeVMkozVc5NrQ9pBK8cXO_spqTpcO5Wt0qQ,7393
9
+ twikit/list.py,sha256=cFqnfQNKWLHWJ8HG0dVnVdma8YATIB3NnuUBtO2B6yM,7786
10
+ twikit/media.py,sha256=ozgR_rPFGCS5jOHkHA-ACUkc8y-QPvp4l6h8urqDMcA,10023
11
+ twikit/message.py,sha256=UtzI6WxP-v0Kv8r-cFvfHR5b6RUI90Jn4leTufa69Hs,3981
12
+ twikit/notification.py,sha256=DQl5_AfOGzDy8z3ujlLfoPP1QjI_hNe2UVHPUy-kxuw,1448
13
+ twikit/streaming.py,sha256=g2E34KL8D6dCGSgRwzZKM-R9MYcX7PsITncv7zH7G3I,8321
14
+ twikit/trend.py,sha256=nbdw4qoO-qYXCw74hK-i6Oju1_-AdFfG6Z0QbnNgTcY,2885
15
+ twikit/tweet.py,sha256=aytHvx70Cq5DcnhMODvYAfR5BJ8aJbmQXX6sc-gjU7Q,25721
16
+ twikit/user.py,sha256=dUcYUs6572jOv4oIYLIyFYYJa6JVdqfDobySlJGF5wg,17607
17
+ twikit/utils.py,sha256=DROKx47mozEtYd3XDmESstZ2n7DZQhfxzF0HeM9-dW0,12978
18
+ twikit/_captcha/__init__.py,sha256=Cdktk_osIVL2qLOpglk3YMQ3sO3wt22axBrz6LPwlTs,67
19
+ twikit/_captcha/base.py,sha256=MhB3qR2ON8fg8JlydnVebYEyEuPS9nJgdk-Q60aj1R0,3646
20
+ twikit/_captcha/capsolver.py,sha256=RHsllf_SywmMRPMczk5Hj4evNpYrmpHl30qa47DGTBw,3017
21
+ twikit/guest/__init__.py,sha256=4BHyJ9wo6rUzNY2CHyhE0zn6CgnJms4caypkwOfqmHw,83
22
+ twikit/guest/client.py,sha256=v8NZgKXfMq3w7ir97ACw5Eehy-VRU_gzg22QqDGHauA,13480
23
+ twikit/guest/tweet.py,sha256=lyWeDiB6KRnM4twAwxsXu1jGoH1uVKjlEiYw0GapWbA,9816
24
+ twikit/guest/user.py,sha256=VayI1P90TZs9PhUA_oys-NVChu8oA6NucG-OFB6cyOM,8204
25
+ twikit/ui_metrics/__init__.py,sha256=whZLkYoaklQvHzzE5yfMvuID1JM8yv8sqzcNDCvQQQc,779
26
+ twikit/ui_metrics/dom.py,sha256=UA_79GQ0YiHrazSs_CIMcKal-htP6rSss2nG2JN-e14,1522
27
+ twikit/x_client_transaction/__init__.py,sha256=7_IdWeil7QbfXlIt7U1Wb4chVVhaR4LuCWxDXr8gchY,230
28
+ twikit/x_client_transaction/cubic_curve.py,sha256=pOe3UHlK5wVbSZY_j5V3e6BUUQuZhxawt-m35x0LjGU,1658
29
+ twikit/x_client_transaction/interpolate.py,sha256=WiYTkgUxJN0QakyT8WRWMjr4gOkQAlOftTEdoDzVu7Q,832
30
+ twikit/x_client_transaction/rotation.py,sha256=1BaUWU00VQ2D3ZQ-qBjmqNNHjArTIZJK-ljxeO0295A,653
31
+ twikit/x_client_transaction/transaction.py,sha256=-hZo0unwejzX_rq6aoCT_stUJoGBA2Y_WcC3il_oDJ0,8364
32
+ twikit/x_client_transaction/utils.py,sha256=RpQMaJwIIcCAX9oqiIm-acwzudBg0RgbPT05-gjSVX0,2769
33
+ twifork-2.3.3.dist-info/METADATA,sha256=m_G-B-J6j6NGWBlKtjSs6BX_zbTTEOPX5JigF4JykJQ,8133
34
+ twifork-2.3.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
35
+ twifork-2.3.3.dist-info/top_level.txt,sha256=qSw4o7KuNsANba4lwGxvLh9r7Fb-7Yg8MmEE_Rtfygk,7
36
+ twifork-2.3.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 d60
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ twikit
twikit/__init__.py ADDED
@@ -0,0 +1,31 @@
1
+ """
2
+ ==========================
3
+ Twikit Twitter API Wrapper
4
+ ==========================
5
+
6
+ https://github.com/d60/twikit
7
+ A Python library for interacting with the Twitter API.
8
+ """
9
+
10
+ __version__ = '2.3.3'
11
+
12
+ import asyncio
13
+ import os
14
+
15
+ if os.name == 'nt':
16
+ asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
17
+
18
+ from ._captcha import Capsolver
19
+ from .bookmark import BookmarkFolder
20
+ from .errors import *
21
+ from .utils import build_query
22
+ from .client.client import Client
23
+ from .community import Community, CommunityCreator, CommunityMember, CommunityRule
24
+ from .geo import Place
25
+ from .group import Group, GroupMessage
26
+ from .list import List
27
+ from .message import Message
28
+ from .notification import Notification
29
+ from .trend import Trend
30
+ from .tweet import CommunityNote, Poll, ScheduledTweet, Tweet
31
+ from .user import User
@@ -0,0 +1,2 @@
1
+ from .base import CaptchaSolver
2
+ from .capsolver import Capsolver
@@ -0,0 +1,114 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from typing import TYPE_CHECKING, NamedTuple
5
+
6
+ from bs4 import BeautifulSoup
7
+ from httpx import Response
8
+ from ..constants import DOMAIN
9
+ from ..ui_metrics import solve_ui_metrics
10
+
11
+ if TYPE_CHECKING:
12
+ from ..client.client import Client
13
+
14
+
15
+ class UnlockHTML(NamedTuple):
16
+ authenticity_token: str
17
+ assignment_token: str
18
+ needs_unlock: bool
19
+ start_button: bool
20
+ finish_button: bool
21
+ delete_button: bool
22
+ blob: str
23
+
24
+
25
+ class CaptchaSolver:
26
+ client: Client
27
+ max_attempts: int
28
+
29
+ CAPTCHA_URL = f'https://{DOMAIN}/account/access'
30
+ CAPTCHA_SITE_KEY = '0152B4EB-D2DC-460A-89A1-629838B529C9'
31
+
32
+ async def get_unlock_html(self) -> tuple[Response, UnlockHTML]:
33
+ headers = {
34
+ 'X-Twitter-Client-Language': 'en-US',
35
+ 'User-Agent': self.client._user_agent,
36
+ 'Upgrade-Insecure-Requests': '1'
37
+ }
38
+ _, response = await self.client.get(
39
+ self.CAPTCHA_URL, headers=headers
40
+ )
41
+ return response, parse_unlock_html(response.text)
42
+
43
+ async def ui_metrix(self) -> str:
44
+ js, _ = await self.client.get(
45
+ f'https://{DOMAIN}/i/js_inst?c_name=ui_metrics'
46
+ )
47
+ return re.findall(r'return ({.*?});', js, re.DOTALL)[0]
48
+
49
+ async def confirm_unlock(
50
+ self,
51
+ authenticity_token: str,
52
+ assignment_token: str,
53
+ verification_string: str = None,
54
+ ui_metrics: bool = False
55
+ ) -> tuple[Response, UnlockHTML]:
56
+ data = {
57
+ 'authenticity_token': authenticity_token,
58
+ 'assignment_token': assignment_token,
59
+ 'lang': 'en',
60
+ 'flow': '',
61
+ }
62
+ params = {}
63
+ if verification_string:
64
+ data['verification_string'] = verification_string
65
+ data['language_code'] = 'en'
66
+ params['lang'] = 'en'
67
+ if ui_metrics:
68
+ data['ui_metrics'] = solve_ui_metrics(
69
+ await self.client._ui_metrics()
70
+ )
71
+ headers = {
72
+ 'Content-Type': 'application/x-www-form-urlencoded',
73
+ 'Upgrade-Insecure-Requests': '1',
74
+ 'Referer': self.CAPTCHA_URL
75
+ }
76
+ _, response = await self.client.post(
77
+ self.CAPTCHA_URL, params=params, data=data, headers=headers
78
+ )
79
+ return response, parse_unlock_html(response.text)
80
+
81
+
82
+ def parse_unlock_html(html: str) -> UnlockHTML:
83
+ soup = BeautifulSoup(html, 'lxml')
84
+
85
+ authenticity_token = None
86
+ authenticity_token_element = soup.find(
87
+ 'input', {'name': 'authenticity_token'}
88
+ )
89
+ if authenticity_token_element is not None:
90
+ authenticity_token: str = authenticity_token_element.get('value')
91
+
92
+ assignment_token = None
93
+ assignment_token_element = soup.find('input', {'name': 'assignment_token'})
94
+ if assignment_token_element is not None:
95
+ assignment_token = assignment_token_element.get('value')
96
+
97
+ verification_string = soup.find('input', id='verification_string')
98
+ needs_unlock = bool(verification_string)
99
+ start_button = bool(soup.find('input', value='Start'))
100
+ finish_button = bool(soup.find('input', value='Continue to X'))
101
+ delete_button = bool(soup.find('input', value='Delete'))
102
+
103
+ iframe = soup.find(id='arkose_iframe')
104
+ blob = re.findall(r'data=(.+)', iframe['src'])[0] if iframe else None
105
+
106
+ return UnlockHTML(
107
+ authenticity_token,
108
+ assignment_token,
109
+ needs_unlock,
110
+ start_button,
111
+ finish_button,
112
+ delete_button,
113
+ blob
114
+ )
@@ -0,0 +1,95 @@
1
+ from __future__ import annotations
2
+
3
+ from time import sleep
4
+
5
+ import httpx
6
+
7
+ from .base import CaptchaSolver
8
+
9
+
10
+ class Capsolver(CaptchaSolver):
11
+ """
12
+ You can automatically unlock the account by passing the `captcha_solver`
13
+ argument when initialising the :class:`.Client`.
14
+
15
+ First, visit https://capsolver.com and obtain your Capsolver API key.
16
+ Next, pass the Capsolver instance to the client as shown in the example.
17
+
18
+ .. code-block:: python
19
+
20
+ from twikit.twikit_async import Capsolver, Client
21
+ solver = Capsolver(
22
+ api_key='your_api_key',
23
+ max_attempts=10
24
+ )
25
+ client = Client(captcha_solver=solver)
26
+
27
+ Parameters
28
+ ----------
29
+ api_key : :class:`str`
30
+ Capsolver API key.
31
+ max_attempts : :class:`int`, default=3
32
+ The maximum number of attempts to solve the captcha.
33
+ get_result_interval : :class:`float`, default=1.0
34
+
35
+ use_blob_data : :class:`bool`, default=False
36
+ """
37
+
38
+ def __init__(
39
+ self,
40
+ api_key: str,
41
+ max_attempts: int = 3,
42
+ get_result_interval: float = 1.0,
43
+ use_blob_data: bool = False
44
+ ) -> None:
45
+ self.api_key = api_key
46
+ self.get_result_interval = get_result_interval
47
+ self.max_attempts = max_attempts
48
+ self.use_blob_data = use_blob_data
49
+
50
+ def create_task(self, task_data: dict) -> dict:
51
+ data = {
52
+ 'clientKey': self.api_key,
53
+ 'task': task_data
54
+ }
55
+ response = httpx.post(
56
+ 'https://api.capsolver.com/createTask',
57
+ json=data,
58
+ headers={'content-type': 'application/json'}
59
+ ).json()
60
+ return response
61
+
62
+ def get_task_result(self, task_id: str) -> dict:
63
+ data = {
64
+ 'clientKey': self.api_key,
65
+ 'taskId': task_id
66
+ }
67
+ response = httpx.post(
68
+ 'https://api.capsolver.com/getTaskResult',
69
+ json=data,
70
+ headers={'content-type': 'application/json'}
71
+ ).json()
72
+ return response
73
+
74
+ def solve_funcaptcha(self, blob: str) -> dict:
75
+ if self.client.proxy is None:
76
+ captcha_type = 'FunCaptchaTaskProxyLess'
77
+ else:
78
+ captcha_type = 'FunCaptchaTask'
79
+
80
+ task_data = {
81
+ 'type': captcha_type,
82
+ 'websiteURL': 'https://iframe.arkoselabs.com',
83
+ 'websitePublicKey': self.CAPTCHA_SITE_KEY,
84
+ 'funcaptchaApiJSSubdomain': 'https://client-api.arkoselabs.com',
85
+ 'proxy': self.client.proxy
86
+ }
87
+ if self.use_blob_data:
88
+ task_data['data'] = '{"blob":"%s"}' % blob
89
+ task_data['userAgent'] = self.client._user_agent
90
+ task = self.create_task(task_data)
91
+ while True:
92
+ sleep(self.get_result_interval)
93
+ result = self.get_task_result(task['taskId'])
94
+ if result['status'] in ('ready', 'failed'):
95
+ return result
twikit/bookmark.py ADDED
@@ -0,0 +1,64 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from httpx import Response
7
+
8
+ from .client.client import Client
9
+ from .tweet import Tweet
10
+ from .utils import Result
11
+
12
+
13
+ class BookmarkFolder:
14
+ """
15
+ Attributes
16
+ ----------
17
+ id : :class:`str`
18
+ The ID of the folder.
19
+ name : :class:`str`
20
+ The name of the folder
21
+ media : :class:`str`
22
+ Icon image data.
23
+ """
24
+ def __init__(self, client: Client, data: dict) -> None:
25
+ self._client = client
26
+
27
+ self.id: str = data['id']
28
+ self.name: str = data['name']
29
+ self.media: dict = data['media']
30
+
31
+ async def get_tweets(self, cursor: str | None = None) -> Result[Tweet]:
32
+ """
33
+ Retrieves tweets from the folder.
34
+ """
35
+ return await self._client.get_bookmarks(
36
+ cursor=cursor, folder_id=self.id
37
+ )
38
+
39
+ async def edit(self, name: str) -> BookmarkFolder:
40
+ """
41
+ Edits the folder.
42
+ """
43
+ return await self._client.edit_bookmark_folder(self.id, name)
44
+
45
+ async def delete(self) -> Response:
46
+ """
47
+ Deletes the folder.
48
+ """
49
+ return await self._client.delete_bookmark_folder(self.id)
50
+
51
+ async def add(self, tweet_id: str) -> Response:
52
+ """
53
+ Adds a tweet to the folder.
54
+ """
55
+ return await self._client.bookmark_tweet(tweet_id, self.id)
56
+
57
+ def __eq__(self, __value: object) -> bool:
58
+ return isinstance(__value, BookmarkFolder) and self.id == __value.id
59
+
60
+ def __ne__(self, __value: object) -> bool:
61
+ return not self == __value
62
+
63
+ def __repr__(self) -> str:
64
+ return f'<BookmarkFolder id="{self.id}">'