Skip to content

Commit

Permalink
state getter and setter for incremental-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit Chatterjee committed May 27, 2024
1 parent 274b132 commit 4dcc137
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,16 @@ class IncrementalStream(CommcareStream, IncrementalMixin):

@property
def state(self) -> Mapping[str, Any]:
if self._cursor_value:
return {self.cursor_field: self._cursor_value}
return {self.cursor_field: self._cursor_value}

@state.setter
def state(self, value: Mapping[str, Any]):
self._cursor_value = datetime.strptime(value[self.cursor_field], self.dateformat)
if self.cursor_field in value:
if "Z" in value[self.cursor_field]:
date_format = "%Y-%m-%dT%H:%M:%S.%fZ"
else:
date_format = "%Y-%m-%dT%H:%M:%S.%f"
self._cursor_value = datetime.strptime(value[self.cursor_field], date_format)

@property
def sync_mode(self):
Expand Down Expand Up @@ -140,7 +144,6 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp


class Case(IncrementalStream):

"""
docs: https://www.commcarehq.org/a/[domain]/api/[version]/case/
"""
Expand Down

0 comments on commit 4dcc137

Please sign in to comment.