twitter-openapi-python 0.1.6__tar.gz → 0.1.7__tar.gz

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.
Files changed (31) hide show
  1. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/PKG-INFO +7 -17
  2. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/README.md +5 -15
  3. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/pyproject.toml +2 -2
  4. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/pyproject.toml.orig +2 -2
  5. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/__init__.py +1 -0
  6. twitter_openapi_python-0.1.7/twitter_openapi_python/api/v20_post_api.py +53 -0
  7. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/client.py +5 -1
  8. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/LICENSE +0 -0
  9. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/LICENSE.AGPL +0 -0
  10. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/__init__.py +0 -0
  11. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/birdwatch_api.py +0 -0
  12. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/community_api.py +0 -0
  13. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/default_api.py +0 -0
  14. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/initial_state_api.py +0 -0
  15. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/post_api.py +0 -0
  16. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/tweet_api.py +0 -0
  17. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/user_api.py +0 -0
  18. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/user_list_api.py +0 -0
  19. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/users_api.py +0 -0
  20. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/v11_get_api.py +0 -0
  21. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/api/v11_post_api.py +0 -0
  22. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/models/__init__.py +0 -0
  23. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/models/base.py +0 -0
  24. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/models/header.py +0 -0
  25. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/models/initial_state.py +0 -0
  26. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/models/response.py +0 -0
  27. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/models/timeline.py +0 -0
  28. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/py.typed +0 -0
  29. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/tid.py +0 -0
  30. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/utils/__init__.py +0 -0
  31. {twitter_openapi_python-0.1.6 → twitter_openapi_python-0.1.7}/twitter_openapi_python/utils/api.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twitter_openapi_python
3
- Version: 0.1.6
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.5
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"',
@@ -16,25 +16,15 @@ pip install twitter-openapi-python
16
16
  import json
17
17
  import datetime
18
18
 
19
- from pathlib import Path
20
- from tweepy_authlib import CookieSessionUserHandler
21
19
  from twitter_openapi_python import TwitterOpenapiPython
22
20
 
23
- # login by tweepy_authlib
24
- if Path("cookie.json").exists():
25
- with open("cookie.json", "r") as f:
26
- cookies_dict = json.load(f)
27
- if isinstance(cookies_dict, list):
28
- cookies_dict = {k["name"]: k["value"] for k in cookies_dict}
29
- else:
30
- auth_handler = CookieSessionUserHandler(
31
- screen_name=input("screen_name: "),
32
- password=input("password: "),
33
- )
34
- cookies_dict = auth_handler.get_cookies().get_dict()
21
+ # cookies exported from the browser
22
+ with open("cookie.json", "r") as f:
23
+ cookies_dict = json.load(f)
24
+ if isinstance(cookies_dict, list):
25
+ cookies_dict = {k["name"]: k["value"] for k in cookies_dict}
35
26
 
36
27
  # To extract cookies from Windows (Linux by default)
37
- # If you use tweepy_authlib, you must be on Windows
38
28
  client = TwitterOpenapiPython()
39
29
  client.additional_api_headers = {
40
30
  "sec-ch-ua-platform": '"Windows"',
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "twitter_openapi_python"
3
- version = "0.1.6"
3
+ version = "0.1.7"
4
4
  description = "Twitter OpenAPI"
5
5
  readme = "README.md"
6
6
  license = "LicenseRef-Custom OR AGPL-3.0-or-later"
@@ -16,7 +16,7 @@ keywords = [
16
16
  ]
17
17
  requires-python = ">=3.10"
18
18
  dependencies = [
19
- "twitter_openapi_python_generated==0.1.5",
19
+ "twitter_openapi_python_generated==0.1.6",
20
20
  "pydantic>=2.6",
21
21
  "requests>=2.31.0,<3.0.0",
22
22
  "urllib3>=2.1.0,<3.0.0",
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "twitter_openapi_python"
3
- version = "0.1.6"
3
+ version = "0.1.7"
4
4
  description = "Twitter OpenAPI"
5
5
  authors = [{ name = "fa0311", email = "yuki@yuki0311.com" }]
6
6
  readme = "README.md"
@@ -9,7 +9,7 @@ license-files = ["LICENSE", "LICENSE.AGPL"]
9
9
  keywords = ["twitter", "api", "python", "scraper"]
10
10
  requires-python = ">=3.10"
11
11
  dependencies = [
12
- "twitter_openapi_python_generated==0.1.5",
12
+ "twitter_openapi_python_generated==0.1.6",
13
13
  "pydantic>=2.6",
14
14
  "requests>=2.31.0,<3.0.0",
15
15
  "urllib3>=2.1.0,<3.0.0",
@@ -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 = "975196678177a65210cff715a1b93ddfc83584eb"
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 = (