twitter: adding account endpoint

Signed-off-by: Alexis Pentori <alexis@status.im>
This commit is contained in:
Alexis Pentori 2024-10-21 11:04:24 +02:00
parent 2c77efd487
commit 4985ffcd40
No known key found for this signature in database
GPG Key ID: 65250D2801E47A10
3 changed files with 88 additions and 4 deletions

View File

@ -1,5 +1,19 @@
{
"streams": [
{
"stream": {
"name": "account",
"json_schema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object"
},
"supported_sync_modes": [
"full_refresh", "incremental"
]
},
"sync_mode": "incremental",
"destination_sync_mode": "overwrite"
},
{
"stream": {
"name": "tweet",
@ -8,10 +22,10 @@
"type": "object"
},
"supported_sync_modes": [
"full_refresh", "incremental"
"full_refresh", "incremental"
]
},
"sync_mode": "incremental",
"sync_mode": "incremental",
"destination_sync_mode": "overwrite"
},
{
@ -22,10 +36,10 @@
"type": "object"
},
"supported_sync_modes": [
"full_refresh", "incremental"
"full_refresh", "incremental"
]
},
"sync_mode": "incremental",
"sync_mode": "incremental",
"destination_sync_mode": "overwrite"
}
]

View File

@ -0,0 +1,50 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"id": {
"type": [ "null", "string" ]
},
"name": {
"type": [ "null", "string" ]
},
"username": {
"type": [ "null", "string" ]
},
"description": {
"type": [ "null", "string" ]
},
"most_recent_tweet_id": {
"type": [ "null", "string" ]
},
"pinned_tweet_id": {
"type": [ "null", "string" ]
},
"protected": {
"type": [ "null", "bool" ]
},
"verified_type": {
"type": [ "null", "string" ]
},
"public_metrics": {
"type": ["null", "object" ],
"properties": {
"tweet_count": {
"type": [ "null", "number" ]
},
"like_count": {
"type": [ "null", "number" ]
},
"following_count": {
"type": [ "null", "number" ]
},
"follower_count": {
"type": [ "null", "number" ]
},
"listed_count": {
"type": [ "null", "number" ]
}
}
}
}
}

View File

@ -39,6 +39,25 @@ class TwitterStream(HttpStream):
if delay_time:
return int(delay_time)
class Account(TwitterStream):
primary_key= "id"
def path(
self, stream_state: Mapping[str, Any] = None,
stream_slice: Mapping[str, Any] = None,
next_page_token: Mapping[str, Any] = None) -> str:
return f"users/me?user.fields=public_metrics,protected,description,url,most_recent_tweet_id,pinned_tweet_id,created_at,verified_type"
def parse_response(
self,
response: requests.Response,
stream_slice: Mapping[str, Any] = None,
**kwargs
) -> Iterable[Mapping]:
logger.debug("Response: %s", response.json())
data=response.json()['data']
yield data
class Tweet(TwitterStream):
primary_key = "id"
@ -144,6 +163,7 @@ class SourceTwitterFetcher(AbstractSource):
parent=tweet
)
return [
Account(authenticator=auth, account_id=config["account_id"]),
tweet,
tweetMetrics
]