forked from ZtF/idos_scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
31 lines (25 loc) · 1.08 KB
/
server.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
from twisted.application.internet import TCPServer
from twisted.application.service import Application
from twisted.web.resource import Resource
from twisted.web.server import Site
from json import dumps
import scrape
class PathPage(Resource):
def render_GET(self, request):
request.setHeader("Content-Type", "application/json; charset=utf-8")
args = {arg: request.args[arg].pop() for arg in request.args}
if not args:
return dumps('Expecting: start, end, [date], [time], [resource]')
return dumps(scrape.get_path(**args))
class DetailPage(Resource):
def render_GET(self, request):
request.setHeader("Content-Type", "application/json; charset=utf-8")
args = {arg: request.args[arg].pop() for arg in request.args}
if not args:
return dumps('Expecting: resource')
return dumps(scrape.get_detail(**args))
root = Resource()
root.putChild("path", PathPage())
root.putChild("detail", DetailPage())
application = Application("IDOS mobile scraper")
TCPServer(8880, Site(root)).setServiceParent(application)