Skip to content

Commit e4a1f48

Browse files
Merge pull request #3 from MLSA-SRM/master
new pull
2 parents 7a3ccc2 + 4c67b6c commit e4a1f48

File tree

4 files changed

+121
-15
lines changed

4 files changed

+121
-15
lines changed

helpVersion.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from utils import message, debug, init_default_key_storage, printy, STORAGE_DIR, STORE_KEY_F
2+
3+
def help():
4+
message.success("Usage: clik <command> \n \n init\t\tinitializes the script to input key value pairs \n add\t\tinsert key value pair in existing json file \n subtract\tdelete key value pair in existing json file \n modify\t\talter key value in existing json file \n encrypt\tencrypts key value dictionary to json and generate encryption key \n decrypt\tdecrypts json file to dictionary \n help\t\tguide through all the CLIK functions \n version\tshows the CLIK version installed ")
5+
6+
def version():
7+
message.success("CLIK Version 0.0.0")
8+
9+
10+
#test functions
11+
#help()
12+
#version()

json_convert.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
#function to convert JSON to dictionary and print
1919
def jsonToDict(filename):
20-
try:
20+
#try:
2121
with open(filename,'r') as fh:
2222
json_str = fh.read()
2323
json_value = json.loads(json_str)
2424
return json_value
25-
except:
25+
#except:
2626
return False
2727

2828

@@ -32,7 +32,7 @@ def dictToJson(inputDict, filename, indents=2):
3232
with open(filename, 'w') as fh2:
3333
fh2.write(json.dumps(inputDict, indent=indents, sort_keys=True))
3434
message.success('Keys stored successfully')
35-
return True
35+
return True
3636
except Exception as e:
3737
message.error('Couldn\'t write to JSON')
3838
debug.error(str(e))
@@ -49,6 +49,7 @@ def display_json (filename, display_indent=4):
4949
debug.error('JSON to Dict Failed')
5050

5151
#calling the functions
52-
# jsonToDict('test_data/apikeys.json')
52+
53+
#print(jsonToDict('test_data/test_api_keys.json'))
5354
# dictToJson(api_val,'test_data/test_api_keys.json')
54-
# display_json ('test_data/test_api_keys.json')
55+
#display_json ('test_data/test_api_keys.json')

menu_functions.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
from utils import message, debug, init_default_key_storage, printy, STORAGE_DIR, STORE_KEY_F
2+
from json_convert import jsonToDict, dictToJson, display_json
3+
4+
fileName = 'test_data/test_api_keys.json'
5+
display_json (fileName)
6+
7+
def add(fileName):
8+
dictkeys = jsonToDict('test_data/test_api_keys.json')
9+
10+
def getKeyValue(keyName):
11+
key = message.prompt(keyName + ' value')
12+
if(key!=''):
13+
dictkeys[keyName] = key
14+
elif(key==''):
15+
message.error('Value cannot be empty.')
16+
getKeyValue(keyName)
17+
18+
while(True):
19+
keyName = message.prompt('Key (done)')
20+
if(keyName!=''):
21+
getKeyValue(keyName)
22+
elif (keyName==''):
23+
break
24+
try:
25+
dictToJson(dictkeys,'test_data/test_api_keys.json')
26+
message.success('New keys added successfully!')
27+
except:
28+
message.error('Some error occured!')
29+
return False
30+
31+
32+
def subtract(fileName):
33+
dictkeys = jsonToDict('test_data/test_api_keys.json')
34+
35+
def removeKeyValue(keyName):
36+
try:
37+
del dictkeys[keyName]
38+
except:
39+
message.error('No such Key exists!')
40+
41+
42+
while(True):
43+
keyName = message.prompt('Enter Key to be removed (done)')
44+
if(keyName!=''):
45+
removeKeyValue(keyName)
46+
elif (keyName==''):
47+
break
48+
49+
try:
50+
dictToJson(dictkeys,'test_data/test_api_keys.json')
51+
message.success('Keys removed successfully!')
52+
except:
53+
message.error('Some error occured!')
54+
return False
55+
56+
57+
def modify(fileName):
58+
dictkeys = jsonToDict('test_data/test_api_keys.json')
59+
60+
def modifyKeyValue(keyName):
61+
if keyName in dictkeys:
62+
key = message.prompt(keyName + ' new value')
63+
if(key!=''):
64+
dictkeys[keyName] = key
65+
elif(key==''):
66+
message.error('Value cannot be empty.')
67+
getKeyValue(keyName)
68+
69+
else:
70+
message.error('No such Key exists!')
71+
72+
while(True):
73+
keyName = message.prompt('Enter Key to be modified (done)')
74+
if(keyName!=''):
75+
modifyKeyValue(keyName)
76+
elif (keyName==''):
77+
break
78+
79+
try:
80+
dictToJson(dictkeys,'test_data/test_api_keys.json')
81+
message.success('Keys modified successfully!')
82+
except:
83+
message.error('Some error occured!')
84+
return False
85+
86+
87+
88+
89+
#test functions
90+
91+
#add(fileName)
92+
#subtract(fileName)
93+
#modify(fileName)

test_data/test_api_keys.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"ADMIN_KEY": "exampleadmin123",
3-
"ADMIN_PASSWORD": "Darwin@Example2506",
4-
"ADMIN_USERNAME": "example@admin",
5-
"FACEBOOK_API_KEYS_SECRET": "7jewdsjnfdnjnfssnsH",
6-
"FACEBOOK_API_KEY_SECRET": "7jewkdjwenbnsH",
7-
"INSTA_API_KEY": "Qhsh6yihijy3e8",
8-
"INSTA_API_KEY_SECRET": "Qhsh6fjkdsbfky3e8",
9-
"TWITTER_ACCESS_TOKEN": "1234614-4Du6ZlFtVOpNMgtwIKjRe4wzwxHejcDRaxjNmAU",
10-
"YOUTUBE_API_KEY": "83nicciwdcIIUNij",
11-
"YOUTUBE_API_KEY_SECRET": "8djkfhjsndcIIUNij"
2+
"ADMIN_KEY": "exampleadmin123",
3+
"ADMIN_PASSWORD": "Darwin@Example2506",
4+
"ADMIN_USERNAME": "example@admin",
5+
"FACEBOOK_API_KEYS_SECRET": "7jewdsjnfdnjnfssnsH",
6+
"FACEBOOK_API_KEY_SECRET": "7jewkdjwenbnsH",
7+
"INSTA_API_KEY": "Qhsh6yihijy3e8",
8+
"INSTA_API_KEY_SECRET": "Qhsh6fjkdsbfky3e8",
9+
"TWITTER_ACCESS_TOKEN": "1234614-4Du6ZlFtVOpNMgtwIKjRe4wzwxHejcDRaxjNmAU",
10+
"YOUTUBE_API_KEY": "HAHAHAHCHANGEDDD2IT",
11+
"YOUTUBE_API_KEY_SECRET": "8djkfhjsndcIIUNij"
1212
}

0 commit comments

Comments
 (0)