From b44fce1cb8b139629141449b940a78445c67d364 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Campion?= <sebastien.campion@inria.fr>
Date: Wed, 3 Jul 2019 21:58:16 +0200
Subject: [PATCH] fix problem of API legacy from server

---
 allgo/__init__.py | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/allgo/__init__.py b/allgo/__init__.py
index 97ec9e1..4ba04d3 100644
--- a/allgo/__init__.py
+++ b/allgo/__init__.py
@@ -13,7 +13,7 @@ except ImportError:
 import requests
 
 log = logging.getLogger('allgo')
-__version__ = '0.1.8'
+__version__ = '0.1.9'
 
 
 def local_token():
@@ -66,14 +66,20 @@ class App:
         r = requests.post(url, headers=headers, files=files, data=data, verify=verify_tls)
         r.raise_for_status()
         r = r.json()
-        jobid = r['id']
+        if 'id' in r.keys():
+            jobid = r['id']
+        else:
+            jobid = list(r.keys())[0]
         results = None
         while True:
             url = '{}/api/v1/jobs/{}'.format(ALLGO_URL, jobid)
             r = requests.get(url, headers=headers, verify=verify_tls)
             r.raise_for_status()
             results = r.json()
-            status = results['status']
+            if 'status' in results.keys():
+                status = results['status']
+            else:
+                status = list(results.values())[0]['status']
             if status in ['created', 'waiting', 'running', 'in progress']:
                 log.info("wait for job %s in status %s", jobid, status)
                 time.sleep(2)
@@ -84,7 +90,15 @@ class App:
             raise Exception('Job %s failed with status %s', (jobid, status))
 
         elif status == 'done' and results:
-            for filename, url in results[str(jobid)].items():
+            if 'id' in results.keys():
+                files = results[str(jobid)].items()
+            else:
+                files = results[str(jobid)]['files'].items()
+            for filename, url in files:
                 filepath = os.path.join(outputdir, filename)
-                with open(filepath, 'wb') as fb:
-                    fb.write(requests.get(url, stream=True).content)
+                with requests.get(url, headers=headers, verify=verify_tls, stream=True) as r:
+                    r.raise_for_status()
+                    with open(filepath, 'wb') as f:
+                        for chunk in r.iter_content(chunk_size=8192): 
+                            if chunk: 
+                                f.write(chunk)
-- 
GitLab