-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.py
More file actions
31 lines (20 loc) · 815 Bytes
/
utilities.py
File metadata and controls
31 lines (20 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import zipfile
import pathlib
import time
FILEPATH = "tasks.txt"
""" Read tasks from the text file. """
def get_tasks(filepath=FILEPATH):
with open(filepath, 'r') as file_local:
tasks_local = file_local.readlines()
return tasks_local
"""" Write Tasks in the text file. """
def write_tasks(data, filepath=FILEPATH):
with open(filepath, 'w') as file_local:
file_local.writelines(data)
""" Create Zip Archive """
def make_zip_archive(filepaths, destination_folder):
destination_path = pathlib.Path(destination_folder, f"compressed-{time.time()}.zip")
with zipfile.ZipFile(destination_path, 'w') as archive:
for filepath in filepaths:
filepath_local = pathlib.Path(filepath)
archive.write(filepath, arcname=filepath_local.name)