Skip to content

Commit

Permalink
Pagination fix for the duplicates. (#16)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Hassan Syyid <[email protected]>
  • Loading branch information
xacadil and hsyyid authored Apr 18, 2024
1 parent 97c0e29 commit 9ee7063
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions tap_restaurant365/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ def get_next_page_token(
previous_token = previous_token['token']
return {"token":previous_token,"skip":self.skip}
else:
self.skip = 0
start_date = (parser.parse(self.tap_state["bookmarks"][self.name]['starting_replication_value']) + timedelta(seconds=1)) or parser.parse(self.config.get("start_date"))
self.skip = 0
#Pick starting value just incase progress marker is not present.
replication_key_value = self.tap_state["bookmarks"][self.name]['starting_replication_value']
if "progress_markers" in self.tap_state["bookmarks"][self.name]:
replication_key_value = self.tap_state["bookmarks"][self.name]['progress_markers']["replication_key_value"]

start_date = (parser.parse(replication_key_value) + timedelta(seconds=1)) or parser.parse(self.config.get("start_date"))
today = datetime.today()
if previous_token:
if "token" in previous_token:
previous_token = previous_token['token']
if previous_token:
#Look for records that are greater than the previous token
previous_token = previous_token + timedelta(seconds=1)
previous_token = previous_token or start_date
next_token = (previous_token + timedelta(days=self.days_delta)).replace(tzinfo=None)
next_token = start_date.replace(tzinfo=None)

if (today - next_token).days < self.days_delta:
self.paginate = False
Expand All @@ -64,7 +62,10 @@ def get_url_params(
start_date = token_date or self.get_starting_time(context)
end_date = start_date + timedelta(days = self.days_delta)
if self.replication_key:
params["$filter"] = f"{self.replication_key} ge {start_date.strftime('%Y-%m-%dT%H:%M:%SZ')} and {self.replication_key} lt {end_date.strftime('%Y-%m-%dT%H:%M:%SZ')}"
params["$filter"] = (
f"{self.replication_key} ge {start_date.strftime('%Y-%m-%dT%H:%M:%SZ')} and {self.replication_key} lt {end_date.strftime('%Y-%m-%dT23:59:59Z')}"
)
params['$orderby'] = f"{self.replication_key}"
if self.name == "journal_entries":
#set a date in the stream to check later to see if we need to keep calling to the stream
params["$filter"] += f" and type eq 'Journal Entry'"
Expand Down

0 comments on commit 9ee7063

Please sign in to comment.