On the last few PRs I have noticed two problems: 1. `ruff format` fails even though it seems OK on our local machines (sometimes, not always) 2. Nate's and Sam's machines kept flip-flopping a specific piece of formatting back and forth, indicating a subtle difference of config hiding somewhere 3. This was reproducible by running `ruff format` in the terminal, followed by `make check`. The former would edit files, and then `make check` would edit them back! This PR addresses both issues, and further standardizes our editor & linter configs to be super stable. Specifically: 1. The main fix for the above, the pre-commit hook was pinned to a super old version of ruff. This resulted in subtle differences in behavior between our machines, and on CI. 2. Moved ruff settings from `pyproject.toml` to `.ruff.toml` pyproject files in subdirectories (e.g. `toolkits/**`) were overriding the main pyproject file and erasing the custom ruff config we set at the root. This meant that our ruff config was applied to `arcade` but not to any of the other packages. By moving the config to `.ruff.toml` at the root, all projects will inherit the same ruff linting & formatting config. 4. Un-ignored the `.vscode/` directory so that we can share vscode/cursor workspace settings. This is valuable for standardizing settings like the default formatter (ruff) and default test framework (pytest). However, it's important that going forward we _only_ commit things here that should apply across all of our machines. 5. To avoid any conflict between prettier and ruff, prettier now explicitly ignores *.py files 6. Finally, `ruff format` and `make check` agree. A number of files are newly auto-formatted.
57 lines
2 KiB
Python
57 lines
2 KiB
Python
from typing import Annotated
|
|
|
|
import requests
|
|
|
|
from arcade.core.errors import ToolExecutionError
|
|
from arcade.core.schema import ToolContext
|
|
from arcade.sdk import tool
|
|
from arcade.sdk.auth import X
|
|
|
|
|
|
# Users Lookup Tools. See developer docs for additional available query parameters: https://developer.x.com/en/docs/x-api/users/lookup/api-reference
|
|
@tool(requires_auth=X(scopes=["users.read", "tweet.read"]))
|
|
def lookup_single_user_by_username(
|
|
context: ToolContext,
|
|
username: Annotated[str, "The username of the X (Twitter) user to look up"],
|
|
) -> Annotated[str, "User information including id, name, username, and description"]:
|
|
"""Look up a user on X (Twitter) by their username."""
|
|
|
|
headers = {
|
|
"Authorization": f"Bearer {context.authorization.token}",
|
|
}
|
|
url = f"https://api.x.com/2/users/by/username/{username}?user.fields=created_at,description,id,location,most_recent_tweet_id,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,verified_type,withheld"
|
|
|
|
response = requests.get(url, headers=headers)
|
|
|
|
if response.status_code != 200:
|
|
raise ToolExecutionError(
|
|
f"Failed to look up user during execution of '{lookup_single_user_by_username.__name__}' tool. Request returned an error: {response.status_code} {response.text}"
|
|
)
|
|
|
|
"""
|
|
Example response.text structure:
|
|
{
|
|
"data": {
|
|
"verified_type": str,
|
|
"public_metrics": {
|
|
"followers_count": int,
|
|
"following_count": int,
|
|
"tweet_count": int,
|
|
"listed_count": int,
|
|
"like_count": int
|
|
},
|
|
"id": str,
|
|
"most_recent_tweet_id": str,
|
|
"url": str,
|
|
"verified": bool,
|
|
"location": str,
|
|
"description": str,
|
|
"name": str,
|
|
"username": str,
|
|
"profile_image_url": str,
|
|
"created_at": str,
|
|
"protected": bool
|
|
}
|
|
}
|
|
"""
|
|
return response.text
|