-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
31 lines (23 loc) · 869 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
from uadetector.pyramid import ua_prop
def index(request):
return Response('<pre>{}</pre>'.format(json.dumps({
'device_type': request.ua.device_type,
'os': request.ua.os,
'browser': request.ua.browser,
'from_pc': request.ua.from_pc,
'from_smartphone': request.ua.from_pc,
}, indent=2)))
with Configurator() as config:
config.add_route('index', '/')
config.add_view(index, route_name='index')
# add request method
config.add_request_method(ua_prop(), name='ua', reify=True)
app = config.make_wsgi_app()
if __name__ == '__main__':
with make_server('127.0.0.1', 8000, app) as server:
print("Serving on port 8000...")
server.serve_forever()