Develop
6 open threads
6 open threads
Resolves #18 (closed) #19 (closed) #20 (closed)
Merge request reports
Activity
112 113 response = requests.get(url=f"{Config.get('base_url')}/download{file_id}") 114 if response.status_code == 404 or response.status_code == 500: 115 raise FileNotFoundError("File not found") 116 117 zip_buffer = io.BytesIO(initial_bytes=response.content) 118 with zipfile.ZipFile( 119 zip_buffer, 120 mode="r", 121 compression=zipfile.ZIP_DEFLATED, 122 ) as zip_file: 123 return {i.filename: zip_file.open(i).read().decode("utf-8") 124 for i in filter( 125 lambda x: try_decode(zip_file.open(x).read()) 126 and not x.is_dir(), 127 zip_file.infolist())} Dict comprehension with filename keys and file content values. If file can be decoded to UTF-8 -> append to dictionary, else ignore
Edited by Szymon Ciomborchanged this line in version 2 of the diff
88 91 return output_path 92 93 94 def download_file_as_dict( 95 file_id: FileID, 96 ) -> tp.Dict[str, str]: 97 """Downloads file by its FileID. 98 99 Args: 100 file_id (FileID): File id of a file to download 101 102 Returns: 103 dict. Dictionary mapping filenames in output zipfile to file contents. 104 105 """ 106 def try_decode(file): changed this line in version 2 of the diff
40 46 file_id = upload_file(file_path=args.input) 41 47 t = Task(args.lpmn) 42 48 output_file_id = t.run(file_id=file_id, verbose=args.verbose, timeout=0) 43 downloaded = download_file(file_id=output_file_id, output_path=args.output) 49 downloaded = download_file(file_id=output_file_id, changed this line in version 2 of the diff
108 file.decode("utf-8") 109 return True 110 except UnicodeDecodeError: 111 return False 112 113 response = requests.get(url=f"{Config.get('base_url')}/download{file_id}") 114 if response.status_code == 404 or response.status_code == 500: 115 raise FileNotFoundError("File not found") 116 117 zip_buffer = io.BytesIO(initial_bytes=response.content) 118 with zipfile.ZipFile( 119 zip_buffer, 120 mode="r", 121 compression=zipfile.ZIP_DEFLATED, 122 ) as zip_file: 123 return {i.filename: zip_file.open(i).read().decode("utf-8") changed this line in version 2 of the diff
103 103 time.sleep(0.5) 104 104 progress = self.get_progress() 105 105 if pbar: 106 pbar.update(progress * 100) 106 pbar.update(progress * 100 - pbar.n) 107 107 108 108 if pbar: 109 109 pbar.update(100) changed this line in version 2 of the diff
added 1 commit
- 67f8351d - added test_download_file_as_dict, fixed indentation and pbar update
mentioned in commit cf9a197f
Please register or sign in to reply