-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
executable file
·45 lines (33 loc) · 1.21 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env -S python3 -u
from http.server import BaseHTTPRequestHandler
from http.server import HTTPServer
from http.server import test
import requests
import urllib
hostName = "localhost"
serverPort = 8080
class WeatherServer(BaseHTTPRequestHandler):
def do_GET(self):
u = urllib.parse.urlparse(self.path)
query = u.query
url = 'https://app.netatmo.net/api/getmeasure'
request = urllib.parse.parse_qsl(query)
headers = {
"Authorization": "Bearer 52d42bfc1777599b298b456c|24fc90e3077d50c39b346c9bc4beae1f",
}
response = requests.post(url, headers=headers, data=request)
response.raise_for_status()
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header("Content-type", "application.json")
self.end_headers()
self.wfile.write(bytes(response.text, "utf-8"))
if __name__ == '__main__':
webServer = HTTPServer((hostName, serverPort), WeatherServer)
print("Server started http://%s:%s" % (hostName, serverPort))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
print("Server stopped.")