arcade-x 0.1.5__py3-none-any.whl → 0.1.6__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.
- arcade_x/tools/tweets.py +22 -5
- arcade_x/tools/utils.py +14 -1
- {arcade_x-0.1.5.dist-info → arcade_x-0.1.6.dist-info}/METADATA +2 -2
- arcade_x-0.1.6.dist-info/RECORD +9 -0
- arcade_x-0.1.5.dist-info/RECORD +0 -9
- {arcade_x-0.1.5.dist-info → arcade_x-0.1.6.dist-info}/LICENSE +0 -0
- {arcade_x-0.1.5.dist-info → arcade_x-0.1.6.dist-info}/WHEEL +0 -0
arcade_x/tools/tweets.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Annotated, Any
|
|
1
|
+
from typing import Annotated, Any, Optional
|
|
2
2
|
|
|
3
3
|
import httpx
|
|
4
4
|
from arcade.sdk import ToolContext, tool
|
|
@@ -10,6 +10,7 @@ from arcade_x.tools.utils import (
|
|
|
10
10
|
get_headers_with_token,
|
|
11
11
|
get_tweet_url,
|
|
12
12
|
parse_search_recent_tweets_response,
|
|
13
|
+
remove_none_values,
|
|
13
14
|
)
|
|
14
15
|
|
|
15
16
|
TWEETS_URL = "https://api.x.com/2/tweets"
|
|
@@ -63,8 +64,11 @@ async def search_recent_tweets_by_username(
|
|
|
63
64
|
context: ToolContext,
|
|
64
65
|
username: Annotated[str, "The username of the X (Twitter) user to look up"],
|
|
65
66
|
max_results: Annotated[
|
|
66
|
-
int, "The maximum number of results to return.
|
|
67
|
+
int, "The maximum number of results to return. Must be in range [1, 100] inclusive"
|
|
67
68
|
] = 10,
|
|
69
|
+
next_token: Annotated[
|
|
70
|
+
Optional[str], "The pagination token starting from which to return results"
|
|
71
|
+
] = None,
|
|
68
72
|
) -> Annotated[dict[str, Any], "Dictionary containing the search results"]:
|
|
69
73
|
"""Search for recent tweets (last 7 days) on X (Twitter) by username.
|
|
70
74
|
Includes replies and reposts."""
|
|
@@ -72,8 +76,13 @@ async def search_recent_tweets_by_username(
|
|
|
72
76
|
headers = get_headers_with_token(context)
|
|
73
77
|
params: dict[str, int | str] = {
|
|
74
78
|
"query": f"from:{username}",
|
|
75
|
-
"max_results":
|
|
79
|
+
"max_results": min(
|
|
80
|
+
max(max_results, 10), 100
|
|
81
|
+
), # X API does not allow 'max_results' less than 10 or greater than 100
|
|
82
|
+
"next_token": next_token,
|
|
76
83
|
}
|
|
84
|
+
params = remove_none_values(params)
|
|
85
|
+
|
|
77
86
|
url = (
|
|
78
87
|
"https://api.x.com/2/tweets/search/recent?"
|
|
79
88
|
"expansions=author_id&user.fields=id,name,username,entities&tweet.fields=entities"
|
|
@@ -106,8 +115,11 @@ async def search_recent_tweets_by_keywords(
|
|
|
106
115
|
list[str] | None, "List of phrases that must be present in the tweet"
|
|
107
116
|
] = None,
|
|
108
117
|
max_results: Annotated[
|
|
109
|
-
int, "The maximum number of results to return.
|
|
118
|
+
int, "The maximum number of results to return. Must be in range [1, 100] inclusive"
|
|
110
119
|
] = 10,
|
|
120
|
+
next_token: Annotated[
|
|
121
|
+
Optional[str], "The pagination token starting from which to return results"
|
|
122
|
+
] = None,
|
|
111
123
|
) -> Annotated[dict[str, Any], "Dictionary containing the search results"]:
|
|
112
124
|
"""
|
|
113
125
|
Search for recent tweets (last 7 days) on X (Twitter) by required keywords and phrases.
|
|
@@ -131,8 +143,13 @@ async def search_recent_tweets_by_keywords(
|
|
|
131
143
|
|
|
132
144
|
params: dict[str, int | str] = {
|
|
133
145
|
"query": query.strip(),
|
|
134
|
-
"max_results":
|
|
146
|
+
"max_results": min(
|
|
147
|
+
max(max_results, 10), 100
|
|
148
|
+
), # X API does not allow 'max_results' less than 10 or greater than 100
|
|
149
|
+
"next_token": next_token,
|
|
135
150
|
}
|
|
151
|
+
params = remove_none_values(params)
|
|
152
|
+
|
|
136
153
|
url = (
|
|
137
154
|
"https://api.x.com/2/tweets/search/recent?"
|
|
138
155
|
"expansions=author_id&user.fields=id,name,username,entities&tweet.fields=entities"
|
arcade_x/tools/utils.py
CHANGED
|
@@ -28,7 +28,7 @@ def parse_search_recent_tweets_response(response_data: dict[str, Any]) -> dict[s
|
|
|
28
28
|
Returns the modified response data with added 'tweet_url', 'author_username', and 'author_name'.
|
|
29
29
|
"""
|
|
30
30
|
if not sanity_check_tweets_data(response_data):
|
|
31
|
-
return {"data": []}
|
|
31
|
+
return {"data": [], "next_token": ""}
|
|
32
32
|
|
|
33
33
|
# Add 'tweet_url' to each tweet
|
|
34
34
|
for tweet in response_data["data"]:
|
|
@@ -110,3 +110,16 @@ def expand_urls_in_user_url(user_data: dict, delete_entities: bool = True) -> di
|
|
|
110
110
|
if delete_entities:
|
|
111
111
|
new_user_data.pop("entities", None)
|
|
112
112
|
return new_user_data
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def remove_none_values(params: dict) -> dict:
|
|
116
|
+
"""
|
|
117
|
+
Remove key/value pairs with None values from a dictionary.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
params: The dictionary to clean
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
A new dictionary with None values removed
|
|
124
|
+
"""
|
|
125
|
+
return {k: v for k, v in params.items() if v is not None}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: arcade_x
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: LLM tools for interacting with X (Twitter)
|
|
5
5
|
Author: Arcade AI
|
|
6
6
|
Author-email: dev@arcade-ai.com
|
|
@@ -10,5 +10,5 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.11
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.12
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
-
Requires-Dist: arcade-ai (==0.1.
|
|
13
|
+
Requires-Dist: arcade-ai (==0.1.6)
|
|
14
14
|
Requires-Dist: httpx (>=0.27.2,<0.28.0)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
arcade_x/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
arcade_x/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
arcade_x/tools/tweets.py,sha256=VchdglDVI15rsEyZuBLIj6qjGql0-UO8TdY6ylGl4yA,7158
|
|
4
|
+
arcade_x/tools/users.py,sha256=zNACU9UhQJkGNnrei-E6GWvFnbDzg0YG9pkdplu8TzM,2148
|
|
5
|
+
arcade_x/tools/utils.py,sha256=YKRGXcUPKcPnIvmiNF2-0jB4edxFmFZLJ90OQNR-DGk,4366
|
|
6
|
+
arcade_x-0.1.6.dist-info/LICENSE,sha256=SphQPbiNmBD1J6yJ7oxG9bIZDbj8lNHKSv5Kl86zA40,1066
|
|
7
|
+
arcade_x-0.1.6.dist-info/METADATA,sha256=5eq4z7KaY2GSDY8J-KLUDRdibTsCsHpt29AgW7qlSac,510
|
|
8
|
+
arcade_x-0.1.6.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
9
|
+
arcade_x-0.1.6.dist-info/RECORD,,
|
arcade_x-0.1.5.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
arcade_x/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
arcade_x/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
arcade_x/tools/tweets.py,sha256=IDAjx1j_XLoc7ILyuRKVyjTPwQeNtD47lnyKUMO-WpU,6594
|
|
4
|
-
arcade_x/tools/users.py,sha256=zNACU9UhQJkGNnrei-E6GWvFnbDzg0YG9pkdplu8TzM,2148
|
|
5
|
-
arcade_x/tools/utils.py,sha256=VEeUo715m6l6X9Syszy2E72rdvv4h_tc-P7wMaQEbGo,4044
|
|
6
|
-
arcade_x-0.1.5.dist-info/LICENSE,sha256=SphQPbiNmBD1J6yJ7oxG9bIZDbj8lNHKSv5Kl86zA40,1066
|
|
7
|
-
arcade_x-0.1.5.dist-info/METADATA,sha256=pa4GiYU352AShVYdd2rDjVa3AP5b1sFtJpi1gUihQmM,510
|
|
8
|
-
arcade_x-0.1.5.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
9
|
-
arcade_x-0.1.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|