From 0cdeaff407078b31b51cdec08c3fe18e5e892b71 Mon Sep 17 00:00:00 2001 From: sujan Date: Fri, 9 Aug 2024 10:23:51 +0545 Subject: [PATCH] feat: created a function to get submission photo by its submission id --- osm_fieldwork/OdkCentral.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/osm_fieldwork/OdkCentral.py b/osm_fieldwork/OdkCentral.py index b3c30aa5..362c71de 100755 --- a/osm_fieldwork/OdkCentral.py +++ b/osm_fieldwork/OdkCentral.py @@ -805,6 +805,33 @@ def getSubmissionMedia( url = self.base + f"projects/{projectId}/forms/{xform}/submissions.csv.zip" result = self.session.get(url, verify=self.verify) return result + + def getSubmissionPhoto( + self, + projectId: int, + instanceID: str, + xform: str, + filename: str, + ): + """Fetch a specific attachment by filename from a submission to a form. + + Args: + projectId (int): The ID of the project on ODK Central + instanceID(str): The ID of the submission on ODK Central + xform (str): The XForm to get the details of from ODK Central + filename (str): The name of the attachment for the XForm on ODK Central + + Returns: + (bytes): The media data + """ + url = f"{self.base}projects/{projectId}/forms/{xform}/submissions/{instanceID}/attachments/{filename}" + result = self.session.get(url, verify=self.verify) + if result.status_code == 200: + log.debug(f"fetched {filename} from Central") + else: + status = eval(result._content) + log.error(f"Couldn't fetch {filename} from Central: {status['message']}") + return result.content def addMedia( self,