twitter-openapi-python 0.0.44__py3-none-any.whl → 0.1.0__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.
Files changed (28) hide show
  1. twitter_openapi_python/__init__.py +15 -15
  2. twitter_openapi_python/api/__init__.py +13 -13
  3. twitter_openapi_python/api/default_api.py +80 -80
  4. twitter_openapi_python/api/initial_state_api.py +72 -72
  5. twitter_openapi_python/api/post_api.py +166 -166
  6. twitter_openapi_python/api/tweet_api.py +428 -353
  7. twitter_openapi_python/api/user_api.py +80 -80
  8. twitter_openapi_python/api/user_list_api.py +171 -171
  9. twitter_openapi_python/api/users_api.py +56 -56
  10. twitter_openapi_python/api/v11_get_api.py +67 -70
  11. twitter_openapi_python/api/v11_post_api.py +61 -66
  12. twitter_openapi_python/client.py +194 -194
  13. twitter_openapi_python/models/__init__.py +22 -22
  14. twitter_openapi_python/models/base.py +9 -9
  15. twitter_openapi_python/models/header.py +20 -20
  16. twitter_openapi_python/models/initial_state.py +17 -17
  17. twitter_openapi_python/models/response.py +19 -19
  18. twitter_openapi_python/models/timeline.py +40 -40
  19. twitter_openapi_python/tid.py +27 -17
  20. twitter_openapi_python/utils/__init__.py +22 -22
  21. twitter_openapi_python/utils/api.py +288 -288
  22. {twitter_openapi_python-0.0.44.dist-info → twitter_openapi_python-0.1.0.dist-info}/METADATA +118 -117
  23. twitter_openapi_python-0.1.0.dist-info/RECORD +27 -0
  24. {twitter_openapi_python-0.0.44.dist-info → twitter_openapi_python-0.1.0.dist-info}/WHEEL +1 -2
  25. {twitter_openapi_python-0.0.44.dist-info → twitter_openapi_python-0.1.0.dist-info}/licenses/LICENSE +31 -31
  26. {twitter_openapi_python-0.0.44.dist-info → twitter_openapi_python-0.1.0.dist-info}/licenses/LICENSE.AGPL +660 -660
  27. twitter_openapi_python-0.0.44.dist-info/RECORD +0 -28
  28. twitter_openapi_python-0.0.44.dist-info/top_level.txt +0 -1
@@ -1,15 +1,15 @@
1
- # coding: utf-8
2
-
3
- # flake8: noqa
4
-
5
-
6
- from twitter_openapi_python_generated.models import *
7
-
8
- from twitter_openapi_python.api import *
9
- from twitter_openapi_python.client import (
10
- TwitterOpenapiPython,
11
- TwitterOpenapiPythonClient,
12
- )
13
- from twitter_openapi_python.models import *
14
-
15
- # from twitter_openapi_python.utils import *
1
+ # coding: utf-8
2
+
3
+ # flake8: noqa
4
+
5
+
6
+ from twitter_openapi_python_generated.models import *
7
+
8
+ from twitter_openapi_python.api import *
9
+ from twitter_openapi_python.client import (
10
+ TwitterOpenapiPython,
11
+ TwitterOpenapiPythonClient,
12
+ )
13
+ from twitter_openapi_python.models import *
14
+
15
+ # from twitter_openapi_python.utils import *
@@ -1,13 +1,13 @@
1
- # coding: utf-8
2
-
3
- # flake8: noqa
4
-
5
- from twitter_openapi_python.api.default_api import DefaultApiUtils
6
- from twitter_openapi_python.api.initial_state_api import InitialStateApiUtils
7
- from twitter_openapi_python.api.post_api import PostApiUtils
8
- from twitter_openapi_python.api.tweet_api import TweetApiUtils
9
- from twitter_openapi_python.api.user_api import UserApiUtils
10
- from twitter_openapi_python.api.user_list_api import UserListApiUtils
11
- from twitter_openapi_python.api.users_api import UsersApiUtils
12
- from twitter_openapi_python.api.v11_get_api import V11GetApiUtils
13
- from twitter_openapi_python.api.v11_post_api import V11PostApiUtils
1
+ # coding: utf-8
2
+
3
+ # flake8: noqa
4
+
5
+ from twitter_openapi_python.api.default_api import DefaultApiUtils
6
+ from twitter_openapi_python.api.initial_state_api import InitialStateApiUtils
7
+ from twitter_openapi_python.api.post_api import PostApiUtils
8
+ from twitter_openapi_python.api.tweet_api import TweetApiUtils
9
+ from twitter_openapi_python.api.user_api import UserApiUtils
10
+ from twitter_openapi_python.api.user_list_api import UserListApiUtils
11
+ from twitter_openapi_python.api.users_api import UsersApiUtils
12
+ from twitter_openapi_python.api.v11_get_api import V11GetApiUtils
13
+ from twitter_openapi_python.api.v11_post_api import V11PostApiUtils
@@ -1,80 +1,80 @@
1
- from typing import Any, Callable, Optional, TypeVar
2
-
3
- import twitter_openapi_python_generated as twitter
4
- import twitter_openapi_python_generated.models as models
5
- from x_client_transaction import ClientTransaction
6
-
7
- from twitter_openapi_python.models import TweetApiUtilsData, TwitterApiUtilsResponse
8
- from twitter_openapi_python.utils import (
9
- build_response,
10
- build_tweet_api_utils,
11
- get_kwargs,
12
- )
13
- from twitter_openapi_python.utils.api import error_check
14
-
15
- T1 = TypeVar("T1")
16
- T2 = TypeVar("T2")
17
- ApiFnType = Callable[..., twitter.ApiResponse[T1]]
18
- ParamType = dict[str, Any]
19
-
20
-
21
- class DefaultApiUtils:
22
- api: twitter.DefaultApi
23
- flag: ParamType
24
-
25
- def __init__(self, api: twitter.DefaultApi, flag: ParamType, ct: ClientTransaction):
26
- self.api = api
27
- self.flag = flag
28
- self.ct = ct
29
-
30
- def request(
31
- self,
32
- apiFn: "ApiFnType[T1]",
33
- convertFn: Callable[[T1], T2],
34
- key: str,
35
- param: ParamType,
36
- ):
37
- args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
38
- res = apiFn(**args)
39
- data = convertFn(res.data)
40
- return build_response(res, data)
41
-
42
- def get_profile_spotlights_query(
43
- self,
44
- screen_name: Optional[str] = None,
45
- extra_param: Optional[ParamType] = None,
46
- ) -> TwitterApiUtilsResponse[models.UserResultByScreenName]:
47
- param: ParamType = {}
48
- if screen_name is not None:
49
- param["screen_name"] = screen_name
50
- if extra_param is not None:
51
- param.update(extra_param)
52
-
53
- response = self.request(
54
- apiFn=self.api.get_profile_spotlights_query_with_http_info,
55
- convertFn=lambda x: error_check(x.data.user_result_by_screen_name, x.errors),
56
- key="ProfileSpotlightsQuery",
57
- param=param,
58
- )
59
- return response
60
-
61
- def get_tweet_result_by_rest_id(
62
- self,
63
- tweet_id: str,
64
- extra_param: Optional[ParamType] = None,
65
- ) -> TwitterApiUtilsResponse[TweetApiUtilsData]:
66
- param: ParamType = {"tweetId": tweet_id}
67
- if extra_param is not None:
68
- param.update(extra_param)
69
-
70
- response = self.request(
71
- apiFn=self.api.get_tweet_result_by_rest_id_with_http_info,
72
- convertFn=lambda x: error_check(
73
- build_tweet_api_utils(error_check(x.data.tweet_result, x.errors)), x.errors
74
- ),
75
- key="TweetResultByRestId",
76
- param=param,
77
- )
78
- if response.data is None:
79
- raise Exception("No tweet")
80
- return response # type: ignore
1
+ from typing import Any, Callable, Optional, TypeVar
2
+
3
+ import twitter_openapi_python_generated as twitter
4
+ import twitter_openapi_python_generated.models as models
5
+ from x_client_transaction import ClientTransaction
6
+
7
+ from twitter_openapi_python.models import TweetApiUtilsData, TwitterApiUtilsResponse
8
+ from twitter_openapi_python.utils import (
9
+ build_response,
10
+ build_tweet_api_utils,
11
+ get_kwargs,
12
+ )
13
+ from twitter_openapi_python.utils.api import error_check
14
+
15
+ T1 = TypeVar("T1")
16
+ T2 = TypeVar("T2")
17
+ ApiFnType = Callable[..., twitter.ApiResponse[T1]]
18
+ ParamType = dict[str, Any]
19
+
20
+
21
+ class DefaultApiUtils:
22
+ api: twitter.DefaultApi
23
+ flag: ParamType
24
+
25
+ def __init__(self, api: twitter.DefaultApi, flag: ParamType, ct: ClientTransaction):
26
+ self.api = api
27
+ self.flag = flag
28
+ self.ct = ct
29
+
30
+ def request(
31
+ self,
32
+ apiFn: "ApiFnType[T1]",
33
+ convertFn: Callable[[T1], T2],
34
+ key: str,
35
+ param: ParamType,
36
+ ):
37
+ args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
38
+ res = apiFn(**args)
39
+ data = convertFn(res.data)
40
+ return build_response(res, data)
41
+
42
+ def get_profile_spotlights_query(
43
+ self,
44
+ screen_name: Optional[str] = None,
45
+ extra_param: Optional[ParamType] = None,
46
+ ) -> TwitterApiUtilsResponse[models.UserResultByScreenName]:
47
+ param: ParamType = {}
48
+ if screen_name is not None:
49
+ param["screen_name"] = screen_name
50
+ if extra_param is not None:
51
+ param.update(extra_param)
52
+
53
+ response = self.request(
54
+ apiFn=self.api.get_profile_spotlights_query_with_http_info,
55
+ convertFn=lambda x: error_check(x.data.user_result_by_screen_name, x.errors),
56
+ key="ProfileSpotlightsQuery",
57
+ param=param,
58
+ )
59
+ return response
60
+
61
+ def get_tweet_result_by_rest_id(
62
+ self,
63
+ tweet_id: str,
64
+ extra_param: Optional[ParamType] = None,
65
+ ) -> TwitterApiUtilsResponse[TweetApiUtilsData]:
66
+ param: ParamType = {"tweetId": tweet_id}
67
+ if extra_param is not None:
68
+ param.update(extra_param)
69
+
70
+ response = self.request(
71
+ apiFn=self.api.get_tweet_result_by_rest_id_with_http_info,
72
+ convertFn=lambda x: error_check(
73
+ build_tweet_api_utils(error_check(x.data.tweet_result, x.errors)), x.errors
74
+ ),
75
+ key="TweetResultByRestId",
76
+ param=param,
77
+ )
78
+ if response.data is None:
79
+ raise Exception("No tweet")
80
+ return response # type: ignore
@@ -1,72 +1,72 @@
1
- import json
2
- import re
3
- from typing import Any, Optional
4
-
5
- import twitter_openapi_python_generated as twitter
6
- import twitter_openapi_python_generated.models as models
7
- from urllib3 import HTTPResponse
8
-
9
- from twitter_openapi_python.models import (
10
- InitialStateApiUtilsRaw,
11
- InitialStateApiUtilsResponse,
12
- )
13
-
14
-
15
- class InitialStateApiUtils:
16
- api: twitter.ApiClient
17
- header: dict[str, Any]
18
-
19
- def __init__(self, api: twitter.ApiClient):
20
- self.api = api
21
- self.header = {
22
- "user-agent": self.api.user_agent,
23
- "cookie": self.api.cookie,
24
- }
25
-
26
- def request(self, url: str) -> HTTPResponse:
27
- return self.api.rest_client.request(
28
- "GET",
29
- url=url,
30
- headers=self.header,
31
- )
32
-
33
- def get_initial_state(self, url: str) -> InitialStateApiUtilsResponse:
34
- response = self.request(url=url).data.decode("utf-8")
35
- reg = '<script type="text/javascript" charset="utf-8" nonce="{nonce}">{any}</script>'
36
- js = re.search(reg.format(nonce=r"([a-zA-Z0-9]{48})", any=r"([\s\S]*?)"), response)
37
-
38
- if js is None:
39
- raise Exception("js is None")
40
-
41
- reg2 = "^window\\.__INITIAL_STATE__={any};window\\.__META_DATA__={any};$"
42
-
43
- source = re.search(reg2.format(any=r"([\s\S]*?)"), js.group(2))
44
-
45
- # none cast
46
- if source is None:
47
- raise Exception("source is None")
48
-
49
- raw = InitialStateApiUtilsRaw(
50
- initial_state=json.loads(source.group(1)),
51
- meta_data=json.loads(source.group(2)),
52
- )
53
-
54
- def get_user(e: dict[str, Any]) -> Optional[models.UserLegacy]:
55
- try:
56
- entities = e["entities"]["users"]["entities"]
57
- return models.UserLegacy.model_validate(list(entities.values())[0])
58
- except Exception:
59
- # todo: fix
60
- return None
61
-
62
- def get_session(e: dict[str, Any]) -> Optional[models.Session]:
63
- try:
64
- return models.Session.model_validate(e["session"])
65
- except Exception:
66
- return None
67
-
68
- return InitialStateApiUtilsResponse(
69
- raw=raw,
70
- user=get_user(raw.initial_state),
71
- session=get_session(raw.initial_state),
72
- )
1
+ import json
2
+ import re
3
+ from typing import Any, Optional
4
+
5
+ import twitter_openapi_python_generated as twitter
6
+ import twitter_openapi_python_generated.models as models
7
+ from urllib3 import HTTPResponse
8
+
9
+ from twitter_openapi_python.models import (
10
+ InitialStateApiUtilsRaw,
11
+ InitialStateApiUtilsResponse,
12
+ )
13
+
14
+
15
+ class InitialStateApiUtils:
16
+ api: twitter.ApiClient
17
+ header: dict[str, Any]
18
+
19
+ def __init__(self, api: twitter.ApiClient):
20
+ self.api = api
21
+ self.header = {
22
+ "user-agent": self.api.user_agent,
23
+ "cookie": self.api.cookie,
24
+ }
25
+
26
+ def request(self, url: str) -> HTTPResponse:
27
+ return self.api.rest_client.request(
28
+ "GET",
29
+ url=url,
30
+ headers=self.header,
31
+ )
32
+
33
+ def get_initial_state(self, url: str) -> InitialStateApiUtilsResponse:
34
+ response = self.request(url=url).data.decode("utf-8")
35
+ reg = '<script type="text/javascript" charset="utf-8" nonce="{nonce}">{any}</script>'
36
+ js = re.search(reg.format(nonce=r"([a-zA-Z0-9]{48})", any=r"([\s\S]*?)"), response)
37
+
38
+ if js is None:
39
+ raise Exception("js is None")
40
+
41
+ reg2 = "^window\\.__INITIAL_STATE__={any};window\\.__META_DATA__={any};$"
42
+
43
+ source = re.search(reg2.format(any=r"([\s\S]*?)"), js.group(2))
44
+
45
+ # none cast
46
+ if source is None:
47
+ raise Exception("source is None")
48
+
49
+ raw = InitialStateApiUtilsRaw(
50
+ initial_state=json.loads(source.group(1)),
51
+ meta_data=json.loads(source.group(2)),
52
+ )
53
+
54
+ def get_user(e: dict[str, Any]) -> Optional[models.UserLegacy]:
55
+ try:
56
+ entities = e["entities"]["users"]["entities"]
57
+ return models.UserLegacy.model_validate(list(entities.values())[0])
58
+ except Exception:
59
+ # todo: fix
60
+ return None
61
+
62
+ def get_session(e: dict[str, Any]) -> Optional[models.Session]:
63
+ try:
64
+ return models.Session.model_validate(e["session"])
65
+ except Exception:
66
+ return None
67
+
68
+ return InitialStateApiUtilsResponse(
69
+ raw=raw,
70
+ user=get_user(raw.initial_state),
71
+ session=get_session(raw.initial_state),
72
+ )