Advertisement
AlexG2230954

Untitled

Jun 5th, 2022
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. from collections import deque
  2. import zipfile
  3. import os
  4.  
  5. def get_salary(file_path):
  6.     with open(file_path, "r", encoding="utf-8") as file:
  7.         data = file.read()
  8.     salary = data.strip().split()[-1]
  9.     return int(salary)
  10.  
  11. def dir_handle(dir_path, data):
  12.     for el in os.listdir(dir_path):
  13.         if not el.startswith("."):
  14.             data["q"].append(os.path.join(dir_path, el))
  15.  
  16. def file_handle(file_path, data):
  17.     if(file_path.endswith(".DS_Store")): return
  18.     data["total_salary"] += get_salary(file_path)
  19.  
  20.  
  21. def handle_element(element, data):
  22.     if os.path.isdir(element): dir_handle(element, data)
  23.     else: file_handle(element, data)
  24.  
  25. def extract_zip(zip_path, extract_folder):
  26.     with zipfile.ZipFile(zip_path, "r") as zip_ref:
  27.         zip_ref.extractall(extract_folder)
  28.  
  29. # Решение
  30. extract_zip("./big_folder.zip", "./big_folder")
  31. data = {"total_salary": 0, "q": deque()}
  32. data["q"].append("./big_folder")
  33.  
  34. while data["q"]:
  35.     curr_path = data["q"].popleft()
  36.     handle_element(curr_path, data)
  37.  
  38. print(data["total_salary"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement