From 173cc6994ea27ec9124ae29a5fe37801e3a92f1f Mon Sep 17 00:00:00 2001 From: Mateo Torres Date: Fri, 18 Jul 2025 18:20:06 -0300 Subject: [PATCH] bugfix: URL expansion in Twitter (#500) This solves an edge case where the `"url"` entity does not have an `"expanded_url"` case when expanding. The behavior for now is simply don't replace the URL as it seems the display_url is NOT what we want to keep as it's normally abbreviated --------- Co-authored-by: Eric Gustin <34000337+EricGustin@users.noreply.github.com> --- toolkits/x/arcade_x/tools/utils.py | 7 ++++--- toolkits/x/pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/toolkits/x/arcade_x/tools/utils.py b/toolkits/x/arcade_x/tools/utils.py index 8545b95e..086fbcb4 100644 --- a/toolkits/x/arcade_x/tools/utils.py +++ b/toolkits/x/arcade_x/tools/utils.py @@ -82,9 +82,10 @@ def expand_urls_in_tweets( new_tweet = tweet_data.copy() if "entities" in new_tweet and "urls" in new_tweet["entities"]: for url_entity in new_tweet["entities"]["urls"]: - short_url = url_entity["url"] - expanded_url = url_entity["expanded_url"] - new_tweet["text"] = new_tweet["text"].replace(short_url, expanded_url) + if "url" in url_entity and "expanded_url" in url_entity: + short_url = url_entity["url"] + expanded_url = url_entity["expanded_url"] + new_tweet["text"] = new_tweet["text"].replace(short_url, expanded_url) if delete_entities: new_tweet.pop("entities", None) diff --git a/toolkits/x/pyproject.toml b/toolkits/x/pyproject.toml index a835d278..c04652ae 100644 --- a/toolkits/x/pyproject.toml +++ b/toolkits/x/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "arcade_x" -version = "0.1.15" +version = "0.1.16" description = "Arcade.dev LLM tools for X (Twitter)" requires-python = ">=3.10" dependencies = [ "arcade-tdk>=2.0.0,<3.0.0", "httpx>=0.27.2,<1.0.0",]