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
|
#Define Area
|
||||||
class APICore(object):
|
class APICore(object):
|
||||||
HTTPHead={
|
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',
|
'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: 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: SparkEG/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\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'
|
'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):
|
def __init__(self):
|
||||||
self.__Log=[]
|
self.__Log=[]
|
||||||
@ -64,6 +64,7 @@ def socket(sock,addr):
|
|||||||
if("HTTP/" in data.decode("utf-8")):
|
if("HTTP/" in data.decode("utf-8")):
|
||||||
API.Log(addr[0],addr[1],"RECV","Received a HTTP request.")
|
API.Log(addr[0],addr[1],"RECV","Received a HTTP request.")
|
||||||
#HTTP Request.
|
#HTTP Request.
|
||||||
|
Type="HTTP"
|
||||||
try:
|
try:
|
||||||
Heada=data.decode("utf-8").split("\r\n")[0].split(" ")[1].split("/")
|
Heada=data.decode("utf-8").split("\r\n")[0].split(" ")[1].split("/")
|
||||||
del Heada[0]
|
del Heada[0]
|
||||||
@ -108,7 +109,6 @@ def socket(sock,addr):
|
|||||||
#No Parameter
|
#No Parameter
|
||||||
sock.send(API.HTTPHead['200'].encode("utf-8"))
|
sock.send(API.HTTPHead['200'].encode("utf-8"))
|
||||||
API.SunAzEl(sock,addr)
|
API.SunAzEl(sock,addr)
|
||||||
break
|
|
||||||
elif("POST " in data.decode("utf-8")):
|
elif("POST " in data.decode("utf-8")):
|
||||||
#POST Request
|
#POST Request
|
||||||
try:
|
try:
|
||||||
@ -134,7 +134,7 @@ def socket(sock,addr):
|
|||||||
else:
|
else:
|
||||||
#Wrong POST Parameter,Return Bad Request
|
#Wrong POST Parameter,Return Bad Request
|
||||||
API.Error400(sock,addr)
|
API.Error400(sock,addr)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
#No Such Command
|
#No Such Command
|
||||||
sock.send(API.HTTPHead['404'].encode("utf8"))
|
sock.send(API.HTTPHead['404'].encode("utf8"))
|
||||||
@ -145,6 +145,7 @@ def socket(sock,addr):
|
|||||||
else:
|
else:
|
||||||
API.Log(addr[0],addr[1],"RECV","Received a TCP request.")
|
API.Log(addr[0],addr[1],"RECV","Received a TCP request.")
|
||||||
#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")=="?"):
|
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
|
#Help Command
|
||||||
Result=json.dumps({"wikis":"https://gitee.com/ghink/api/wikis"})
|
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","Wrong code mode,must be utf-8.")
|
||||||
API.Log(addr[0],addr[1],"STATUS","Lost connection.")
|
API.Log(addr[0],addr[1],"STATUS","Lost connection.")
|
||||||
break
|
break
|
||||||
|
if Type=="HTTP":
|
||||||
|
sock.close()
|
||||||
def main():
|
def main():
|
||||||
LogOutput=API.AutoLogOutput
|
LogOutput=API.AutoLogOutput
|
||||||
log_thread=threading.Thread(target=LogOutput,args=())
|
log_thread=threading.Thread(target=LogOutput,args=())
|
||||||
|
Reference in New Issue
Block a user