From 36555d0c236c853d1a6aa0960938537bc4a198b1 Mon Sep 17 00:00:00 2001 From: Alexis Pentori Date: Tue, 16 Apr 2024 15:55:57 +0200 Subject: [PATCH] twitter: adding promoted_metrics to the API call Signed-off-by: Alexis Pentori --- source-twitter-fetcher/metadata.yaml | 2 +- .../source_twitter_fetcher/schemas/tweet.json | 73 ++++++++++++------- .../source_twitter_fetcher/source.py | 2 +- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/source-twitter-fetcher/metadata.yaml b/source-twitter-fetcher/metadata.yaml index 2164538..b113a22 100644 --- a/source-twitter-fetcher/metadata.yaml +++ b/source-twitter-fetcher/metadata.yaml @@ -10,7 +10,7 @@ data: connectorSubtype: api connectorType: source definitionId: 1c448bfb-8950-478c-9ae0-f03aaaf4e920 - dockerImageTag: '0.2.0' + dockerImageTag: '0.2.1' dockerRepository: status-im/airbyte/source-twitter-fetcher githubIssueLabel: source-twitter-fetcher icon: twitter-fetcher.svg diff --git a/source-twitter-fetcher/source_twitter_fetcher/schemas/tweet.json b/source-twitter-fetcher/source_twitter_fetcher/schemas/tweet.json index 9548fb6..514a15f 100644 --- a/source-twitter-fetcher/source_twitter_fetcher/schemas/tweet.json +++ b/source-twitter-fetcher/source_twitter_fetcher/schemas/tweet.json @@ -3,57 +3,57 @@ "type": "object", "properties": { "id": { - "type": [ "null", "string"] + "type": ["null", "string"] }, "text": { - "type": [ "null", "string"] + "type": ["null", "string"] }, "created_at": { - "type": [ "null", "string"] + "type": ["null", "string"] }, "author_id": { - "type": [ "null", "string"] + "type": ["null", "string"] }, "conversation_id": { - "type": [ "null", "string"] + "type": ["null", "string"] }, "reply_settings": { - "type": ["null", "string"] + "type": ["null", "string"] }, "referenced_tweets": { - "type": [ "null", "array" ], + "type": ["null", "array"], "items": { "type": ["object"], "properties":{ "type": { - "type": [ "null", "string" ] + "type": ["null", "string"] }, "id": { - "type": [ "null", "number" ] + "type": ["null", "number"] } } } }, "public_metrics": { - "type": ["null", "object" ], + "type": ["null", "object"], "properties": { "retweet_count": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "reply_count": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "like_count": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "quote_count": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "impression_count": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "bookmark_count": { - "type": [ "null", "number" ] + "type": ["null", "number"] } } }, @@ -61,13 +61,36 @@ "type": ["null", "object" ], "properties": { "impression_count": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "url_link_clicks": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "user_profile_clicks": { - "type": [ "null", "number" ] + "type": ["null", "number"] + } + } + }, + "non_public_metrics": { + "type": ["null", "object" ], + "properties": { + "impression_count": { + "type": ["null", "number"] + }, + "like_count": { + "type": ["null", "number"] + }, + "reply_count": { + "type": ["null", "number"] + }, + "retweet_count": { + "type": ["null", "number"] + }, + "url_link_clicks": { + "type": ["null", "number"] + }, + "user_profile_clicks": { + "type": ["null", "number"] } } }, @@ -75,22 +98,22 @@ "type": ["null", "object" ], "properties": { "impression_count": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "url_link_clicks": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "user_profile_clicks": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "retweet_count": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "reply_count": { - "type": [ "null", "number" ] + "type": ["null", "number"] }, "like_count": { - "type": [ "null", "number" ] + "type": ["null", "number"] } } } diff --git a/source-twitter-fetcher/source_twitter_fetcher/source.py b/source-twitter-fetcher/source_twitter_fetcher/source.py index ef71a08..fae55f4 100644 --- a/source-twitter-fetcher/source_twitter_fetcher/source.py +++ b/source-twitter-fetcher/source_twitter_fetcher/source.py @@ -71,7 +71,7 @@ class Tweet(HttpSubStream, Account): ) -> str: account_id = stream_slice.get("parent").get("id") logger.info("Account id %s", account_id) - return f"users/{account_id}/tweets?tweet.fields=text,public_metrics,non_public_metrics,organic_metrics,author_id,referenced_tweets,created_at" + return f"users/{account_id}/tweets?tweet.fields=text,public_metrics,non_public_metrics,organic_metrics,author_id,referenced_tweets,promoted_metrics,created_at" def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]: logger.debug("Twtter Response: %s", response.json())