Skip to content

Commit 035439e

Browse files
committed
twitter_tags: adding tags_frequent_extractions parameter
1 parent 2d99f81 commit 035439e

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

source-twitter-fetcher/source_twitter_fetcher/source.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
3838
if "start_time" in config:
3939
tags_kwargs["start_time"] = datetime.strptime(config['start_time'], DATE_FORMAT)
4040

41+
# Add tags_frequent_extractions if provided in config
42+
if "tags_frequent_extractions" in config:
43+
tags_kwargs["tags_frequent_extractions"] = config["tags_frequent_extractions"]
44+
4145
tags = TagsStream(**tags_kwargs)
4246

4347
tweet_metrics = TweetMetrics(

source-twitter-fetcher/source_twitter_fetcher/spec.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ connectionSpecification:
5050
description: "List of Twitter handles to monitor (e.g., ['@IFT', '@Airbyte'])"
5151
items:
5252
type: string
53-
minItems: 1
53+
minItems: 1
54+
tags_frequent_extractions:
55+
type: boolean
56+
title: "Tags Frequent Extractions"
57+
description: "If true, defaults start_time to 1 hour 15 minutes before current time for more frequent extractions. If false, defaults to 5 days before current time."
58+
default: false

source-twitter-fetcher/source_twitter_fetcher/tags_stream.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ class TagsStream(HttpStream):
1212
url_base = "https://api.x.com/2/"
1313
primary_key = "id"
1414

15-
def __init__(self, start_time: str = None, account_id: str = None, tags: List[str] = None, **kwargs):
15+
def __init__(self, start_time: str = None, account_id: str = None, tags: List[str] = None, tags_frequent_extractions: bool = False, **kwargs):
1616
super().__init__(**kwargs)
1717

18-
# If start_time is provided, parse it; otherwise default to 5 days ago
18+
# If start_time is provided, parse it; otherwise default based on tags_frequent_extractions
1919
if start_time:
2020
self.start_time = start_time if isinstance(start_time, datetime) else datetime.strptime(start_time, "%Y-%m-%dT%H:%M:%SZ")
2121
else:
22-
# Default to 5 days before current time
23-
self.start_time = datetime.utcnow() - timedelta(days=5)
22+
if tags_frequent_extractions:
23+
# Default to 1 hour 15 minutes before current time
24+
self.start_time = datetime.utcnow() - timedelta(hours=1, minutes=15)
25+
else:
26+
# Default to 5 days before current time
27+
self.start_time = datetime.utcnow() - timedelta(days=5)
2428

2529
self.account_id = account_id
2630
self.tags = tags or []

0 commit comments

Comments
 (0)