Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- import zipfile
- import os
- def get_salary(file_path):
- with open(file_path, "r", encoding="utf-8") as file:
- data = file.read()
- salary = data.strip().split()[-1]
- return int(salary)
- def dir_handle(dir_path, data):
- for el in os.listdir(dir_path):
- if not el.startswith("."):
- data["q"].append(os.path.join(dir_path, el))
- def file_handle(file_path, data):
- if(file_path.endswith(".DS_Store")): return
- data["total_salary"] += get_salary(file_path)
- def handle_element(element, data):
- if os.path.isdir(element): dir_handle(element, data)
- else: file_handle(element, data)
- def extract_zip(zip_path, extract_folder):
- with zipfile.ZipFile(zip_path, "r") as zip_ref:
- zip_ref.extractall(extract_folder)
- # Решение
- extract_zip("./big_folder.zip", "./big_folder")
- data = {"total_salary": 0, "q": deque()}
- data["q"].append("./big_folder")
- while data["q"]:
- curr_path = data["q"].popleft()
- handle_element(curr_path, data)
- print(data["total_salary"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement