twitter-openapi-python 0.0.24__tar.gz → 0.0.26__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 (36) hide show
  1. twitter_openapi_python-0.0.26/PKG-INFO +102 -0
  2. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/README.md +14 -3
  3. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/pyproject.toml +2 -2
  4. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/setup.py +15 -5
  5. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/client.py +9 -3
  6. twitter_openapi_python-0.0.26/twitter_openapi_python.egg-info/PKG-INFO +102 -0
  7. twitter_openapi_python-0.0.26/twitter_openapi_python.egg-info/requires.txt +2 -0
  8. twitter_openapi_python-0.0.24/PKG-INFO +0 -15
  9. twitter_openapi_python-0.0.24/twitter_openapi_python.egg-info/PKG-INFO +0 -15
  10. twitter_openapi_python-0.0.24/twitter_openapi_python.egg-info/requires.txt +0 -2
  11. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/LICENSE +0 -0
  12. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/LICENSE.AGPL +0 -0
  13. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/setup.cfg +0 -0
  14. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/__init__.py +0 -0
  15. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/api/__init__.py +0 -0
  16. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/api/default_api.py +0 -0
  17. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/api/initial_state_api.py +0 -0
  18. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/api/post_api.py +0 -0
  19. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/api/tweet_api.py +0 -0
  20. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/api/user_api.py +0 -0
  21. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/api/user_list_api.py +0 -0
  22. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/api/users_api.py +0 -0
  23. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/api/v11_get_api.py +0 -0
  24. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/api/v11_post_api.py +0 -0
  25. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/models/__init__.py +0 -0
  26. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/models/base.py +0 -0
  27. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/models/header.py +0 -0
  28. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/models/initial_state.py +0 -0
  29. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/models/response.py +0 -0
  30. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/models/timeline.py +0 -0
  31. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/py.typed +0 -0
  32. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/utils/__init__.py +0 -0
  33. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python/utils/api.py +0 -0
  34. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python.egg-info/SOURCES.txt +0 -0
  35. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python.egg-info/dependency_links.txt +0 -0
  36. {twitter_openapi_python-0.0.24 → twitter_openapi_python-0.0.26}/twitter_openapi_python.egg-info/top_level.txt +0 -0
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.1
2
+ Name: twitter_openapi_python
3
+ Version: 0.0.26
4
+ Summary: Twitter OpenAPI
5
+ Home-page: https://github.com/fa0311/twitter_openapi_python
6
+ Author: fa0311
7
+ Author-email: yuki@yuki0311.com
8
+ License: proprietary or AGPL-3.0-or-later
9
+ Keywords: OpenAPI,OpenAPI-Generator,Twitter OpenAPI
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ License-File: LICENSE.AGPL
13
+
14
+ # twitter_openapi_python
15
+
16
+ Twitter scraping with data validation by pydantic.
17
+
18
+ ![1691572735537](https://raw.githubusercontent.com/fa0311/twitter_openapi_python/refs/heads/master/twitter_openapi_python/docs/image/README/1691572735537.png)
19
+
20
+ ## Setup
21
+
22
+ ```shell
23
+ pip install twitter-openapi-python
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```python
29
+ import json
30
+ import datetime
31
+
32
+ from pathlib import Path
33
+ from tweepy_authlib import CookieSessionUserHandler
34
+ from twitter_openapi_python import TwitterOpenapiPython
35
+
36
+ # login by tweepy_authlib
37
+ if Path("cookie.json").exists():
38
+ with open("cookie.json", "r") as f:
39
+ cookies_dict = json.load(f)
40
+ if isinstance(cookies_dict, list):
41
+ cookies_dict = {k["name"]: k["value"] for k in cookies_dict}
42
+ else:
43
+ auth_handler = CookieSessionUserHandler(
44
+ screen_name=input("screen_name: "),
45
+ password=input("password: "),
46
+ )
47
+ cookies_dict = auth_handler.get_cookies().get_dict()
48
+
49
+ # To extract cookies from Windows (Linux by default)
50
+ # If you use tweepy_authlib, you must be on Windows
51
+ client = TwitterOpenapiPython()
52
+ client.additional_api_headers = {
53
+ "sec-ch-ua-platform": '"Windows"',
54
+ }
55
+ client.additional_browser_headers = {
56
+ "sec-ch-ua-platform": '"Windows"',
57
+ }
58
+
59
+ # get client from cookies
60
+ 撫 = client.get_client_from_cookies(cookies=cookies_dict)
61
+
62
+ # tweet "Hello World!!" with current time
63
+ time = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ")
64
+ 撫.get_post_api().post_create_tweet(tweet_text=f"Hello World!!{time}")
65
+
66
+ # get user info
67
+ response = 撫.get_user_api().get_user_by_screen_name("elonmusk")
68
+ ```
69
+
70
+ ### Login
71
+
72
+ ```python
73
+ from twitter_openapi_python import TwitterOpenapiPython
74
+
75
+ # guest client
76
+ 撫 = TwitterOpenapiPython().get_guest_client()
77
+ tweet = 撫.get_default_api().get_tweet_result_by_rest_id("1349129669258448897")
78
+ assert tweet.data is not None
79
+ assert tweet.data.tweet.legacy is not None
80
+ print(tweet.data.tweet.legacy.full_text)
81
+ ```
82
+
83
+ ### Multiple OS
84
+
85
+ The Token can only be used on the same OS that issued the Token
86
+ In other words, if the sec-ch-ua-platform does not match, the Token cannot be used.
87
+ This library uses the Linux Chrome header by default.
88
+ To use Token issued by Windows, do the following.
89
+
90
+ ```python
91
+ client = TwitterOpenapiPython()
92
+ client.additional_api_headers = {
93
+ "sec-ch-ua-platform": '"Windows"',
94
+ };
95
+ ```
96
+
97
+ ## License
98
+
99
+ This project is dual licensed. You can choose one of the following licenses:
100
+
101
+ - [Custom License](./LICENSE)
102
+ - [GNU Affero General Public License v3.0](./LICENSE.AGPL)
@@ -33,8 +33,18 @@ else:
33
33
  )
34
34
  cookies_dict = auth_handler.get_cookies().get_dict()
35
35
 
36
+ # To extract cookies from Windows (Linux by default)
37
+ # If you use tweepy_authlib, you must be on Windows
38
+ client = TwitterOpenapiPython()
39
+ client.additional_api_headers = {
40
+ "sec-ch-ua-platform": '"Windows"',
41
+ }
42
+ client.additional_browser_headers = {
43
+ "sec-ch-ua-platform": '"Windows"',
44
+ }
45
+
36
46
  # get client from cookies
37
- 𝕏 = TwitterOpenapiPython().get_client_from_cookies(cookies=cookies_dict)
47
+ 𝕏 = client.get_client_from_cookies(cookies=cookies_dict)
38
48
 
39
49
  # tweet "Hello World!!" with current time
40
50
  time = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ")
@@ -64,8 +74,9 @@ In other words, if the sec-ch-ua-platform does not match, the Token cannot be us
64
74
  This library uses the Linux Chrome header by default.
65
75
  To use Token issued by Windows, do the following.
66
76
 
67
- ```typescript
68
- TwitterOpenapiPython.additional_api_headers = {
77
+ ```python
78
+ client = TwitterOpenapiPython()
79
+ client.additional_api_headers = {
69
80
  "sec-ch-ua-platform": '"Windows"',
70
81
  };
71
82
  ```
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "twitter_openapi_python"
3
- version = "0.0.24"
3
+ version = "0.0.26"
4
4
  description = "Twitter OpenAPI"
5
5
  authors = ["fa0311 <yuki@yuki0311.com>"]
6
6
  license = "proprietary" # or "AGPL-3.0-only"
@@ -14,7 +14,7 @@ include = ["twitter_openapi_python/py.typed"]
14
14
  python = "^3.7"
15
15
  pydantic = ">=2.6"
16
16
 
17
- twitter-openapi-python-generated = "0.0.21"
17
+ twitter-openapi-python-generated = "0.0.24"
18
18
 
19
19
  [tool.poetry.dev-dependencies]
20
20
 
@@ -1,14 +1,26 @@
1
1
  # coding: utf-8
2
2
 
3
+ import re
4
+
3
5
  from setuptools import find_packages, setup
4
6
 
5
7
  NAME = "twitter_openapi_python"
6
- VERSION = "0.0.24"
8
+ VERSION = "0.0.26"
7
9
  PYTHON_REQUIRES = ">=3.7"
8
10
  REQUIRES = [
9
- "twitter_openapi_python_generated == 0.0.21",
11
+ "twitter_openapi_python_generated == 0.0.24",
10
12
  "pydantic >= 2.6",
11
13
  ]
14
+ GITHUB_RAW_URL = "https://raw.githubusercontent.com/fa0311/twitter_openapi_python/refs/heads/master/twitter_openapi_python/"
15
+
16
+
17
+ def image_replace(text: str, url: str):
18
+ return re.sub(
19
+ r"!\[(.*?)\]\((.*?)\)",
20
+ r"![\1](" + url + r"\2)",
21
+ text,
22
+ )
23
+
12
24
 
13
25
  setup(
14
26
  name=NAME,
@@ -23,8 +35,6 @@ setup(
23
35
  include_package_data=True,
24
36
  license="proprietary or AGPL-3.0-or-later",
25
37
  long_description_content_type="text/markdown",
26
- long_description="""\
27
- Twitter scraping with data validation by pydantic.
28
- """, # noqa: E501
38
+ long_description=image_replace(open("README.md").read(), GITHUB_RAW_URL),
29
39
  package_data={"twitter_openapi_python": ["py.typed"]},
30
40
  )
@@ -58,7 +58,7 @@ class TwitterOpenapiPythonClient:
58
58
 
59
59
 
60
60
  class TwitterOpenapiPython:
61
- hash: str = "0c64eebbfb93b3ed69c3aba923ec8d6894a39902"
61
+ hash: str = "4b27150977e1bdd807de8969dc0ddd7918ac9923"
62
62
  placeholder_url = "https://raw.githubusercontent.com/fa0311/twitter-openapi/{hash}/src/config/placeholder.json"
63
63
  header = "https://raw.githubusercontent.com/fa0311/latest-user-agent/refs/heads/main/header.json"
64
64
  access_token: str = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
@@ -81,7 +81,6 @@ class TwitterOpenapiPython:
81
81
  {
82
82
  **getHader("chrome-fetch"),
83
83
  "accept-encoding": "identity",
84
- "pragma": "no-cache",
85
84
  "referer": self.twitter_url,
86
85
  "priority": "u=1, i",
87
86
  "x-twitter-client-language": "en",
@@ -98,11 +97,18 @@ class TwitterOpenapiPython:
98
97
  },
99
98
  )
100
99
 
100
+ def remove_prefix(self, text: str) -> str:
101
+ if text.startswith("x-twitter-"):
102
+ return text[10:]
103
+ if text.startswith("x-"):
104
+ return text[2:]
105
+ return text
106
+
101
107
  def kebab_to_upper_camel(self, text: dict[str, Any]) -> dict[str, Any]:
102
108
  res = {}
103
109
  for key, value in text.items():
104
110
  new_key = "".join(
105
- [x.capitalize() for x in key.replace("x-twitter-", "").split("-")]
111
+ [x.capitalize() for x in self.remove_prefix(key).split("-")]
106
112
  )
107
113
  res[new_key] = value
108
114
  return res
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.1
2
+ Name: twitter-openapi-python
3
+ Version: 0.0.26
4
+ Summary: Twitter OpenAPI
5
+ Home-page: https://github.com/fa0311/twitter_openapi_python
6
+ Author: fa0311
7
+ Author-email: yuki@yuki0311.com
8
+ License: proprietary or AGPL-3.0-or-later
9
+ Keywords: OpenAPI,OpenAPI-Generator,Twitter OpenAPI
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ License-File: LICENSE.AGPL
13
+
14
+ # twitter_openapi_python
15
+
16
+ Twitter scraping with data validation by pydantic.
17
+
18
+ ![1691572735537](https://raw.githubusercontent.com/fa0311/twitter_openapi_python/refs/heads/master/twitter_openapi_python/docs/image/README/1691572735537.png)
19
+
20
+ ## Setup
21
+
22
+ ```shell
23
+ pip install twitter-openapi-python
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```python
29
+ import json
30
+ import datetime
31
+
32
+ from pathlib import Path
33
+ from tweepy_authlib import CookieSessionUserHandler
34
+ from twitter_openapi_python import TwitterOpenapiPython
35
+
36
+ # login by tweepy_authlib
37
+ if Path("cookie.json").exists():
38
+ with open("cookie.json", "r") as f:
39
+ cookies_dict = json.load(f)
40
+ if isinstance(cookies_dict, list):
41
+ cookies_dict = {k["name"]: k["value"] for k in cookies_dict}
42
+ else:
43
+ auth_handler = CookieSessionUserHandler(
44
+ screen_name=input("screen_name: "),
45
+ password=input("password: "),
46
+ )
47
+ cookies_dict = auth_handler.get_cookies().get_dict()
48
+
49
+ # To extract cookies from Windows (Linux by default)
50
+ # If you use tweepy_authlib, you must be on Windows
51
+ client = TwitterOpenapiPython()
52
+ client.additional_api_headers = {
53
+ "sec-ch-ua-platform": '"Windows"',
54
+ }
55
+ client.additional_browser_headers = {
56
+ "sec-ch-ua-platform": '"Windows"',
57
+ }
58
+
59
+ # get client from cookies
60
+ 撫 = client.get_client_from_cookies(cookies=cookies_dict)
61
+
62
+ # tweet "Hello World!!" with current time
63
+ time = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ")
64
+ 撫.get_post_api().post_create_tweet(tweet_text=f"Hello World!!{time}")
65
+
66
+ # get user info
67
+ response = 撫.get_user_api().get_user_by_screen_name("elonmusk")
68
+ ```
69
+
70
+ ### Login
71
+
72
+ ```python
73
+ from twitter_openapi_python import TwitterOpenapiPython
74
+
75
+ # guest client
76
+ 撫 = TwitterOpenapiPython().get_guest_client()
77
+ tweet = 撫.get_default_api().get_tweet_result_by_rest_id("1349129669258448897")
78
+ assert tweet.data is not None
79
+ assert tweet.data.tweet.legacy is not None
80
+ print(tweet.data.tweet.legacy.full_text)
81
+ ```
82
+
83
+ ### Multiple OS
84
+
85
+ The Token can only be used on the same OS that issued the Token
86
+ In other words, if the sec-ch-ua-platform does not match, the Token cannot be used.
87
+ This library uses the Linux Chrome header by default.
88
+ To use Token issued by Windows, do the following.
89
+
90
+ ```python
91
+ client = TwitterOpenapiPython()
92
+ client.additional_api_headers = {
93
+ "sec-ch-ua-platform": '"Windows"',
94
+ };
95
+ ```
96
+
97
+ ## License
98
+
99
+ This project is dual licensed. You can choose one of the following licenses:
100
+
101
+ - [Custom License](./LICENSE)
102
+ - [GNU Affero General Public License v3.0](./LICENSE.AGPL)
@@ -0,0 +1,2 @@
1
+ twitter_openapi_python_generated==0.0.24
2
+ pydantic>=2.6
@@ -1,15 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: twitter_openapi_python
3
- Version: 0.0.24
4
- Summary: Twitter OpenAPI
5
- Home-page: https://github.com/fa0311/twitter_openapi_python
6
- Author: fa0311
7
- Author-email: yuki@yuki0311.com
8
- License: proprietary or AGPL-3.0-or-later
9
- Keywords: OpenAPI,OpenAPI-Generator,Twitter OpenAPI
10
- Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
- License-File: LICENSE.AGPL
13
-
14
- Twitter scraping with data validation by pydantic.
15
-
@@ -1,15 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: twitter-openapi-python
3
- Version: 0.0.24
4
- Summary: Twitter OpenAPI
5
- Home-page: https://github.com/fa0311/twitter_openapi_python
6
- Author: fa0311
7
- Author-email: yuki@yuki0311.com
8
- License: proprietary or AGPL-3.0-or-later
9
- Keywords: OpenAPI,OpenAPI-Generator,Twitter OpenAPI
10
- Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
- License-File: LICENSE.AGPL
13
-
14
- Twitter scraping with data validation by pydantic.
15
-
@@ -1,2 +0,0 @@
1
- twitter_openapi_python_generated==0.0.21
2
- pydantic>=2.6