-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwr.py
More file actions
94 lines (83 loc) · 3.38 KB
/
wr.py
File metadata and controls
94 lines (83 loc) · 3.38 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
from collections import defaultdict
keywords_dict=defaultdict(list)
scelta=-1
while (scelta!=0):
file=open('keywords.txt','r') #CHANGE this with the other files. Create it before and add an empty dict in it
keywords_dict=eval(file.readline())
file.close()
print("Keywords insert Script")
print("What do you want to do?")
print("1. View all keywords.")
print("2. Insert a new keyword.")
print("3. Insert a new key with new keywords. ")
print("4. Delete a keyword.")
print("5. Delete a key of the keyword's dict.")
print("0. Exit. ")
scelta=input("Input: ")
if scelta=="1":
for key in list(keywords_dict.keys()):
print(key,": ",keywords_dict.get(key))
if scelta=="2":
newkw=False
while newkw==False:
print("Type the key of the new keyword")
for key in list(keywords_dict.keys()):
print(key)
array_key=input("Key: ")
if array_key in keywords_dict.keys():
new_keyword=input("Insert new keyword: ")
keywords_dict[array_key].append(new_keyword)
newkw=True
else:
print("Key not found! Reinsert key")
file=open('keywords.txt','w')
file.write(str(keywords_dict))
file.close()
if scelta=="3":
new_key=input("Insert the new key: ")
if new_key in keywords_dict.keys():
print("This key already exists!")
else:
new_value=input("Do you want to insert a new value for new key?").lower()
while new_value!="no":
value=input("Insert new value: ")
keywords_dict.setdefault(new_key,[]).append(value)
new_value=input("Do you want to insert a new value for new key?").lower()
file=open('keywords.txt','w')
file.write(str(keywords_dict))
file.close()
if scelta=="4":
for key in list(keywords_dict.keys()):
print(key,": ",keywords_dict.get(key))
newkw=False
while newkw==False:
print("Type the key of the keyword to delete")
for key in list(keywords_dict.keys()):
print(key)
array_key=input("Key: ")
if array_key in keywords_dict.keys():
old_keyword=input("Insert the keyword you want to delete: ")
if old_keyword in keywords_dict[array_key]:
keywords_dict[array_key].remove(old_keyword)
newkw=True
else:
print(old_keyword," can't be found in this key")
else:
print("Key not found! Reinsert key")
file=open('keywords.txt','w')
file.write(str(keywords_dict))
file.close()
if scelta=="5":
for key in list(keywords_dict.keys()):
print(key,": ",keywords_dict.get(key))
old_key=input("Insert the key to be removed: ")
if old_key in list(keywords_dict.keys()):
print("This will REMOVE all the value for this key!")
delkey=input("Are you sure you want remove it? (YES) ").upper()
if (delkey=="YES"):
keywords_dict.pop(old_key,None)
else:
print("Key not found!")
file=open('keywords.txt','w')
file.write(str(keywords_dict))
file.close()