Skip to content

Commit 7c16572

Browse files
author
Rodion Yaryy
committed
Add Export issues to SDK
1 parent 0b6edd5 commit 7c16572

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

labelbox/schema/project.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,48 @@ def export_labels(self, timeout_seconds=60):
177177
self.uid)
178178
time.sleep(sleep_time)
179179

180+
181+
def export_issues(self, status=None, timeout_seconds=60):
182+
""" Calls the server-side Issues exporting that generates a JSON
183+
payload, and returns the URL to that payload.
184+
185+
Args:
186+
timeout_seconds (float): Max waiting time, in seconds.
187+
status (string): valid values: Open, Resolved
188+
Returns:
189+
URL of the data file with this Project's issues. If the server didn't
190+
generate during the `timeout_seconds` period, None is returned.
191+
"""
192+
sleep_time = 2
193+
id_param = "projectId"
194+
status_param = "status"
195+
query_str = """query getProjectIssues($%s: ID!, $%s: IssueStatus) {
196+
project(where: { id: $%s }) {
197+
issueExportUrl(where: { status: $%s })
198+
}
199+
}""" % (id_param, status_param, id_param, status_param)
200+
201+
valid_statuses = [None, "Open", "Resolved"]
202+
203+
if status not in valid_statuses:
204+
raise ValueError("status must be in {}. Found {}".format(valid_statuses, status))
205+
206+
while True:
207+
res = self.client.execute(query_str, {id_param: self.uid, status_param: status})
208+
print(res)
209+
res = res.get('project').get('issueExportUrl')
210+
211+
if res:
212+
return res
213+
214+
timeout_seconds -= sleep_time
215+
if timeout_seconds <= 0:
216+
return None
217+
218+
logger.debug("Project '%s' issues export, waiting for server...",
219+
self.uid)
220+
time.sleep(sleep_time)
221+
180222
def upsert_instructions(self, instructions_file: str):
181223
"""
182224
* Uploads instructions to the UI. Running more than once will replace the instructions

0 commit comments

Comments
 (0)