twitter-openapi-python 0.1.4__py3-none-any.whl → 0.1.5__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.
@@ -26,7 +26,7 @@ class BirdwatchApiUtils:
26
26
  api: twitter.BirdwatchApi
27
27
  flag: ParamType
28
28
 
29
- def __init__(self, api: twitter.BirdwatchApi, flag: ParamType, ct: ClientTransaction):
29
+ def __init__(self, api: twitter.BirdwatchApi, flag: ParamType, ct: Optional[ClientTransaction]):
30
30
  self.api = api
31
31
  self.flag = flag
32
32
  self.ct = ct
@@ -24,7 +24,7 @@ class CommunityApiUtils:
24
24
  api: twitter.CommunityApi
25
25
  flag: ParamType
26
26
 
27
- def __init__(self, api: twitter.CommunityApi, flag: ParamType, ct: ClientTransaction):
27
+ def __init__(self, api: twitter.CommunityApi, flag: ParamType, ct: Optional[ClientTransaction]):
28
28
  self.api = api
29
29
  self.flag = flag
30
30
  self.ct = ct
@@ -22,7 +22,7 @@ class DefaultApiUtils:
22
22
  api: twitter.DefaultApi
23
23
  flag: ParamType
24
24
 
25
- def __init__(self, api: twitter.DefaultApi, flag: ParamType, ct: ClientTransaction):
25
+ def __init__(self, api: twitter.DefaultApi, flag: ParamType, ct: Optional[ClientTransaction]):
26
26
  self.api = api
27
27
  self.flag = flag
28
28
  self.ct = ct
@@ -17,7 +17,7 @@ class PostApiUtils:
17
17
  api: twitter.PostApi
18
18
  flag: ParamType
19
19
 
20
- def __init__(self, api: twitter.PostApi, flag: ParamType, ct: ClientTransaction):
20
+ def __init__(self, api: twitter.PostApi, flag: ParamType, ct: Optional[ClientTransaction]):
21
21
  self.api = api
22
22
  self.flag = flag
23
23
  self.ct = ct
@@ -36,7 +36,7 @@ class TweetApiUtils:
36
36
  api: twitter.TweetApi
37
37
  flag: ParamType
38
38
 
39
- def __init__(self, api: twitter.TweetApi, flag: ParamType, ct: ClientTransaction):
39
+ def __init__(self, api: twitter.TweetApi, flag: ParamType, ct: Optional[ClientTransaction]):
40
40
  self.api = api
41
41
  self.flag = flag
42
42
  self.ct = ct
@@ -23,7 +23,7 @@ class UserApiUtils:
23
23
  api: twitter.UserApi
24
24
  flag: ParamType
25
25
 
26
- def __init__(self, api: twitter.UserApi, flag: ParamType, ct: ClientTransaction):
26
+ def __init__(self, api: twitter.UserApi, flag: ParamType, ct: Optional[ClientTransaction]):
27
27
  self.api = api
28
28
  self.flag = flag
29
29
  self.ct = ct
@@ -29,7 +29,7 @@ class UserListApiUtils:
29
29
  api: twitter.UserListApi
30
30
  flag: ParamType
31
31
 
32
- def __init__(self, api: twitter.UserListApi, flag: ParamType, ct: ClientTransaction):
32
+ def __init__(self, api: twitter.UserListApi, flag: ParamType, ct: Optional[ClientTransaction]):
33
33
  self.api = api
34
34
  self.flag = flag
35
35
  self.ct = ct
@@ -23,7 +23,7 @@ class UsersApiUtils:
23
23
  api: twitter.UsersApi
24
24
  flag: ParamType
25
25
 
26
- def __init__(self, api: twitter.UsersApi, flag: ParamType, ct: ClientTransaction):
26
+ def __init__(self, api: twitter.UsersApi, flag: ParamType, ct: Optional[ClientTransaction]):
27
27
  self.api = api
28
28
  self.flag = flag
29
29
  self.ct = ct
@@ -1,6 +1,6 @@
1
1
  import json
2
2
  import re
3
- from typing import Any
3
+ from typing import Any, Optional
4
4
 
5
5
  import twitter_openapi_python_generated as twitter
6
6
  import twitter_openapi_python_generated.configuration as conf
@@ -29,7 +29,7 @@ class TwitterOpenapiPythonClient:
29
29
  api: twitter.ApiClient
30
30
  placeholder: ParamType
31
31
 
32
- def __init__(self, api: twitter.ApiClient, placeholder: ParamType, ct: ClientTransaction):
32
+ def __init__(self, api: twitter.ApiClient, placeholder: ParamType, ct: Optional[ClientTransaction]):
33
33
  self.api = api
34
34
  self.placeholder = placeholder
35
35
  self.ct = ct
@@ -137,6 +137,18 @@ class TwitterOpenapiPython:
137
137
  ct = get_tid()
138
138
  return TwitterOpenapiPythonClient(api, json.loads(flag.data), ct)
139
139
 
140
+ def get_client_from_endpoint(
141
+ self,
142
+ host: str,
143
+ headers: dict[str, str] = {},
144
+ ) -> TwitterOpenapiPythonClient:
145
+ http = urllib3.PoolManager()
146
+ flag = http.request("GET", self.placeholder_url.format(hash=self.hash))
147
+ api_client = twitter.ApiClient(configuration=conf.Configuration(host=host))
148
+ for key, value in headers.items():
149
+ api_client.set_default_header(key, value)
150
+ return TwitterOpenapiPythonClient(api_client, json.loads(flag.data), None)
151
+
140
152
  def get_client_from_cookies(
141
153
  self,
142
154
  cookies: dict[str, str],
@@ -40,7 +40,7 @@ def non_nullable_list(x: List[Optional[T]]) -> List[T]:
40
40
  return list(filter(filter_fn, x))
41
41
 
42
42
 
43
- def get_kwargs(flag: ParamType, additional: ParamType, ct: ClientTransaction) -> ParamType:
43
+ def get_kwargs(flag: ParamType, additional: ParamType, ct: Optional[ClientTransaction]) -> ParamType:
44
44
  assert flag is not None
45
45
  kwargs = {"path_query_id": flag["queryId"]}
46
46
  if flag.get("variables") is not None:
@@ -54,7 +54,9 @@ def get_kwargs(flag: ParamType, additional: ParamType, ct: ClientTransaction) ->
54
54
  return kwargs
55
55
 
56
56
 
57
- def get_headers(flag: ParamType, ct: ClientTransaction) -> Dict[str, str]:
57
+ def get_headers(flag: ParamType, ct: Optional[ClientTransaction]) -> Dict[str, str]:
58
+ if ct is None:
59
+ return {}
58
60
  tid = ct.generate_transaction_id(flag["@method"], flag["@path"])
59
61
  return {"x-client-transaction-id": tid}
60
62
 
@@ -304,7 +306,7 @@ def build_header(headers: Dict[str, str]) -> ApiUtilsHeader:
304
306
  def timeline_request(
305
307
  api_fn: Callable[..., twitter.ApiResponse[T1]],
306
308
  flag: ParamType,
307
- ct: ClientTransaction,
309
+ ct: Optional[ClientTransaction],
308
310
  convert_fn: Callable[[T1], List[models.InstructionUnion]],
309
311
  param: ParamType,
310
312
  items_fn: Callable[[List[models.TimelineAddEntry]], List[T2]],
@@ -323,7 +325,7 @@ def timeline_request(
323
325
  def data_request(
324
326
  api_fn: Callable[..., twitter.ApiResponse[T1]],
325
327
  flag: ParamType,
326
- ct: ClientTransaction,
328
+ ct: Optional[ClientTransaction],
327
329
  convert_fn: Callable[[T1], T2],
328
330
  param: ParamType,
329
331
  ) -> TwitterApiUtilsResponse[T2]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twitter_openapi_python
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Twitter OpenAPI
5
5
  Keywords: twitter,api,python,scraper
6
6
  Author: fa0311
@@ -102,14 +102,12 @@ client.additional_api_headers = {
102
102
 
103
103
  ### Endpoint
104
104
 
105
- The generated client accepts any host that keeps X's path shape (`/graphql/{queryId}/{operationName}`, `/1.1/...`, `/2/...` under `https://x.com/i/api`). Build the `ApiClient` yourself and hand it to `get_twitter_openapi_python_client`; the login helpers are not involved, so cookies and headers are then up to you (or to whatever answers at that host). For example, [twitter_api_safe_relay](https://github.com/fa0311/twitter_api_safe_relay) answers at `http://localhost:3000/i/api` with a logged-in browser session.
105
+ The generated client accepts any host that keeps X's path shape (`/graphql/{queryId}/{operationName}`, `/1.1/...`, `/2/...` under `https://x.com/i/api`). `get_client_from_endpoint` is for a host that already holds the session: it sends no cookie, no bearer, no browser headers and no transaction id, only the query and the headers you pass (the second argument is added to every request, for whatever the host defines). For example, [twitter_api_safe_relay](https://github.com/fa0311/twitter_api_safe_relay) answers at `http://localhost:3000/i/api` with a logged-in browser session.
106
106
 
107
107
  ```python
108
- import twitter_openapi_python_generated as twitter
109
108
  from twitter_openapi_python import TwitterOpenapiPython
110
109
 
111
- api_client = twitter.ApiClient(twitter.Configuration(host="http://localhost:3000/i/api"))
112
- client = TwitterOpenapiPython().get_twitter_openapi_python_client(api_client)
110
+ client = TwitterOpenapiPython().get_client_from_endpoint("http://localhost:3000/i/api")
113
111
  response = client.get_user_api().get_user_by_screen_name(screen_name="elonmusk")
114
112
  ```
115
113
 
@@ -1,17 +1,17 @@
1
1
  twitter_openapi_python/__init__.py,sha256=IyCanHNVJtKPGaYEMBqF37VXfMtZNUJlPhSOZMvO5jg,324
2
2
  twitter_openapi_python/api/__init__.py,sha256=1YPsr8wnqlrBFAViXCwYwDdk2kNwA6PMC8DAnsWC62U,772
3
- twitter_openapi_python/api/birdwatch_api.py,sha256=_SpT0-RU3GhEvYa9Sqf7JpC62kxnE-u0CbUnCHNTrBM,4121
4
- twitter_openapi_python/api/community_api.py,sha256=hht31A83v3BfqcYa1-H9LyNIKd7UJMUWM9kzMUEJCus,5379
5
- twitter_openapi_python/api/default_api.py,sha256=Ca8OYS6TiYYVWo64QG-HUcmgog8FXwo5Xe8_-PUI6Js,7765
3
+ twitter_openapi_python/api/birdwatch_api.py,sha256=5Nk1wqpsUmAFQXytpNP5tVAnEUy06r0Yb7oJMA1jbDc,4131
4
+ twitter_openapi_python/api/community_api.py,sha256=AA59UgBz_l2i9ny9rNyPxFUVj5zR40WKQavHr5SLxs0,5389
5
+ twitter_openapi_python/api/default_api.py,sha256=rE6hrAe_wxBkiYe6ZhdseSHMwFuBzSeItDTRqop4J7M,7775
6
6
  twitter_openapi_python/api/initial_state_api.py,sha256=nAkb25-btWdMoSyyncxS_VrBQ9uKDgzmG7jBubfETYo,2269
7
- twitter_openapi_python/api/post_api.py,sha256=YSiGjV95AxxxSukZZESVRJ34D8hde6YRjd0Q6ElQ8fE,13166
8
- twitter_openapi_python/api/tweet_api.py,sha256=qaFin2czb9SObvEz_ObMG6NOf7e_Da90m7Pkckon7rM,24226
9
- twitter_openapi_python/api/user_api.py,sha256=DdNQHQUThdRA_ODFfEJVR3hJloU3_iOJQwlX1YW-Wxw,5249
10
- twitter_openapi_python/api/user_list_api.py,sha256=dCp_K0bIC0CBn_kI5B8hpKy0TVhZgET4zpfadc_TrZ0,13471
11
- twitter_openapi_python/api/users_api.py,sha256=edfkhsQ6y3GdaMuTl7XEX22NBXWqn8J9zTBDyPe9cTU,3243
7
+ twitter_openapi_python/api/post_api.py,sha256=bmVMHcEMrBcwL3nkqf1mqx2Y2TYgFiEIyaUQVcgFoyw,13176
8
+ twitter_openapi_python/api/tweet_api.py,sha256=v9Qf5FOGTDmrT6zuQwlDixYxxkP0LNwZpE-btVSYCoc,24236
9
+ twitter_openapi_python/api/user_api.py,sha256=D9K3OVIZFYhZMTDMFvy42-8kMBE6xisiSMa3yQhIQIo,5259
10
+ twitter_openapi_python/api/user_list_api.py,sha256=8WxhVU69I_mmVlgdvkeIKFw1vcE2raDQ4kBTTMX_ua4,13481
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=FNPxbYLaYnxEUfZ2KxNVb4ebXxTgNmwuS6XDn2BOH6o,7126
14
+ twitter_openapi_python/client.py,sha256=K8qz5O7jwmgxHUjhSm8HOq7kbXsxCj39NKMVWqghpXk,7670
15
15
  twitter_openapi_python/models/__init__.py,sha256=pHISZJrEPBlXS25kMydl1SxXuCct-CUpnPDfL7kEEBo,588
16
16
  twitter_openapi_python/models/base.py,sha256=3sw6wdQn9i8FoujFxhEFVWIB26-qjI6JTDuXKuebM0Y,189
17
17
  twitter_openapi_python/models/header.py,sha256=EKujtBRZOJmeh2SD1QOCsLWaE9gdGY4wsNUgwCnbTCU,644
@@ -21,9 +21,9 @@ twitter_openapi_python/models/timeline.py,sha256=dRMoc7zqyW_E2iehs4F6HfX8Iy_1b-e
21
21
  twitter_openapi_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  twitter_openapi_python/tid.py,sha256=xjqJMyPOp62nw2MQjMGHaB4L6G6OZHuWkMR-WKJo7aU,1120
23
23
  twitter_openapi_python/utils/__init__.py,sha256=lIEPoDqtgCvUk0A8cWqdTlTWMhkEp_NbVxL7sJ0uiu8,612
24
- twitter_openapi_python/utils/api.py,sha256=pB8HxigbImUPb-dN0skQM8Am1jPEybhX9KUioJZzL50,12678
25
- twitter_openapi_python-0.1.4.dist-info/licenses/LICENSE,sha256=sLv8EMhrPCMG_LeweYvYKS_B-cDMBwBSKZel7LSMGAs,1493
26
- twitter_openapi_python-0.1.4.dist-info/licenses/LICENSE.AGPL,sha256=TfPDBt3ar0uv_f9cqCDMZ5rIzW3CY8anRRd4PkL6ejs,34522
27
- twitter_openapi_python-0.1.4.dist-info/WHEEL,sha256=3NO1oYsF7mANFUWVdyEQLM-zmecczWWEmmF5rEbXrWk,80
28
- twitter_openapi_python-0.1.4.dist-info/METADATA,sha256=19fM08JkjkVq2dyC5srB3R3q0nsfPzizIBU6z2WM1XU,4136
29
- twitter_openapi_python-0.1.4.dist-info/RECORD,,
24
+ 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,,