38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||
|
import igmirror
|
||
|
import re
|
||
|
|
||
|
hostName = "localhost"
|
||
|
serverPort = 8080
|
||
|
|
||
|
def update_igaccount(name):
|
||
|
print(name)
|
||
|
|
||
|
class MyServer(BaseHTTPRequestHandler):
|
||
|
def do_GET(self):
|
||
|
self.send_response(200)
|
||
|
self.send_header("Content-type", "application/json")
|
||
|
self.end_headers()
|
||
|
path = self.path.strip('/')
|
||
|
parts = path.split('/')
|
||
|
if len(parts) == 2:
|
||
|
# make sure account name contains only safe characters
|
||
|
accname = re.sub(r'[^a-zA-Z0-9_]+', '', parts[0])
|
||
|
if parts[1].lower() == 'add':
|
||
|
igmirror.add_igaccount(accname)
|
||
|
elif parts[1].lower() == 'update':
|
||
|
update_igaccount(accname)
|
||
|
self.wfile.write(bytes('OK', "utf-8"))
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
webServer = HTTPServer(('localhost', 8080), MyServer)
|
||
|
print("Server started http://%s:%s" % (hostName, serverPort))
|
||
|
|
||
|
try:
|
||
|
webServer.serve_forever()
|
||
|
except KeyboardInterrupt:
|
||
|
pass
|
||
|
|
||
|
webServer.server_close()
|
||
|
print("Server stopped.")
|