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.
- twitter_openapi_python/__init__.py +15 -15
- twitter_openapi_python/api/__init__.py +13 -13
- twitter_openapi_python/api/default_api.py +80 -80
- twitter_openapi_python/api/initial_state_api.py +72 -72
- twitter_openapi_python/api/post_api.py +166 -166
- twitter_openapi_python/api/tweet_api.py +428 -353
- twitter_openapi_python/api/user_api.py +80 -80
- twitter_openapi_python/api/user_list_api.py +171 -171
- twitter_openapi_python/api/users_api.py +56 -56
- twitter_openapi_python/api/v11_get_api.py +67 -70
- twitter_openapi_python/api/v11_post_api.py +61 -66
- twitter_openapi_python/client.py +194 -194
- twitter_openapi_python/models/__init__.py +22 -22
- twitter_openapi_python/models/base.py +9 -9
- twitter_openapi_python/models/header.py +20 -20
- twitter_openapi_python/models/initial_state.py +17 -17
- twitter_openapi_python/models/response.py +19 -19
- twitter_openapi_python/models/timeline.py +40 -40
- twitter_openapi_python/tid.py +27 -17
- twitter_openapi_python/utils/__init__.py +22 -22
- twitter_openapi_python/utils/api.py +288 -288
- {twitter_openapi_python-0.0.44.dist-info → twitter_openapi_python-0.1.0.dist-info}/METADATA +118 -117
- twitter_openapi_python-0.1.0.dist-info/RECORD +27 -0
- {twitter_openapi_python-0.0.44.dist-info → twitter_openapi_python-0.1.0.dist-info}/WHEEL +1 -2
- {twitter_openapi_python-0.0.44.dist-info → twitter_openapi_python-0.1.0.dist-info}/licenses/LICENSE +31 -31
- {twitter_openapi_python-0.0.44.dist-info → twitter_openapi_python-0.1.0.dist-info}/licenses/LICENSE.AGPL +660 -660
- twitter_openapi_python-0.0.44.dist-info/RECORD +0 -28
- twitter_openapi_python-0.0.44.dist-info/top_level.txt +0 -1
|
@@ -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 TwitterApiUtilsResponse, UserApiUtilsData
|
|
8
|
-
from twitter_openapi_python.utils import (
|
|
9
|
-
build_response,
|
|
10
|
-
error_check,
|
|
11
|
-
get_kwargs,
|
|
12
|
-
user_or_null_converter,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
T = TypeVar("T")
|
|
16
|
-
ResponseType = TwitterApiUtilsResponse[UserApiUtilsData]
|
|
17
|
-
ApiFnType = Callable[..., twitter.ApiResponse[T]]
|
|
18
|
-
ParamType = dict[str, Any]
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class UserApiUtils:
|
|
22
|
-
api: twitter.UserApi
|
|
23
|
-
flag: ParamType
|
|
24
|
-
|
|
25
|
-
def __init__(self, api: twitter.UserApi, 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[T]",
|
|
33
|
-
convertFn: Callable[[T], models.UserResults],
|
|
34
|
-
key: str,
|
|
35
|
-
param: ParamType,
|
|
36
|
-
) -> ResponseType:
|
|
37
|
-
args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
|
|
38
|
-
res = apiFn(**args)
|
|
39
|
-
result = convertFn(res.data)
|
|
40
|
-
if result.result is None:
|
|
41
|
-
raise Exception("No user")
|
|
42
|
-
user = user_or_null_converter(result.result)
|
|
43
|
-
if user is None:
|
|
44
|
-
raise Exception("No user")
|
|
45
|
-
data = UserApiUtilsData(
|
|
46
|
-
raw=result,
|
|
47
|
-
user=user,
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
return build_response(response=res, data=data)
|
|
51
|
-
|
|
52
|
-
def get_user_by_screen_name(
|
|
53
|
-
self,
|
|
54
|
-
screen_name: str,
|
|
55
|
-
extra_param: Optional[ParamType] = None,
|
|
56
|
-
) -> ResponseType:
|
|
57
|
-
param: ParamType = {"screen_name": screen_name}
|
|
58
|
-
if extra_param is not None:
|
|
59
|
-
param.update(extra_param)
|
|
60
|
-
return self.request(
|
|
61
|
-
apiFn=self.api.get_user_by_screen_name_with_http_info,
|
|
62
|
-
convertFn=lambda e: error_check(e.data.user, e.errors),
|
|
63
|
-
key="UserByScreenName",
|
|
64
|
-
param=param,
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
def get_user_by_rest_id(
|
|
68
|
-
self,
|
|
69
|
-
user_id: str,
|
|
70
|
-
extra_param: Optional[ParamType] = None,
|
|
71
|
-
) -> ResponseType:
|
|
72
|
-
param: ParamType = {"userId": user_id}
|
|
73
|
-
if extra_param is not None:
|
|
74
|
-
param.update(extra_param)
|
|
75
|
-
return self.request(
|
|
76
|
-
apiFn=self.api.get_user_by_rest_id_with_http_info,
|
|
77
|
-
convertFn=lambda e: error_check(e.data.user, e.errors),
|
|
78
|
-
key="UserByRestId",
|
|
79
|
-
param=param,
|
|
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 TwitterApiUtilsResponse, UserApiUtilsData
|
|
8
|
+
from twitter_openapi_python.utils import (
|
|
9
|
+
build_response,
|
|
10
|
+
error_check,
|
|
11
|
+
get_kwargs,
|
|
12
|
+
user_or_null_converter,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
T = TypeVar("T")
|
|
16
|
+
ResponseType = TwitterApiUtilsResponse[UserApiUtilsData]
|
|
17
|
+
ApiFnType = Callable[..., twitter.ApiResponse[T]]
|
|
18
|
+
ParamType = dict[str, Any]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class UserApiUtils:
|
|
22
|
+
api: twitter.UserApi
|
|
23
|
+
flag: ParamType
|
|
24
|
+
|
|
25
|
+
def __init__(self, api: twitter.UserApi, 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[T]",
|
|
33
|
+
convertFn: Callable[[T], models.UserResults],
|
|
34
|
+
key: str,
|
|
35
|
+
param: ParamType,
|
|
36
|
+
) -> ResponseType:
|
|
37
|
+
args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
|
|
38
|
+
res = apiFn(**args)
|
|
39
|
+
result = convertFn(res.data)
|
|
40
|
+
if result.result is None:
|
|
41
|
+
raise Exception("No user")
|
|
42
|
+
user = user_or_null_converter(result.result)
|
|
43
|
+
if user is None:
|
|
44
|
+
raise Exception("No user")
|
|
45
|
+
data = UserApiUtilsData(
|
|
46
|
+
raw=result,
|
|
47
|
+
user=user,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
return build_response(response=res, data=data)
|
|
51
|
+
|
|
52
|
+
def get_user_by_screen_name(
|
|
53
|
+
self,
|
|
54
|
+
screen_name: str,
|
|
55
|
+
extra_param: Optional[ParamType] = None,
|
|
56
|
+
) -> ResponseType:
|
|
57
|
+
param: ParamType = {"screen_name": screen_name}
|
|
58
|
+
if extra_param is not None:
|
|
59
|
+
param.update(extra_param)
|
|
60
|
+
return self.request(
|
|
61
|
+
apiFn=self.api.get_user_by_screen_name_with_http_info,
|
|
62
|
+
convertFn=lambda e: error_check(e.data.user, e.errors),
|
|
63
|
+
key="UserByScreenName",
|
|
64
|
+
param=param,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
def get_user_by_rest_id(
|
|
68
|
+
self,
|
|
69
|
+
user_id: str,
|
|
70
|
+
extra_param: Optional[ParamType] = None,
|
|
71
|
+
) -> ResponseType:
|
|
72
|
+
param: ParamType = {"userId": user_id}
|
|
73
|
+
if extra_param is not None:
|
|
74
|
+
param.update(extra_param)
|
|
75
|
+
return self.request(
|
|
76
|
+
apiFn=self.api.get_user_by_rest_id_with_http_info,
|
|
77
|
+
convertFn=lambda e: error_check(e.data.user, e.errors),
|
|
78
|
+
key="UserByRestId",
|
|
79
|
+
param=param,
|
|
80
|
+
)
|
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
from typing import Any, Callable, List, 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 (
|
|
8
|
-
ApiUtilsRaw,
|
|
9
|
-
TimelineApiUtilsResponse,
|
|
10
|
-
TwitterApiUtilsResponse,
|
|
11
|
-
UserApiUtilsData,
|
|
12
|
-
)
|
|
13
|
-
from twitter_openapi_python.utils import (
|
|
14
|
-
build_response,
|
|
15
|
-
entries_cursor,
|
|
16
|
-
error_check,
|
|
17
|
-
get_kwargs,
|
|
18
|
-
instruction_to_entry,
|
|
19
|
-
user_entries_converter,
|
|
20
|
-
user_result_converter,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
T = TypeVar("T")
|
|
24
|
-
ResponseType = TwitterApiUtilsResponse[TimelineApiUtilsResponse[UserApiUtilsData]]
|
|
25
|
-
ApiFnType = Callable[..., twitter.ApiResponse[T]]
|
|
26
|
-
ParamType = dict[str, Any]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class UserListApiUtils:
|
|
30
|
-
api: twitter.UserListApi
|
|
31
|
-
flag: ParamType
|
|
32
|
-
|
|
33
|
-
def __init__(self, api: twitter.UserListApi, flag: ParamType, ct: ClientTransaction):
|
|
34
|
-
self.api = api
|
|
35
|
-
self.flag = flag
|
|
36
|
-
self.ct = ct
|
|
37
|
-
|
|
38
|
-
def request(
|
|
39
|
-
self,
|
|
40
|
-
apiFn: "ApiFnType[T]",
|
|
41
|
-
convertFn: Callable[[T], List[models.InstructionUnion]],
|
|
42
|
-
key: str,
|
|
43
|
-
param: ParamType,
|
|
44
|
-
) -> ResponseType:
|
|
45
|
-
args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
|
|
46
|
-
res = apiFn(**args)
|
|
47
|
-
instruction = convertFn(res.data)
|
|
48
|
-
entry = instruction_to_entry(instruction)
|
|
49
|
-
user_list = user_entries_converter(entry)
|
|
50
|
-
user = user_result_converter(user_list)
|
|
51
|
-
|
|
52
|
-
raw = ApiUtilsRaw(
|
|
53
|
-
instruction=instruction,
|
|
54
|
-
entry=entry,
|
|
55
|
-
)
|
|
56
|
-
data = TimelineApiUtilsResponse[UserApiUtilsData](
|
|
57
|
-
raw=raw,
|
|
58
|
-
cursor=entries_cursor(entry),
|
|
59
|
-
data=user,
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
return build_response(response=res, data=data)
|
|
63
|
-
|
|
64
|
-
def get_followers(
|
|
65
|
-
self,
|
|
66
|
-
user_id: str,
|
|
67
|
-
cursor: Optional[str] = None,
|
|
68
|
-
count: Optional[int] = None,
|
|
69
|
-
extra_param: Optional[ParamType] = None,
|
|
70
|
-
) -> ResponseType:
|
|
71
|
-
param: ParamType = {"userId": user_id}
|
|
72
|
-
if cursor is not None:
|
|
73
|
-
param["cursor"] = cursor
|
|
74
|
-
if count is not None:
|
|
75
|
-
param["count"] = count
|
|
76
|
-
if extra_param is not None:
|
|
77
|
-
param.update(extra_param)
|
|
78
|
-
return self.request(
|
|
79
|
-
apiFn=self.api.get_followers_with_http_info,
|
|
80
|
-
convertFn=lambda e: error_check(e.data.user, e.errors).result.timeline.timeline.instructions,
|
|
81
|
-
key="Followers",
|
|
82
|
-
param=param,
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
def get_following(
|
|
86
|
-
self,
|
|
87
|
-
user_id: str,
|
|
88
|
-
cursor: Optional[str] = None,
|
|
89
|
-
count: Optional[int] = None,
|
|
90
|
-
extra_param: Optional[ParamType] = None,
|
|
91
|
-
) -> ResponseType:
|
|
92
|
-
param: ParamType = {"userId": user_id}
|
|
93
|
-
if cursor is not None:
|
|
94
|
-
param["cursor"] = cursor
|
|
95
|
-
if count is not None:
|
|
96
|
-
param["count"] = count
|
|
97
|
-
if extra_param is not None:
|
|
98
|
-
param.update(extra_param)
|
|
99
|
-
return self.request(
|
|
100
|
-
apiFn=self.api.get_following_with_http_info,
|
|
101
|
-
convertFn=lambda e: error_check(e.data.user, e.errors).result.timeline.timeline.instructions,
|
|
102
|
-
key="Following",
|
|
103
|
-
param=param,
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
def get_followers_you_know(
|
|
107
|
-
self,
|
|
108
|
-
user_id: str,
|
|
109
|
-
cursor: Optional[str] = None,
|
|
110
|
-
count: Optional[int] = None,
|
|
111
|
-
extra_param: Optional[ParamType] = None,
|
|
112
|
-
) -> ResponseType:
|
|
113
|
-
param: ParamType = {"userId": user_id}
|
|
114
|
-
if cursor is not None:
|
|
115
|
-
param["cursor"] = cursor
|
|
116
|
-
if count is not None:
|
|
117
|
-
param["count"] = count
|
|
118
|
-
if extra_param is not None:
|
|
119
|
-
param.update(extra_param)
|
|
120
|
-
return self.request(
|
|
121
|
-
apiFn=self.api.get_followers_you_know_with_http_info,
|
|
122
|
-
convertFn=lambda e: error_check(e.data.user, e.errors).result.timeline.timeline.instructions,
|
|
123
|
-
key="FollowersYouKnow",
|
|
124
|
-
param=param,
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
def get_favoriters(
|
|
128
|
-
self,
|
|
129
|
-
tweet_id: str,
|
|
130
|
-
cursor: Optional[str] = None,
|
|
131
|
-
count: Optional[int] = None,
|
|
132
|
-
extra_param: Optional[ParamType] = None,
|
|
133
|
-
) -> ResponseType:
|
|
134
|
-
param: ParamType = {"tweetId": tweet_id}
|
|
135
|
-
if cursor is not None:
|
|
136
|
-
param["cursor"] = cursor
|
|
137
|
-
if count is not None:
|
|
138
|
-
param["count"] = count
|
|
139
|
-
if extra_param is not None:
|
|
140
|
-
param.update(extra_param)
|
|
141
|
-
return self.request(
|
|
142
|
-
apiFn=self.api.get_favoriters_with_http_info,
|
|
143
|
-
convertFn=lambda e: error_check(
|
|
144
|
-
error_check(e.data.favoriters_timeline, e.errors).timeline, e.errors
|
|
145
|
-
).instructions,
|
|
146
|
-
key="Favoriters",
|
|
147
|
-
param=param,
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
def get_retweeters(
|
|
151
|
-
self,
|
|
152
|
-
tweet_id: str,
|
|
153
|
-
cursor: Optional[str] = None,
|
|
154
|
-
count: Optional[int] = None,
|
|
155
|
-
extra_param: Optional[ParamType] = None,
|
|
156
|
-
) -> ResponseType:
|
|
157
|
-
param: ParamType = {"tweetId": tweet_id}
|
|
158
|
-
if cursor is not None:
|
|
159
|
-
param["cursor"] = cursor
|
|
160
|
-
if count is not None:
|
|
161
|
-
param["count"] = count
|
|
162
|
-
if extra_param is not None:
|
|
163
|
-
param.update(extra_param)
|
|
164
|
-
return self.request(
|
|
165
|
-
apiFn=self.api.get_retweeters_with_http_info,
|
|
166
|
-
convertFn=lambda e: error_check(
|
|
167
|
-
error_check(e.data.retweeters_timeline, e.errors).timeline, e.errors
|
|
168
|
-
).instructions,
|
|
169
|
-
key="Retweeters",
|
|
170
|
-
param=param,
|
|
171
|
-
)
|
|
1
|
+
from typing import Any, Callable, List, 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 (
|
|
8
|
+
ApiUtilsRaw,
|
|
9
|
+
TimelineApiUtilsResponse,
|
|
10
|
+
TwitterApiUtilsResponse,
|
|
11
|
+
UserApiUtilsData,
|
|
12
|
+
)
|
|
13
|
+
from twitter_openapi_python.utils import (
|
|
14
|
+
build_response,
|
|
15
|
+
entries_cursor,
|
|
16
|
+
error_check,
|
|
17
|
+
get_kwargs,
|
|
18
|
+
instruction_to_entry,
|
|
19
|
+
user_entries_converter,
|
|
20
|
+
user_result_converter,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
T = TypeVar("T")
|
|
24
|
+
ResponseType = TwitterApiUtilsResponse[TimelineApiUtilsResponse[UserApiUtilsData]]
|
|
25
|
+
ApiFnType = Callable[..., twitter.ApiResponse[T]]
|
|
26
|
+
ParamType = dict[str, Any]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class UserListApiUtils:
|
|
30
|
+
api: twitter.UserListApi
|
|
31
|
+
flag: ParamType
|
|
32
|
+
|
|
33
|
+
def __init__(self, api: twitter.UserListApi, flag: ParamType, ct: ClientTransaction):
|
|
34
|
+
self.api = api
|
|
35
|
+
self.flag = flag
|
|
36
|
+
self.ct = ct
|
|
37
|
+
|
|
38
|
+
def request(
|
|
39
|
+
self,
|
|
40
|
+
apiFn: "ApiFnType[T]",
|
|
41
|
+
convertFn: Callable[[T], List[models.InstructionUnion]],
|
|
42
|
+
key: str,
|
|
43
|
+
param: ParamType,
|
|
44
|
+
) -> ResponseType:
|
|
45
|
+
args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
|
|
46
|
+
res = apiFn(**args)
|
|
47
|
+
instruction = convertFn(res.data)
|
|
48
|
+
entry = instruction_to_entry(instruction)
|
|
49
|
+
user_list = user_entries_converter(entry)
|
|
50
|
+
user = user_result_converter(user_list)
|
|
51
|
+
|
|
52
|
+
raw = ApiUtilsRaw(
|
|
53
|
+
instruction=instruction,
|
|
54
|
+
entry=entry,
|
|
55
|
+
)
|
|
56
|
+
data = TimelineApiUtilsResponse[UserApiUtilsData](
|
|
57
|
+
raw=raw,
|
|
58
|
+
cursor=entries_cursor(entry),
|
|
59
|
+
data=user,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
return build_response(response=res, data=data)
|
|
63
|
+
|
|
64
|
+
def get_followers(
|
|
65
|
+
self,
|
|
66
|
+
user_id: str,
|
|
67
|
+
cursor: Optional[str] = None,
|
|
68
|
+
count: Optional[int] = None,
|
|
69
|
+
extra_param: Optional[ParamType] = None,
|
|
70
|
+
) -> ResponseType:
|
|
71
|
+
param: ParamType = {"userId": user_id}
|
|
72
|
+
if cursor is not None:
|
|
73
|
+
param["cursor"] = cursor
|
|
74
|
+
if count is not None:
|
|
75
|
+
param["count"] = count
|
|
76
|
+
if extra_param is not None:
|
|
77
|
+
param.update(extra_param)
|
|
78
|
+
return self.request(
|
|
79
|
+
apiFn=self.api.get_followers_with_http_info,
|
|
80
|
+
convertFn=lambda e: error_check(e.data.user, e.errors).result.timeline.timeline.instructions,
|
|
81
|
+
key="Followers",
|
|
82
|
+
param=param,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
def get_following(
|
|
86
|
+
self,
|
|
87
|
+
user_id: str,
|
|
88
|
+
cursor: Optional[str] = None,
|
|
89
|
+
count: Optional[int] = None,
|
|
90
|
+
extra_param: Optional[ParamType] = None,
|
|
91
|
+
) -> ResponseType:
|
|
92
|
+
param: ParamType = {"userId": user_id}
|
|
93
|
+
if cursor is not None:
|
|
94
|
+
param["cursor"] = cursor
|
|
95
|
+
if count is not None:
|
|
96
|
+
param["count"] = count
|
|
97
|
+
if extra_param is not None:
|
|
98
|
+
param.update(extra_param)
|
|
99
|
+
return self.request(
|
|
100
|
+
apiFn=self.api.get_following_with_http_info,
|
|
101
|
+
convertFn=lambda e: error_check(e.data.user, e.errors).result.timeline.timeline.instructions,
|
|
102
|
+
key="Following",
|
|
103
|
+
param=param,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def get_followers_you_know(
|
|
107
|
+
self,
|
|
108
|
+
user_id: str,
|
|
109
|
+
cursor: Optional[str] = None,
|
|
110
|
+
count: Optional[int] = None,
|
|
111
|
+
extra_param: Optional[ParamType] = None,
|
|
112
|
+
) -> ResponseType:
|
|
113
|
+
param: ParamType = {"userId": user_id}
|
|
114
|
+
if cursor is not None:
|
|
115
|
+
param["cursor"] = cursor
|
|
116
|
+
if count is not None:
|
|
117
|
+
param["count"] = count
|
|
118
|
+
if extra_param is not None:
|
|
119
|
+
param.update(extra_param)
|
|
120
|
+
return self.request(
|
|
121
|
+
apiFn=self.api.get_followers_you_know_with_http_info,
|
|
122
|
+
convertFn=lambda e: error_check(e.data.user, e.errors).result.timeline.timeline.instructions,
|
|
123
|
+
key="FollowersYouKnow",
|
|
124
|
+
param=param,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
def get_favoriters(
|
|
128
|
+
self,
|
|
129
|
+
tweet_id: str,
|
|
130
|
+
cursor: Optional[str] = None,
|
|
131
|
+
count: Optional[int] = None,
|
|
132
|
+
extra_param: Optional[ParamType] = None,
|
|
133
|
+
) -> ResponseType:
|
|
134
|
+
param: ParamType = {"tweetId": tweet_id}
|
|
135
|
+
if cursor is not None:
|
|
136
|
+
param["cursor"] = cursor
|
|
137
|
+
if count is not None:
|
|
138
|
+
param["count"] = count
|
|
139
|
+
if extra_param is not None:
|
|
140
|
+
param.update(extra_param)
|
|
141
|
+
return self.request(
|
|
142
|
+
apiFn=self.api.get_favoriters_with_http_info,
|
|
143
|
+
convertFn=lambda e: error_check(
|
|
144
|
+
error_check(e.data.favoriters_timeline, e.errors).timeline, e.errors
|
|
145
|
+
).instructions,
|
|
146
|
+
key="Favoriters",
|
|
147
|
+
param=param,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
def get_retweeters(
|
|
151
|
+
self,
|
|
152
|
+
tweet_id: str,
|
|
153
|
+
cursor: Optional[str] = None,
|
|
154
|
+
count: Optional[int] = None,
|
|
155
|
+
extra_param: Optional[ParamType] = None,
|
|
156
|
+
) -> ResponseType:
|
|
157
|
+
param: ParamType = {"tweetId": tweet_id}
|
|
158
|
+
if cursor is not None:
|
|
159
|
+
param["cursor"] = cursor
|
|
160
|
+
if count is not None:
|
|
161
|
+
param["count"] = count
|
|
162
|
+
if extra_param is not None:
|
|
163
|
+
param.update(extra_param)
|
|
164
|
+
return self.request(
|
|
165
|
+
apiFn=self.api.get_retweeters_with_http_info,
|
|
166
|
+
convertFn=lambda e: error_check(
|
|
167
|
+
error_check(e.data.retweeters_timeline, e.errors).timeline, e.errors
|
|
168
|
+
).instructions,
|
|
169
|
+
key="Retweeters",
|
|
170
|
+
param=param,
|
|
171
|
+
)
|
|
@@ -1,56 +1,56 @@
|
|
|
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 TwitterApiUtilsResponse, UserApiUtilsData
|
|
8
|
-
from twitter_openapi_python.utils import (
|
|
9
|
-
build_response,
|
|
10
|
-
error_check,
|
|
11
|
-
get_kwargs,
|
|
12
|
-
user_result_converter,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
T = TypeVar("T")
|
|
16
|
-
ResponseType = TwitterApiUtilsResponse[list[UserApiUtilsData]]
|
|
17
|
-
ApiFnType = Callable[..., twitter.ApiResponse[T]]
|
|
18
|
-
ParamType = dict[str, Any]
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class UsersApiUtils:
|
|
22
|
-
api: twitter.UsersApi
|
|
23
|
-
flag: ParamType
|
|
24
|
-
|
|
25
|
-
def __init__(self, api: twitter.UsersApi, 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[T]",
|
|
33
|
-
convertFn: Callable[[T], list[models.UserResults]],
|
|
34
|
-
key: str,
|
|
35
|
-
param: ParamType,
|
|
36
|
-
) -> ResponseType:
|
|
37
|
-
args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
|
|
38
|
-
res = apiFn(**args)
|
|
39
|
-
user_result = convertFn(res.data)
|
|
40
|
-
user = user_result_converter(user_result)
|
|
41
|
-
return build_response(response=res, data=user)
|
|
42
|
-
|
|
43
|
-
def get_users_by_rest_ids(
|
|
44
|
-
self,
|
|
45
|
-
user_ids: list[str],
|
|
46
|
-
extra_param: Optional[ParamType] = None,
|
|
47
|
-
) -> ResponseType:
|
|
48
|
-
param: ParamType = {"userIds": user_ids}
|
|
49
|
-
if extra_param is not None:
|
|
50
|
-
param.update(extra_param)
|
|
51
|
-
return self.request(
|
|
52
|
-
apiFn=self.api.get_users_by_rest_ids_with_http_info,
|
|
53
|
-
convertFn=lambda e: error_check(e.data.users, e.errors),
|
|
54
|
-
key="UsersByRestIds",
|
|
55
|
-
param=param,
|
|
56
|
-
)
|
|
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 TwitterApiUtilsResponse, UserApiUtilsData
|
|
8
|
+
from twitter_openapi_python.utils import (
|
|
9
|
+
build_response,
|
|
10
|
+
error_check,
|
|
11
|
+
get_kwargs,
|
|
12
|
+
user_result_converter,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
T = TypeVar("T")
|
|
16
|
+
ResponseType = TwitterApiUtilsResponse[list[UserApiUtilsData]]
|
|
17
|
+
ApiFnType = Callable[..., twitter.ApiResponse[T]]
|
|
18
|
+
ParamType = dict[str, Any]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class UsersApiUtils:
|
|
22
|
+
api: twitter.UsersApi
|
|
23
|
+
flag: ParamType
|
|
24
|
+
|
|
25
|
+
def __init__(self, api: twitter.UsersApi, 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[T]",
|
|
33
|
+
convertFn: Callable[[T], list[models.UserResults]],
|
|
34
|
+
key: str,
|
|
35
|
+
param: ParamType,
|
|
36
|
+
) -> ResponseType:
|
|
37
|
+
args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
|
|
38
|
+
res = apiFn(**args)
|
|
39
|
+
user_result = convertFn(res.data)
|
|
40
|
+
user = user_result_converter(user_result)
|
|
41
|
+
return build_response(response=res, data=user)
|
|
42
|
+
|
|
43
|
+
def get_users_by_rest_ids(
|
|
44
|
+
self,
|
|
45
|
+
user_ids: list[str],
|
|
46
|
+
extra_param: Optional[ParamType] = None,
|
|
47
|
+
) -> ResponseType:
|
|
48
|
+
param: ParamType = {"userIds": user_ids}
|
|
49
|
+
if extra_param is not None:
|
|
50
|
+
param.update(extra_param)
|
|
51
|
+
return self.request(
|
|
52
|
+
apiFn=self.api.get_users_by_rest_ids_with_http_info,
|
|
53
|
+
convertFn=lambda e: error_check(e.data.users, e.errors),
|
|
54
|
+
key="UsersByRestIds",
|
|
55
|
+
param=param,
|
|
56
|
+
)
|