upgrade to python3
This commit is contained in:
parent
4673325aa7
commit
5e08d676f6
87
mapserver/mapper.py
Normal file → Executable file
87
mapserver/mapper.py
Normal file → Executable file
@ -1,48 +1,61 @@
|
||||
#!/usr/bin/env python
|
||||
#-*-coding:utf-8-*-
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from http.server import SimpleHTTPRequestHandler, HTTPServer
|
||||
from urllib.parse import parse_qs
|
||||
import socket
|
||||
import struct
|
||||
import time
|
||||
import web
|
||||
HOST = 'localhost'
|
||||
PORT = 5678
|
||||
BUFFSIZE = 1024
|
||||
ADDR = ( HOST, PORT )
|
||||
import os
|
||||
|
||||
sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
|
||||
HOST = 'localhost'
|
||||
PORT = 5678
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
|
||||
class MapHandler(SimpleHTTPRequestHandler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
directory = os.path.dirname(__file__)
|
||||
super().__init__(*args, directory=directory, **kwargs)
|
||||
|
||||
urls = (
|
||||
'/','index',
|
||||
'/post','post',
|
||||
'/static/*','static',
|
||||
)
|
||||
app = web.application(urls, globals())
|
||||
def do_GET(self):
|
||||
if self.path == '/':
|
||||
self.send_response(301)
|
||||
self.send_header('Location', '/static/baidumap.html')
|
||||
self.end_headers()
|
||||
else:
|
||||
super(MapHandler, self).do_GET()
|
||||
|
||||
class index:
|
||||
def GET(self):
|
||||
return ""
|
||||
|
||||
class post:
|
||||
def POST(self):
|
||||
inn=web.input()
|
||||
lon=float(inn.get('lon'))
|
||||
lat=float(inn.get('lat'))
|
||||
h=float(inn.get('hgt'))
|
||||
data=struct.pack("ddd",lat,lon,h)
|
||||
sock.sendto(data,ADDR)
|
||||
print lon,lat,h
|
||||
|
||||
class static:
|
||||
def GET(self, media, file):
|
||||
try:
|
||||
f = open(media+'/'+file, 'r')
|
||||
return f.read()
|
||||
except:
|
||||
return '404'
|
||||
|
||||
if __name__ == "__main__": app.run()
|
||||
def do_POST(self):
|
||||
if self.path == '/post':
|
||||
urlencoded = self.rfile.read(int(self.headers['Content-Length']))
|
||||
parsed = parse_qs(urlencoded)
|
||||
pos = [float(parsed.get(k)[0]) for k in [b'lon', b'lat', b'hgt']]
|
||||
data = struct.pack('ddd', *pos)
|
||||
sock.sendto(data, (HOST, PORT))
|
||||
print(*pos)
|
||||
self.send_response(200)
|
||||
self.send_header('Content-Type', 'text/plain')
|
||||
else:
|
||||
self.send_response(404)
|
||||
self.end_headers()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from argparse import ArgumentParser
|
||||
argp = ArgumentParser(description='GPS-SDR-SIM realtime map server.')
|
||||
argp.add_argument('port',
|
||||
type=int,
|
||||
default=8080,
|
||||
nargs='?',
|
||||
help='specify port for map server [default: 8080]')
|
||||
argp.add_argument(
|
||||
'--host',
|
||||
type=str,
|
||||
default='0.0.0.0',
|
||||
help='specify host map server to bind [default: 0.0.0.0]')
|
||||
args = argp.parse_args()
|
||||
|
||||
httpd = HTTPServer((args.host, args.port), MapHandler)
|
||||
print('Serving at http://{}:{}'.format(args.host, args.port))
|
||||
httpd.serve_forever()
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user