Skip to content
Snippets Groups Projects

Develop

Merged
Szymon Ciomborrequested to merge
develop into master
6 open threads

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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())}
  • 86 89 with open(output_path, "wb") as f:
    87 90 f.write(response.content)
    88 91 return output_path
    92
    93
    94 def download_file_as_dict(
  • 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):
  • 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,
  • 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")
  • 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)
  • Please, do not use develop for new functionalities. Always create a new branch from develop.

  • Szymon Ciombor added 1 commit

    added 1 commit

    • 67f8351d - added test_download_file_as_dict, fixed indentation and pbar update

    Compare with previous version

  • mentioned in commit cf9a197f

  • Please register or sign in to reply
    Loading