UPDATE API
This commit is contained in:
parent
bb608d1000
commit
2ace390c35
13
Server.py
13
Server.py
@ -5,9 +5,9 @@ from Astronomy import *
|
||||
#Define Area
|
||||
class APICore(object):
|
||||
HTTPHead={
|
||||
'200':'HTTP/1.1 200 OK\r\nServer: SparkE/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\nConnection: keep-alive\r\n\r\n',
|
||||
'400':'HTTP/1.1 400 BAD REQUEST\r\nServer: SparkE/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\nConnection: keep-alive\r\n\r\n',
|
||||
'404':'HTTP/1.1 404 NOT FOUND\r\nServer: SparkE/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\nConnection: keep-alive\r\n\r\n'
|
||||
'200':'HTTP/1.1 200 OK\r\nServer: SparkEG/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\n\r\n',
|
||||
'400':'HTTP/1.1 400 BAD REQUEST\r\nServer: SparkEG/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\n\r\n',
|
||||
'404':'HTTP/1.1 404 NOT FOUND\r\nServer: SparkEG/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\n\r\n'
|
||||
}
|
||||
def __init__(self):
|
||||
self.__Log=[]
|
||||
@ -64,6 +64,7 @@ def socket(sock,addr):
|
||||
if("HTTP/" in data.decode("utf-8")):
|
||||
API.Log(addr[0],addr[1],"RECV","Received a HTTP request.")
|
||||
#HTTP Request.
|
||||
Type="HTTP"
|
||||
try:
|
||||
Heada=data.decode("utf-8").split("\r\n")[0].split(" ")[1].split("/")
|
||||
del Heada[0]
|
||||
@ -108,7 +109,6 @@ def socket(sock,addr):
|
||||
#No Parameter
|
||||
sock.send(API.HTTPHead['200'].encode("utf-8"))
|
||||
API.SunAzEl(sock,addr)
|
||||
break
|
||||
elif("POST " in data.decode("utf-8")):
|
||||
#POST Request
|
||||
try:
|
||||
@ -134,7 +134,7 @@ def socket(sock,addr):
|
||||
else:
|
||||
#Wrong POST Parameter,Return Bad Request
|
||||
API.Error400(sock,addr)
|
||||
break
|
||||
break
|
||||
else:
|
||||
#No Such Command
|
||||
sock.send(API.HTTPHead['404'].encode("utf8"))
|
||||
@ -145,6 +145,7 @@ def socket(sock,addr):
|
||||
else:
|
||||
API.Log(addr[0],addr[1],"RECV","Received a TCP request.")
|
||||
#TCP Request.
|
||||
Type="TCP"
|
||||
if(data.decode("utf-8")=="Help" or data.decode("utf-8")=="HELP" or data.decode("utf-8")=="help" or data.decode("utf-8")=="WIKI" or data.decode("utf-8")=="wiki" or data.decode("utf-8")=="wikis" or data.decode("utf-8")=="WIKIS" or data.decode("utf-8")=="?"):
|
||||
#Help Command
|
||||
Result=json.dumps({"wikis":"https://gitee.com/ghink/api/wikis"})
|
||||
@ -184,6 +185,8 @@ def socket(sock,addr):
|
||||
API.Log(addr[0],addr[1],"STATUS","Wrong code mode,must be utf-8.")
|
||||
API.Log(addr[0],addr[1],"STATUS","Lost connection.")
|
||||
break
|
||||
if Type=="HTTP":
|
||||
sock.close()
|
||||
def main():
|
||||
LogOutput=API.AutoLogOutput
|
||||
log_thread=threading.Thread(target=LogOutput,args=())
|
||||
|
Reference in New Issue
Block a user