change back to web.py since it is much more faster

And finally I found that web.py supports Python 3...
This commit is contained in:
Chuang Zhu 2020-12-13 01:16:17 +08:00
parent ff45f465e6
commit 4ce4d0a753
2 changed files with 171 additions and 47 deletions

138
.gitignore vendored
View File

@ -39,3 +39,141 @@ gps-sdr-sim-lut
# Temporary files # Temporary files
*.swp *.swp
*~ *~
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/

View File

@ -1,62 +1,48 @@
#!/usr/bin/env python3 #!/usr/bin/env python
from __future__ import print_function
import tornado.ioloop
import tornado.web
from tornado.web import RequestHandler, StaticFileHandler
import socket import socket
import struct import struct
import time import time
import os import web
HOST = 'localhost' HOST = 'localhost'
PORT = 5678 PORT = 5678
BUFFSIZE = 1024
ADDR = (HOST, PORT)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
urls = (
class IndexHandler(RequestHandler): '/', 'index',
def get(self): '/post', 'post',
self.redirect('/static/baidumap.html') '/static/*', 'static',
)
app = web.application(urls, globals())
class PostHandler(RequestHandler): class index:
def post(self): def GET(self):
self.set_header('Content-Type', 'text/plain') raise web.seeother('/static/baidumap.html')
pos = [
float(self.get_body_argument(k)) for k in ['lat', 'lon', 'hgt']
]
data = struct.pack('ddd', *pos)
sock.sendto(data, (HOST, PORT))
print(*pos)
self.write('OK')
def make_app(): class post:
return tornado.web.Application([ def POST(self):
(r'/', IndexHandler), inn = web.input()
(r'/post', PostHandler), lon = float(inn.get('lon'))
(r'/static/(.*)', StaticFileHandler, { lat = float(inn.get('lat'))
'path': os.path.dirname(__file__) h = float(inn.get('hgt'))
}) data = struct.pack('ddd', lat, lon, h)
]) sock.sendto(data, ADDR)
print(lon, lat, h)
if __name__ == "__main__": class static:
from argparse import ArgumentParser def GET(self, media, file):
argp = ArgumentParser(description='GPS-SDR-SIM realtime map server.') try:
argp.add_argument('port', f = open(media + '/' + file, 'r')
type=int, return f.read()
default=8080, except:
nargs='?', return '404'
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()
app = make_app()
print('Serving at http://{}:{}'.format(args.host, args.port)) if __name__ == '__main__':
app.listen(args.port, args.host) app.run()
tornado.ioloop.IOLoop.current().start()