Skip to content

Commit

Permalink
fix tests and linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
prratek committed Feb 28, 2022
1 parent 7fd81d5 commit 0d38dae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
43 changes: 33 additions & 10 deletions tap_instagram/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ class MediaStream(InstagramStream):

def make_since_param(self, context: Optional[dict]) -> datetime:
state_ts = self.get_starting_timestamp(context)
return pendulum.instance(state_ts).subtract(days=self.config["media_insights_lookback_days"])
if state_ts:
return pendulum.instance(state_ts).subtract(
days=self.config["media_insights_lookback_days"]
)
else:
return state_ts

def get_url_params(
self, context: Optional[dict], next_page_token: Optional[Any]
Expand All @@ -210,7 +215,9 @@ def get_child_context(self, record: dict, context: Optional[dict]) -> dict:
def parse_response(self, response: requests.Response) -> Iterable[dict]:
for row in extract_jsonpath(self.records_jsonpath, input=response.json()):
if "timestamp" in row:
row["timestamp"] = pendulum.parse(row["timestamp"]).format("YYYY-MM-DD HH:mm:ss")
row["timestamp"] = pendulum.parse(row["timestamp"]).format(
"YYYY-MM-DD HH:mm:ss"
)
yield row


Expand Down Expand Up @@ -361,7 +368,9 @@ def get_child_context(self, record: dict, context: Optional[dict]) -> dict:
def parse_response(self, response: requests.Response) -> Iterable[dict]:
for row in extract_jsonpath(self.records_jsonpath, input=response.json()):
if "timestamp" in row:
row["timestamp"] = pendulum.parse(row["timestamp"]).format("YYYY-MM-DD HH:mm:ss")
row["timestamp"] = pendulum.parse(row["timestamp"]).format(
"YYYY-MM-DD HH:mm:ss"
)
yield row


Expand Down Expand Up @@ -392,7 +401,9 @@ class MediaChildrenStream(MediaStream):
def parse_response(self, response: requests.Response) -> Iterable[dict]:
for row in extract_jsonpath(self.records_jsonpath, input=response.json()):
if "timestamp" in row:
row["timestamp"] = pendulum.parse(row["timestamp"]).format("YYYY-MM-DD HH:mm:ss")
row["timestamp"] = pendulum.parse(row["timestamp"]).format(
"YYYY-MM-DD HH:mm:ss"
)
yield row


Expand Down Expand Up @@ -528,14 +539,18 @@ 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"),
"end_time": pendulum.parse(values["end_time"]).format(
"YYYY-MM-DD HH:mm:ss"
),
}
item.update(base_item)
yield item
else:
values.update(base_item)
if "end_time" in values:
values["end_time"] = pendulum.parse(values["end_time"]).format("YYYY-MM-DD HH:mm:ss")
values["end_time"] = pendulum.parse(
values["end_time"]
).format("YYYY-MM-DD HH:mm:ss")
yield values


Expand Down Expand Up @@ -687,14 +702,18 @@ 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"),
"end_time": pendulum.parse(values["end_time"]).format(
"YYYY-MM-DD HH:mm:ss"
),
}
item.update(base_item)
yield item
else:
values.update(base_item)
if "end_time" in values:
values["end_time"] = pendulum.parse(values["end_time"]).format("YYYY-MM-DD HH:mm:ss")
values["end_time"] = pendulum.parse(
values["end_time"]
).format("YYYY-MM-DD HH:mm:ss")
yield values


Expand Down Expand Up @@ -827,14 +846,18 @@ 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"),
"end_time": pendulum.parse(values["end_time"]).format(
"YYYY-MM-DD HH:mm:ss"
),
}
item.update(base_item)
yield item
else:
values.update(base_item)
if "end_time" in values:
values["end_time"] = pendulum.parse(values["end_time"]).format("YYYY-MM-DD HH:mm:ss")
values["end_time"] = pendulum.parse(
values["end_time"]
).format("YYYY-MM-DD HH:mm:ss")
yield values


Expand Down
2 changes: 1 addition & 1 deletion tap_instagram/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TapInstagram(Tap):
th.IntegerType,
default=60,
description="The tap fetches media insights for Media objects posted in the last `insights_lookback_days` "
"days - defaults to 14 days if not provided"
"days - defaults to 14 days if not provided",
),
th.Property(
"start_date",
Expand Down

0 comments on commit 0d38dae

Please sign in to comment.