twitter-openapi-python 0.0.24__py3-none-any.whl → 0.0.26__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.
@@ -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,104 @@
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
+ Requires-Dist: twitter-openapi-python-generated ==0.0.24
14
+ Requires-Dist: pydantic >=2.6
15
+
16
+ # twitter_openapi_python
17
+
18
+ Twitter scraping with data validation by pydantic.
19
+
20
+ ![1691572735537](https://raw.githubusercontent.com/fa0311/twitter_openapi_python/refs/heads/master/twitter_openapi_python/docs/image/README/1691572735537.png)
21
+
22
+ ## Setup
23
+
24
+ ```shell
25
+ pip install twitter-openapi-python
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```python
31
+ import json
32
+ import datetime
33
+
34
+ from pathlib import Path
35
+ from tweepy_authlib import CookieSessionUserHandler
36
+ from twitter_openapi_python import TwitterOpenapiPython
37
+
38
+ # login by tweepy_authlib
39
+ if Path("cookie.json").exists():
40
+ with open("cookie.json", "r") as f:
41
+ cookies_dict = json.load(f)
42
+ if isinstance(cookies_dict, list):
43
+ cookies_dict = {k["name"]: k["value"] for k in cookies_dict}
44
+ else:
45
+ auth_handler = CookieSessionUserHandler(
46
+ screen_name=input("screen_name: "),
47
+ password=input("password: "),
48
+ )
49
+ cookies_dict = auth_handler.get_cookies().get_dict()
50
+
51
+ # To extract cookies from Windows (Linux by default)
52
+ # If you use tweepy_authlib, you must be on Windows
53
+ client = TwitterOpenapiPython()
54
+ client.additional_api_headers = {
55
+ "sec-ch-ua-platform": '"Windows"',
56
+ }
57
+ client.additional_browser_headers = {
58
+ "sec-ch-ua-platform": '"Windows"',
59
+ }
60
+
61
+ # get client from cookies
62
+ 撫 = client.get_client_from_cookies(cookies=cookies_dict)
63
+
64
+ # tweet "Hello World!!" with current time
65
+ time = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ")
66
+ 撫.get_post_api().post_create_tweet(tweet_text=f"Hello World!!{time}")
67
+
68
+ # get user info
69
+ response = 撫.get_user_api().get_user_by_screen_name("elonmusk")
70
+ ```
71
+
72
+ ### Login
73
+
74
+ ```python
75
+ from twitter_openapi_python import TwitterOpenapiPython
76
+
77
+ # guest client
78
+ 撫 = TwitterOpenapiPython().get_guest_client()
79
+ tweet = 撫.get_default_api().get_tweet_result_by_rest_id("1349129669258448897")
80
+ assert tweet.data is not None
81
+ assert tweet.data.tweet.legacy is not None
82
+ print(tweet.data.tweet.legacy.full_text)
83
+ ```
84
+
85
+ ### Multiple OS
86
+
87
+ The Token can only be used on the same OS that issued the Token
88
+ In other words, if the sec-ch-ua-platform does not match, the Token cannot be used.
89
+ This library uses the Linux Chrome header by default.
90
+ To use Token issued by Windows, do the following.
91
+
92
+ ```python
93
+ client = TwitterOpenapiPython()
94
+ client.additional_api_headers = {
95
+ "sec-ch-ua-platform": '"Windows"',
96
+ };
97
+ ```
98
+
99
+ ## License
100
+
101
+ This project is dual licensed. You can choose one of the following licenses:
102
+
103
+ - [Custom License](./LICENSE)
104
+ - [GNU Affero General Public License v3.0](./LICENSE.AGPL)
@@ -1,5 +1,5 @@
1
1
  twitter_openapi_python/__init__.py,sha256=stqYIfWDqM0yC93SQNp4-b2hSz-ONWR3QxOG5g2oREg,339
2
- twitter_openapi_python/client.py,sha256=i0ynE5orodZtPCLGUYmalBD7lL4HMBBItypdUmlJYJg,6673
2
+ twitter_openapi_python/client.py,sha256=zs95e9BLmYLMfO5ZF3XqrSlj2wMBCeOHsYALtBNd8fQ,6836
3
3
  twitter_openapi_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  twitter_openapi_python/api/__init__.py,sha256=-2hoS75Fp0KvCIWKYQFpvAl0pcbFyt7Be3ood08P7n8,643
5
5
  twitter_openapi_python/api/default_api.py,sha256=PeHYaAw6xaUB9ZE3An5SKcEvW71JLTFSgyte80BBvX4,2751
@@ -19,9 +19,9 @@ twitter_openapi_python/models/response.py,sha256=ZuaX36mKRsVx5aiJhNw3CjrvVGVaGjM
19
19
  twitter_openapi_python/models/timeline.py,sha256=AoWfrJsonYImlweciaUSjFzmeciaX0zshi7d-FkT4LM,1392
20
20
  twitter_openapi_python/utils/__init__.py,sha256=QVT1eCClP9EVfcZ4QU96TVegfAUDEtJ-PVp3zv6qy6w,449
21
21
  twitter_openapi_python/utils/api.py,sha256=JTSXE1Wh3AiuOb_APTDTQMrR4HTkI9AihzrXkJGV2d8,10026
22
- twitter_openapi_python-0.0.24.dist-info/LICENSE,sha256=xthyYzrtSmRlBu2gnfuIxzsZeHrqtIZgZPL9UPrYiQU,1524
23
- twitter_openapi_python-0.0.24.dist-info/LICENSE.AGPL,sha256=Nv6u1ubULm-E2y6q2-pQPK8s2BzkOltLaVlPKQ3tkcs,35182
24
- twitter_openapi_python-0.0.24.dist-info/METADATA,sha256=gAfBFLyf8j_Nb0LtsAPTmWrRdaG62cbE7WdveewWmsU,551
25
- twitter_openapi_python-0.0.24.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
26
- twitter_openapi_python-0.0.24.dist-info/top_level.txt,sha256=wKFCnW_S6aWD3nFPmd65SxZIviiqQ30LqHOLLpcnTdE,23
27
- twitter_openapi_python-0.0.24.dist-info/RECORD,,
22
+ twitter_openapi_python-0.0.26.dist-info/LICENSE,sha256=xthyYzrtSmRlBu2gnfuIxzsZeHrqtIZgZPL9UPrYiQU,1524
23
+ twitter_openapi_python-0.0.26.dist-info/LICENSE.AGPL,sha256=Nv6u1ubULm-E2y6q2-pQPK8s2BzkOltLaVlPKQ3tkcs,35182
24
+ twitter_openapi_python-0.0.26.dist-info/METADATA,sha256=R9x-5XSeTj8csBZpxiaaXPDyf5rG1ihqmltoCT7PkWw,3070
25
+ twitter_openapi_python-0.0.26.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
26
+ twitter_openapi_python-0.0.26.dist-info/top_level.txt,sha256=wKFCnW_S6aWD3nFPmd65SxZIviiqQ30LqHOLLpcnTdE,23
27
+ twitter_openapi_python-0.0.26.dist-info/RECORD,,
@@ -1,17 +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
- Requires-Dist: twitter-openapi-python-generated ==0.0.21
14
- Requires-Dist: pydantic >=2.6
15
-
16
- Twitter scraping with data validation by pydantic.
17
-