-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_clipboard.py
58 lines (48 loc) · 1.36 KB
/
multi_clipboard.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
import sys
import clipboard
import json
SAVED_DATA = 'clipboard.json'
def save_data(filepath, data):
with open(filepath, "w") as f:
json.dump(data, f, indent = 6)
def load_data(filepath):
try:
with open(filepath, 'r') as f:
data = json.load(f)
return data
except Exception as e:
print("error in load", e)
return {}
def file_chooser():
pass
if len(sys.argv) == 2:
command = sys.argv[1]
data = load_data(SAVED_DATA)
if command == 'save':
key = input('Enter a key: ')
data[key] = clipboard.paste()
save_data(SAVED_DATA, data)
print("Data saved.")
elif command == 'load':
key = input('Enter a key: ')
if key in data:
clipboard.copy(data[key])
print('Data copied to clipboard')
else:
print("Key doesn't exist.")
elif command == 'list':
print(data)
# Delete something from json file / not deleting
elif command == 'delete':
key = input('Enter a key: ')
try:
if key in data:
del data[key]
except Exception as e:
print("This has been already deleted", e)
else:
print('Data has been deleted.')
else:
print('Unknown command')
else:
print('Please pass exactly one command.')