twitter-openapi-python 0.1.5__py3-none-any.whl → 0.1.7__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.
@@ -13,3 +13,4 @@ from twitter_openapi_python.api.user_list_api import UserListApiUtils
13
13
  from twitter_openapi_python.api.users_api import UsersApiUtils
14
14
  from twitter_openapi_python.api.v11_get_api import V11GetApiUtils
15
15
  from twitter_openapi_python.api.v11_post_api import V11PostApiUtils
16
+ from twitter_openapi_python.api.v20_post_api import V20PostApiUtils
@@ -0,0 +1,53 @@
1
+ from typing import Any, Callable, Optional, TypeVar
2
+
3
+ import twitter_openapi_python_generated as twitter
4
+
5
+ from twitter_openapi_python.models import TwitterApiUtilsResponse
6
+ from twitter_openapi_python.utils import build_response, get_legacy_kwargs
7
+
8
+ T = TypeVar("T")
9
+ ApiFnType = Callable[..., twitter.ApiResponse[T]]
10
+ ParamType = dict[str, Any]
11
+
12
+
13
+ class V20PostApiUtils:
14
+ api: twitter.V20PostApi
15
+ flag: ParamType
16
+
17
+ def __init__(self, api: twitter.V20PostApi, flag: ParamType):
18
+ self.api = api
19
+ self.flag = flag
20
+
21
+ def request(
22
+ self,
23
+ apiFn: "ApiFnType[T]",
24
+ key: str,
25
+ param: ParamType,
26
+ ) -> TwitterApiUtilsResponse[T]:
27
+ args = get_legacy_kwargs(flag=self.flag[key], additional=param)
28
+ res = apiFn(**args)
29
+ return build_response(response=res, data=res.data)
30
+
31
+ def post_timeline_feedback(
32
+ self,
33
+ feedback_type: str,
34
+ action_metadata: str,
35
+ undo: bool = False,
36
+ extra_param: Optional[ParamType] = None,
37
+ ) -> TwitterApiUtilsResponse[None]:
38
+ """feedback_type and action_metadata are the query of a feedbackUrl in the timeline."""
39
+ param = {
40
+ "feedback_type": feedback_type,
41
+ "action_metadata": action_metadata,
42
+ "feedback_type2": feedback_type, # the form repeats the query's feedback_type
43
+ "undo": "true" if undo else "false",
44
+ }
45
+ if extra_param is not None:
46
+ param.update(extra_param)
47
+
48
+ response = self.request(
49
+ apiFn=self.api.post_timeline_feedback_with_http_info,
50
+ param=param,
51
+ key="timeline/feedback.json",
52
+ )
53
+ return response
@@ -19,6 +19,7 @@ from twitter_openapi_python.api import (
19
19
  UsersApiUtils,
20
20
  V11GetApiUtils,
21
21
  V11PostApiUtils,
22
+ V20PostApiUtils,
22
23
  )
23
24
  from twitter_openapi_python.tid import get_tid
24
25
 
@@ -67,9 +68,12 @@ class TwitterOpenapiPythonClient:
67
68
  def get_v11_post_api(self) -> V11PostApiUtils:
68
69
  return V11PostApiUtils(twitter.V11PostApi(self.api), self.placeholder)
69
70
 
71
+ def get_v20_post_api(self) -> V20PostApiUtils:
72
+ return V20PostApiUtils(twitter.V20PostApi(self.api), self.placeholder)
73
+
70
74
 
71
75
  class TwitterOpenapiPython:
72
- hash: str = "8535fd9baca301ede55b10da03495a7d413f5102"
76
+ hash: str = "10a5fe81b6c8622361652574eecc3027733405f8"
73
77
  placeholder_url = "https://raw.githubusercontent.com/fa0311/twitter-openapi/{hash}/src/config/placeholder.json"
74
78
  header = "https://raw.githubusercontent.com/fa0311/latest-user-agent/refs/heads/main/header.json"
75
79
  access_token: str = (
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twitter_openapi_python
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Twitter OpenAPI
5
5
  Keywords: twitter,api,python,scraper
6
6
  Author: fa0311
@@ -8,7 +8,7 @@ Author-email: fa0311 <yuki@yuki0311.com>
8
8
  License-Expression: LicenseRef-Custom OR AGPL-3.0-or-later
9
9
  License-File: LICENSE
10
10
  License-File: LICENSE.AGPL
11
- Requires-Dist: twitter-openapi-python-generated==0.1.4
11
+ Requires-Dist: twitter-openapi-python-generated==0.1.6
12
12
  Requires-Dist: pydantic>=2.6
13
13
  Requires-Dist: requests>=2.31.0,<3.0.0
14
14
  Requires-Dist: urllib3>=2.1.0,<3.0.0
@@ -35,25 +35,15 @@ pip install twitter-openapi-python
35
35
  import json
36
36
  import datetime
37
37
 
38
- from pathlib import Path
39
- from tweepy_authlib import CookieSessionUserHandler
40
38
  from twitter_openapi_python import TwitterOpenapiPython
41
39
 
42
- # login by tweepy_authlib
43
- if Path("cookie.json").exists():
44
- with open("cookie.json", "r") as f:
45
- cookies_dict = json.load(f)
46
- if isinstance(cookies_dict, list):
47
- cookies_dict = {k["name"]: k["value"] for k in cookies_dict}
48
- else:
49
- auth_handler = CookieSessionUserHandler(
50
- screen_name=input("screen_name: "),
51
- password=input("password: "),
52
- )
53
- cookies_dict = auth_handler.get_cookies().get_dict()
40
+ # cookies exported from the browser
41
+ with open("cookie.json", "r") as f:
42
+ cookies_dict = json.load(f)
43
+ if isinstance(cookies_dict, list):
44
+ cookies_dict = {k["name"]: k["value"] for k in cookies_dict}
54
45
 
55
46
  # To extract cookies from Windows (Linux by default)
56
- # If you use tweepy_authlib, you must be on Windows
57
47
  client = TwitterOpenapiPython()
58
48
  client.additional_api_headers = {
59
49
  "sec-ch-ua-platform": '"Windows"',
@@ -1,5 +1,5 @@
1
1
  twitter_openapi_python/__init__.py,sha256=IyCanHNVJtKPGaYEMBqF37VXfMtZNUJlPhSOZMvO5jg,324
2
- twitter_openapi_python/api/__init__.py,sha256=1YPsr8wnqlrBFAViXCwYwDdk2kNwA6PMC8DAnsWC62U,772
2
+ twitter_openapi_python/api/__init__.py,sha256=LUIzvFQ6D-iMADPuMwn-K6kev7MDcXlFCpStzpYRke8,840
3
3
  twitter_openapi_python/api/birdwatch_api.py,sha256=5Nk1wqpsUmAFQXytpNP5tVAnEUy06r0Yb7oJMA1jbDc,4131
4
4
  twitter_openapi_python/api/community_api.py,sha256=AA59UgBz_l2i9ny9rNyPxFUVj5zR40WKQavHr5SLxs0,5389
5
5
  twitter_openapi_python/api/default_api.py,sha256=rE6hrAe_wxBkiYe6ZhdseSHMwFuBzSeItDTRqop4J7M,7775
@@ -11,7 +11,8 @@ twitter_openapi_python/api/user_list_api.py,sha256=8WxhVU69I_mmVlgdvkeIKFw1vcE2r
11
11
  twitter_openapi_python/api/users_api.py,sha256=VGdJV-vDZ1_4E1lddzHkrRGIdLhuYdOSXLTjjmLudQI,3253
12
12
  twitter_openapi_python/api/v11_get_api.py,sha256=UXe34f6IBYExqWCJ8HCld_8d_ChQb92je0G5VtLxmyM,1978
13
13
  twitter_openapi_python/api/v11_post_api.py,sha256=eErGBOo-y4E1AAMIHgeWnc0rAFmc5KgIoipJI-8V0Y8,1781
14
- twitter_openapi_python/client.py,sha256=K8qz5O7jwmgxHUjhSm8HOq7kbXsxCj39NKMVWqghpXk,7670
14
+ twitter_openapi_python/api/v20_post_api.py,sha256=8CQPFaVwe--guZZ28M1dPIeOY7m7x5UofWhsWpVWGHY,1685
15
+ twitter_openapi_python/client.py,sha256=o9nL_3z6mA2hsjwIOYSSKuiPTnBUw1rQcEO_NVaDN9c,7822
15
16
  twitter_openapi_python/models/__init__.py,sha256=pHISZJrEPBlXS25kMydl1SxXuCct-CUpnPDfL7kEEBo,588
16
17
  twitter_openapi_python/models/base.py,sha256=3sw6wdQn9i8FoujFxhEFVWIB26-qjI6JTDuXKuebM0Y,189
17
18
  twitter_openapi_python/models/header.py,sha256=EKujtBRZOJmeh2SD1QOCsLWaE9gdGY4wsNUgwCnbTCU,644
@@ -22,8 +23,8 @@ twitter_openapi_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
22
23
  twitter_openapi_python/tid.py,sha256=xjqJMyPOp62nw2MQjMGHaB4L6G6OZHuWkMR-WKJo7aU,1120
23
24
  twitter_openapi_python/utils/__init__.py,sha256=lIEPoDqtgCvUk0A8cWqdTlTWMhkEp_NbVxL7sJ0uiu8,612
24
25
  twitter_openapi_python/utils/api.py,sha256=1GCVabc9Reff_-OKWs4c4rAek4uIRCpBRIUMHE7Ht_c,12755
25
- twitter_openapi_python-0.1.5.dist-info/licenses/LICENSE,sha256=sLv8EMhrPCMG_LeweYvYKS_B-cDMBwBSKZel7LSMGAs,1493
26
- twitter_openapi_python-0.1.5.dist-info/licenses/LICENSE.AGPL,sha256=TfPDBt3ar0uv_f9cqCDMZ5rIzW3CY8anRRd4PkL6ejs,34522
27
- twitter_openapi_python-0.1.5.dist-info/WHEEL,sha256=3NO1oYsF7mANFUWVdyEQLM-zmecczWWEmmF5rEbXrWk,80
28
- twitter_openapi_python-0.1.5.dist-info/METADATA,sha256=u6kZuwIsBBmrD24AFJtA9i3XvUbnSWvmNAzgDR1IoXM,4071
29
- twitter_openapi_python-0.1.5.dist-info/RECORD,,
26
+ twitter_openapi_python-0.1.7.dist-info/licenses/LICENSE,sha256=sLv8EMhrPCMG_LeweYvYKS_B-cDMBwBSKZel7LSMGAs,1493
27
+ twitter_openapi_python-0.1.7.dist-info/licenses/LICENSE.AGPL,sha256=TfPDBt3ar0uv_f9cqCDMZ5rIzW3CY8anRRd4PkL6ejs,34522
28
+ twitter_openapi_python-0.1.7.dist-info/WHEEL,sha256=MWx7psoF7KNST9G72pGtiBYuaXRXQXBk9pw5R6FzYko,80
29
+ twitter_openapi_python-0.1.7.dist-info/METADATA,sha256=6zWc4Xpy1eEcpfibYN81d8Iro9X5oVvuF-a9gOB7ytw,3707
30
+ twitter_openapi_python-0.1.7.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.13.6
2
+ Generator: uv 0.13.7
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any