Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions twitter_openapi_python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "twitter_openapi_python"
version = "0.0.35"
version = "0.0.37"
description = "Twitter OpenAPI"
authors = ["fa0311 <yuki@yuki0311.com>"]
license = "proprietary" # or "AGPL-3.0-only"
Expand All @@ -15,7 +15,7 @@ python = "^3.7"
pydantic = ">=2.6"
urllib3 = ">= 2.1.0 < 3.0.0"

twitter-openapi-python-generated = "0.0.31"
twitter-openapi-python-generated = "0.0.33"

[tool.poetry.dev-dependencies]

Expand Down
Binary file modified twitter_openapi_python/requirements.txt
Binary file not shown.
8 changes: 2 additions & 6 deletions twitter_openapi_python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
from setuptools import find_packages, setup

NAME = "twitter_openapi_python"
VERSION = "0.0.35"
VERSION = "0.0.37"
PYTHON_REQUIRES = ">=3.7"
REQUIRES = [
"twitter_openapi_python_generated == 0.0.31",
"pydantic >= 2.6",
"urllib3 >= 2.1.0, < 3.0.0"
]
REQUIRES = ["twitter_openapi_python_generated == 0.0.33", "pydantic >= 2.6", "urllib3 >= 2.1.0, < 3.0.0"]
GITHUB_RAW_URL = (
"https://raw.githubusercontent.com/fa0311/twitter_openapi_python/refs/heads/master/twitter_openapi_python/"
)
Expand Down
10 changes: 10 additions & 0 deletions twitter_openapi_python/test/api/test_1_tweet_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ def test_get_bookmarks(self):
for tweet in list(filter(self.ad_fillter, result.data.data)):
print_tweet(tweet)

def test_get_community_tweets_timeline(self):
result = self.client.get_community_tweets_timeline()
for tweet in list(filter(self.ad_fillter, result.data.data)):
print_tweet(tweet)

def test_get_community_media_timeline(self):
result = self.client.get_community_media_timeline()
for tweet in list(filter(self.ad_fillter, result.data.data)):
print_tweet(tweet)


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import twitter_openapi_python_generated as twitter
import twitter_openapi_python_generated.models as models
from x_client_transaction import ClientTransaction

from twitter_openapi_python.models import TweetApiUtilsData, TwitterApiUtilsResponse
from twitter_openapi_python.utils import (
Expand All @@ -21,9 +22,10 @@ class DefaultApiUtils:
api: twitter.DefaultApi
flag: ParamType

def __init__(self, api: twitter.DefaultApi, flag: ParamType):
def __init__(self, api: twitter.DefaultApi, flag: ParamType, ct: ClientTransaction):
self.api = api
self.flag = flag
self.ct = ct

def request(
self,
Expand All @@ -32,7 +34,7 @@ def request(
key: str,
param: ParamType,
):
args = get_kwargs(flag=self.flag[key], additional=param)
args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
res = apiFn(**args)
data = convertFn(res.data)
return build_response(res, data)
Expand Down
11 changes: 10 additions & 1 deletion twitter_openapi_python/twitter_openapi_python/api/post_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import twitter_openapi_python_generated as twitter
import twitter_openapi_python_generated.models as models
from x_client_transaction import ClientTransaction

from twitter_openapi_python.models import TwitterApiUtilsResponse
from twitter_openapi_python.utils import build_response, non_nullable
from twitter_openapi_python.utils.api import get_headers

T = TypeVar("T")
ResponseType = TwitterApiUtilsResponse[T]
Expand All @@ -15,9 +17,10 @@ class PostApiUtils:
api: twitter.PostApi
flag: ParamType

def __init__(self, api: twitter.PostApi, flag: ParamType):
def __init__(self, api: twitter.PostApi, flag: ParamType, ct: ClientTransaction):
self.api = api
self.flag = flag
self.ct = ct

def post_create_tweet(
self,
Expand Down Expand Up @@ -61,6 +64,7 @@ def post_create_tweet(
variables=variables,
features=features,
),
_headers=get_headers(self.flag["CreateTweet"], self.ct),
)
return build_response(res, res.data)

Expand All @@ -79,6 +83,7 @@ def post_delete_tweet(
queryId=self.flag["DeleteTweet"]["queryId"],
variables=variables,
),
_headers=get_headers(self.flag["DeleteTweet"], self.ct),
)
return build_response(res, res.data)

Expand All @@ -97,6 +102,7 @@ def post_create_retweet(
queryId=self.flag["CreateRetweet"]["queryId"],
variables=variables,
),
_headers=get_headers(self.flag["CreateRetweet"], self.ct),
)
return build_response(res, res.data)

Expand All @@ -115,6 +121,7 @@ def post_delete_retweet(
queryId=self.flag["DeleteRetweet"]["queryId"],
variables=variables,
),
_headers=get_headers(self.flag["DeleteRetweet"], self.ct),
)
return build_response(res, res.data)

Expand All @@ -134,6 +141,7 @@ def post_favorite_tweet(
queryId=self.flag["FavoriteTweet"]["queryId"],
variables=variables,
),
_headers=get_headers(self.flag["FavoriteTweet"], self.ct),
)
return build_response(res, res.data)

Expand All @@ -153,5 +161,6 @@ def post_unfavorite_tweet(
queryId=self.flag["UnfavoriteTweet"]["queryId"],
variables=variables,
),
_headers=get_headers(self.flag["UnfavoriteTweet"], self.ct),
)
return build_response(res, res.data)
69 changes: 61 additions & 8 deletions twitter_openapi_python/twitter_openapi_python/api/tweet_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Any, Callable, List, Optional, TypeVar
from typing import Any, Callable, List, Literal, Optional, TypeVar

import twitter_openapi_python_generated as twitter
import twitter_openapi_python_generated.models as models
from x_client_transaction import ClientTransaction

from twitter_openapi_python.models import (
ApiUtilsRaw,
Expand All @@ -28,9 +29,10 @@ class TweetApiUtils:
api: twitter.TweetApi
flag: ParamType

def __init__(self, api: twitter.TweetApi, flag: ParamType):
def __init__(self, api: twitter.TweetApi, flag: ParamType, ct: ClientTransaction):
self.api = api
self.flag = flag
self.ct = ct

def request(
self,
Expand All @@ -39,7 +41,7 @@ def request(
key: str,
param: ParamType,
) -> ResponseType:
args = get_kwargs(flag=self.flag[key], additional=param)
args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
res = apiFn(**args)
instruction = convertFn(res.data)
entry = instruction_to_entry(instruction)
Expand Down Expand Up @@ -81,7 +83,7 @@ def get_tweet_detail(
def get_search_timeline(
self,
raw_query: str,
product: Optional[str] = None,
product: Optional[Literal["Top", "Latest", "People", "Photos", "Videos"]] = None,
cursor: Optional[str] = None,
count: Optional[int] = None,
extra_param: Optional[ParamType] = None,
Expand Down Expand Up @@ -191,7 +193,7 @@ def get_user_tweets(
response = self.request(
apiFn=self.api.get_user_tweets_with_http_info,
convertFn=lambda e: error_check(
error_check(e.data.user, e.errors).result.timeline_v2.timeline, e.errors
error_check(e.data.user, e.errors).result.timeline.timeline, e.errors
).instructions,
key="UserTweets",
param=param,
Expand All @@ -216,7 +218,7 @@ def get_user_tweets_and_replies(
response = self.request(
apiFn=self.api.get_user_tweets_and_replies_with_http_info,
convertFn=lambda e: error_check(
error_check(e.data.user, e.errors).result.timeline_v2.timeline, e.errors
error_check(e.data.user, e.errors).result.timeline.timeline, e.errors
).instructions,
key="UserTweetsAndReplies",
param=param,
Expand All @@ -241,7 +243,7 @@ def get_user_media(
response = self.request(
apiFn=self.api.get_user_media_with_http_info,
convertFn=lambda e: error_check(
error_check(e.data.user, e.errors).result.timeline_v2.timeline, e.errors
error_check(e.data.user, e.errors).result.timeline.timeline, e.errors
).instructions,
key="UserMedia",
param=param,
Expand All @@ -266,7 +268,7 @@ def get_likes(
response = self.request(
apiFn=self.api.get_likes_with_http_info,
convertFn=lambda e: error_check(
error_check(e.data.user, e.errors).result.timeline_v2.timeline, e.errors
error_check(e.data.user, e.errors).result.timeline.timeline, e.errors
).instructions,
key="Likes",
param=param,
Expand Down Expand Up @@ -296,3 +298,54 @@ def get_bookmarks(
param=param,
)
return response

def get_community_tweets_timeline(
self,
cursor: Optional[str] = None,
count: Optional[int] = None,
rankingMode: Optional[Literal["Recency", "Relevance"]] = None,
extra_param: Optional[ParamType] = None,
) -> ResponseType:
param: ParamType = {}
if cursor is not None:
param["cursor"] = cursor
if count is not None:
param["count"] = count
if rankingMode is not None:
param["rankingMode"] = rankingMode
if extra_param is not None:
param.update(extra_param)

response = self.request(
apiFn=self.api.get_community_tweets_timeline_with_http_info,
convertFn=lambda e: error_check(
error_check(e.data, e.errors).community_results.result.ranked_community_timeline.timeline, e.errors
).instructions,
key="CommunityTweetsTimeline",
param=param,
)
return response

def get_community_media_timeline(
self,
cursor: Optional[str] = None,
count: Optional[int] = None,
extra_param: Optional[ParamType] = None,
) -> ResponseType:
param: ParamType = {}
if cursor is not None:
param["cursor"] = cursor
if count is not None:
param["count"] = count
if extra_param is not None:
param.update(extra_param)

response = self.request(
apiFn=self.api.get_community_media_timeline_with_http_info,
convertFn=lambda e: error_check(
error_check(e.data, e.errors).community_results.result.community_media_timeline.timeline, e.errors
).instructions,
key="CommunityMediaTimeline",
param=param,
)
return response
6 changes: 4 additions & 2 deletions twitter_openapi_python/twitter_openapi_python/api/user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import twitter_openapi_python_generated as twitter
import twitter_openapi_python_generated.models as models
from x_client_transaction import ClientTransaction

from twitter_openapi_python.models import TwitterApiUtilsResponse, UserApiUtilsData
from twitter_openapi_python.utils import (
Expand All @@ -21,9 +22,10 @@ class UserApiUtils:
api: twitter.UserApi
flag: ParamType

def __init__(self, api: twitter.UserApi, flag: ParamType):
def __init__(self, api: twitter.UserApi, flag: ParamType, ct: ClientTransaction):
self.api = api
self.flag = flag
self.ct = ct

def request(
self,
Expand All @@ -32,7 +34,7 @@ def request(
key: str,
param: ParamType,
) -> ResponseType:
args = get_kwargs(flag=self.flag[key], additional=param)
args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
res = apiFn(**args)
result = convertFn(res.data)
if result.result is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import twitter_openapi_python_generated as twitter
import twitter_openapi_python_generated.models as models
from x_client_transaction import ClientTransaction

from twitter_openapi_python.models import (
ApiUtilsRaw,
Expand Down Expand Up @@ -29,9 +30,10 @@ class UserListApiUtils:
api: twitter.UserListApi
flag: ParamType

def __init__(self, api: twitter.UserListApi, flag: ParamType):
def __init__(self, api: twitter.UserListApi, flag: ParamType, ct: ClientTransaction):
self.api = api
self.flag = flag
self.ct = ct

def request(
self,
Expand All @@ -40,7 +42,7 @@ def request(
key: str,
param: ParamType,
) -> ResponseType:
args = get_kwargs(flag=self.flag[key], additional=param)
args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
res = apiFn(**args)
instruction = convertFn(res.data)
entry = instruction_to_entry(instruction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import twitter_openapi_python_generated as twitter
import twitter_openapi_python_generated.models as models
from x_client_transaction import ClientTransaction

from twitter_openapi_python.models import TwitterApiUtilsResponse, UserApiUtilsData
from twitter_openapi_python.utils import (
Expand All @@ -21,9 +22,10 @@ class UsersApiUtils:
api: twitter.UsersApi
flag: ParamType

def __init__(self, api: twitter.UsersApi, flag: ParamType):
def __init__(self, api: twitter.UsersApi, flag: ParamType, ct: ClientTransaction):
self.api = api
self.flag = flag
self.ct = ct

def request(
self,
Expand All @@ -32,7 +34,7 @@ def request(
key: str,
param: ParamType,
) -> ResponseType:
args = get_kwargs(flag=self.flag[key], additional=param)
args = get_kwargs(flag=self.flag[key], additional=param, ct=self.ct)
res = apiFn(**args)
user_result = convertFn(res.data)
user = user_result_converter(user_result)
Expand Down
Loading