Skip to content

Commit

Permalink
Merge pull request #2 from ganpatagarwal/reporting-days-v3
Browse files Browse the repository at this point in the history
Reporting days v3
  • Loading branch information
ganpatagarwal authored Apr 6, 2023
2 parents 7d7e8e7 + b484187 commit 59020c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class SponsoredProductsReportStreamV3(ReportStream):
ad_product = "SPONSORED_PRODUCTS"
report_is_created = HTTPStatus.OK
metrics_map = METRICS_MAP
REPORTING_PERIOD = 95

def report_init_endpoint(self, record_type: str) -> str:
return f"/{self.API_VERSION}/reports"
Expand Down Expand Up @@ -390,7 +391,7 @@ def _get_init_report_body(self, report_date: str, record_type: str, profile):
]
}
]

elif record_type == "searchTerm":
group_by = ["searchTerm"]
reportTypeId = "spSearchTerm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,16 @@ def get_start_date(self, profile: Profile, stream_state: Mapping[str, Any]) -> D
return max(self._start_date, today.subtract(days=self.REPORTING_PERIOD))
return today

def get_end_date(self, profile: Profile) -> Date:
def get_end_date(self, profile: Profile, start_date: Date) -> Date:
today = pendulum.today(tz=profile.timezone).date()
if self._end_date:
return min(self._end_date, today)
return min(max(self._end_date, start_date), today)

return today

def stream_profile_slices(self, profile: Profile, stream_state: Mapping[str, Any]) -> Iterable[Mapping[str, Any]]:
start_date = self.get_start_date(profile, stream_state)
for report_date in self.get_date_range(start_date, self.get_end_date(profile)):
for report_date in self.get_date_range(start_date, self.get_end_date(profile, start_date)):
yield {"profile": profile, self.cursor_field: report_date}

def stream_slices(
Expand Down

0 comments on commit 59020c4

Please sign in to comment.