-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.py
80 lines (49 loc) · 1.64 KB
/
utilities.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import json
import os
def displayMessage(message:str,style:int=0):
pointer=""
if style is 0:
pointer="-"
elif style is 1:
pointer="*"
else:
pointer=" "
print(f"[{pointer}] {message}")
def getLogo():
with open("art.txt","r",encoding="utf-8") as f:
logo=f.read()
f.close()
return logo
def getConfigData():
print("\n")
displayMessage("Running Configuration as config file is not present. Please Enter the required details :")
print("\n")
data={"name":"","path":"","email":"","interval":1,"files_to_track":[]}
data["name"]=input("Enter your Name: ")
data["path"]=input("Enter the folder path you want to track: ")
data["email"]=input("Enter your email id: ")
data["interval"]=int(input("Enter the frequency of tracking (in seconds) : "))
files_in_directory=os.listdir(data["path"])
for index,file in enumerate(files_in_directory):
print(f"[{index}] {file}")
fileIndicies=list(map(int,input("Enter Option Numbers with comma (,):").split(",")))
for index in fileIndicies:
data["files_to_track"].append(files_in_directory[index])
print("\n")
displayMessage("Configuration Complited Successfully")
print("\n")
return data
def createConfig(data:dict):
with open("config.json","a") as f:
json.dump(data, f)
f.close()
def loadConfig():
try:
with open("config.json","r") as f:
config=json.load(f)
f.close()
return config
except FileNotFoundError:
data=getConfigData()
createConfig(data)
return data