@@ -73,6 +73,7 @@ def save_original(self, filename):
7373
7474 @api_method
7575 def save_analytics (self , filename , output_format = 'application/json' ):
76+ self .wait_for_completion ()
7677 response = self .api .request ('%s/files/%s/analytics' % (self .api ._UPLOAD_BASE_URL , self .file_id ,),
7778 headers = dict (
7879 Accept = output_format ,
@@ -83,14 +84,34 @@ def save_analytics(self, filename, output_format='application/json'):
8384 for chunk in response .iter_content (chunk_size = self .api ._CHUNK_SIZE ):
8485 f .write (chunk )
8586
87+ @api_method
88+ def get_analytics (self , output_format = 'application/json' ):
89+ self .wait_for_completion ()
90+ response = self .api .request ('%s/files/%s/analytics' % (self .api ._UPLOAD_BASE_URL , self .file_id ,),
91+ headers = dict (
92+ Accept = output_format ,
93+ ** self .api .headers
94+ ))
95+ if output_format == 'application/json' :
96+ return response .json ()
97+ else :
98+ return response .text
99+
86100 @api_method
87101 def save_annotated (self , filename ):
102+ self .wait_for_completion ()
88103 response = self .api .request ('%s/files/%s/annotated' % (self .api ._UPLOAD_BASE_URL , self .file_id ),
89104 stream = True )
90105 with open (filename , 'wb' ) as f :
91106 for chunk in response .iter_content (chunk_size = self .api ._CHUNK_SIZE ):
92107 f .write (chunk )
93108
109+ @api_method
110+ def get_annotated (self ):
111+ self .wait_for_completion ()
112+ response = self .api .request ('%s/files/%s/annotated' % (self .api ._UPLOAD_BASE_URL , self .file_id ))
113+ return response .text
114+
94115 @api_method
95116 def delete (self ):
96117 response = self .api .request ('%s/files/%s' % (self .api ._UPLOAD_BASE_URL , self .file_id ),
@@ -114,7 +135,7 @@ def set_metadata(self,
114135 method = 'patch' )
115136
116137 def wait_for_completion (self ):
117- while self .status not in {"COMPLETED" , "DELETED" }:
138+ while self .status not in {"COMPLETED" , "DELETED" , "FAILED" }:
118139 sleep (1 )
119140 self .get_status ()
120141
0 commit comments