-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxyserver.py
46 lines (39 loc) · 1.29 KB
/
proxyserver.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
from urlparse import urlparse
import requests
import json
PORT = 8000
class RequestHandler(BaseHTTPRequestHandler):
#Handler for the GET requests
def do_OPTIONS(self):
fullPath = 'http://api.sportradar.us' + self.path
r = requests.get(fullPath)
print r.json()
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*')
self.end_headers()
self.wfile.write(r.json())
return
def do_GET(self):
print self.path
fullPath = 'http://api.sportradar.us' + self.path
r = requests.get(fullPath)
data = r.json()
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Headers', '*')
self.send_header('Access-Control-Allow-Methods', '*')
self.end_headers()
self.wfile.write(json.dumps(data))
return
try:
#Create a web server and define the handler to manage the
#incoming request
server = HTTPServer(('', PORT), RequestHandler)
print 'Started httpserver on port ' , PORT
#Wait forever for incoming htto requests
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down the web server'
server.socket.close()