Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split out streams for 'lifetime' time periods #15

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions tap_instagram/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,6 @@ def parse_response(self, response: requests.Response) -> Iterable[dict]:
class UserInsightsStream(InstagramStream):
parent_stream_type = UsersStream
path = "/{user_id}/insights" # user_id is populated using child context keys from UsersStream
primary_keys = ["id"]
replication_key = "end_time"
records_jsonpath = "$.data[*]"
has_pagination = True
Expand Down Expand Up @@ -848,10 +847,11 @@ def parse_response(self, response: requests.Response) -> Iterable[dict]:
item = {
"context": key,
"value": value,
"end_time": pendulum.parse(values["end_time"]).format(
"YYYY-MM-DD HH:mm:ss"
),
}
if "end_time" in values:
item["end_time"] = pendulum.parse(values["end_time"]).format(
"YYYY-MM-DD HH:mm:ss"
)
item.update(base_item)
yield item
else:
Expand All @@ -863,6 +863,11 @@ def parse_response(self, response: requests.Response) -> Iterable[dict]:
yield values


class UserInsightsPeriodStream(UserInsightsStream):
time_period: str # must define in the subclass
primary_keys = ['id', 'end_time']


class UserInsightsOnlineFollowersStream(UserInsightsStream):
"""Define custom stream."""

Expand All @@ -884,9 +889,10 @@ class UserInsightsAudienceStream(UserInsightsStream):
]
time_period = "lifetime"
has_pagination = False
replication_method = 'FULL_TABLE'


class UserInsightsFollowersStream(UserInsightsStream):
class UserInsightsFollowersStream(UserInsightsPeriodStream):
"""Define custom stream."""

name = "user_insights_followers"
Expand All @@ -895,7 +901,7 @@ class UserInsightsFollowersStream(UserInsightsStream):
min_start_date = pendulum.now("UTC").subtract(days=30)


class UserInsightsDailyStream(UserInsightsStream):
class UserInsightsDailyStream(UserInsightsPeriodStream):
"""Define custom stream."""

name = "user_insights_daily"
Expand All @@ -912,7 +918,7 @@ class UserInsightsDailyStream(UserInsightsStream):
time_period = "day"


class UserInsightsWeeklyStream(UserInsightsStream):
class UserInsightsWeeklyStream(UserInsightsPeriodStream):
"""Define custom stream."""

name = "user_insights_weekly"
Expand All @@ -923,7 +929,7 @@ class UserInsightsWeeklyStream(UserInsightsStream):
time_period = "week"


class UserInsights28DayStream(UserInsightsStream):
class UserInsights28DayStream(UserInsightsPeriodStream):
"""Define custom stream."""

name = "user_insights_28day"
Expand Down