82 lines
2 KiB
Python
82 lines
2 KiB
Python
import json
|
|
import requests
|
|
"""
|
|
Features
|
|
This is the main API for executing functions with data
|
|
"""
|
|
|
|
|
|
class API:
|
|
def __init__(self):
|
|
with open('data.json') as f:
|
|
self.data = json.loads(f.read())
|
|
# Only refresh data when a change is made
|
|
|
|
def save(self):
|
|
with open('data.json','w') as f:
|
|
f.write(json.dumps(self.data,indent=2))
|
|
return True
|
|
return False
|
|
|
|
#Administration
|
|
|
|
|
|
def is_admin(self,handle):
|
|
#return bool
|
|
pass
|
|
def add_admin(self,handle):
|
|
#return bool
|
|
if self.is_admin(handle):
|
|
return True
|
|
else:
|
|
self.data["admins"].append(handle)
|
|
self.save()
|
|
return True
|
|
def remove_admin(self,handle):
|
|
#return bool
|
|
if self.is_admin(handle):
|
|
i = self.data["admins"].index(handle)
|
|
self.data["admins"].pop(i)
|
|
self.save()
|
|
return True
|
|
else:
|
|
return True
|
|
|
|
#FAQ
|
|
def get_header(self):
|
|
return self.data["faq"]["header"]
|
|
def set_header(self,hdr):
|
|
#return bool
|
|
self.data["faq"]["header"] = hdr
|
|
self.save()
|
|
return True
|
|
def get_questions(self):
|
|
#return questions
|
|
return self.data["faq"]["questions"]
|
|
def add_question(self,qtn):
|
|
#return bool
|
|
self.data["faq"]["questions"].append(qtn)
|
|
self.save()
|
|
return True
|
|
def remove_question(self,qtn_i):
|
|
#return bool
|
|
self.data["faq"]["questions"].pop(qtn_i)
|
|
self.save()
|
|
return True
|
|
def update_question(self,qtn_i,qtn):
|
|
#return bool
|
|
self.data["faq"]["questions"][qtn_i]=qtn
|
|
return True
|
|
|
|
#Meetings
|
|
def get_meetings():
|
|
pass
|
|
def request_meeting():
|
|
pass
|
|
def accept_meeting():
|
|
pass
|
|
|
|
|
|
if __name__ == '__main__':
|
|
storeAPI = API()
|
|
print("Storage loaded.\n",storeAPI.data['username'])
|