-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
38 lines (31 loc) · 1.15 KB
/
util.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
from path_constants import *
import json
import pyAesCrypt
import os
def get_entry_id(res_name):
with open(RESIDENTS_PATH) as residents_file:
residents_json = json.load(residents_file)
#TODO make it store the residents like this in the first place
#create a dictionary that is actually useful
residents_dict = {}
for resident in residents_json:
residents_dict[f"{resident['NameFirst']} {resident['NameLast']}"] = resident['EntryID']
return residents_dict[res_name]
def get_config():
with open(CONFIG_PATH) as config_file:
config_json = json.load(config_file)
return config_json
def get_API_key(password):
pyAesCrypt.decryptFile(KEY_PATH, 'config/key', password)
with open('config/key') as key_file:
API_key = key_file.read()
os.remove('config/key')
return API_key
def write_API_key(API_key, password):
with open('temporary', 'w') as tempFile:
tempFile.write(API_key)
pyAesCrypt.encryptFile('temporary', KEY_PATH, password)
os.remove('temporary')
def get_resident_list():
with open(RESIDENTS_PATH) as res_name_file:
return json.load(res_name_file)