fix: results provided
This commit is contained in:
parent
9185bec3fe
commit
2be0fe6ec5
Binary file not shown.
|
@ -1,11 +1,35 @@
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
import json
|
import json
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
|
||||||
def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler):
|
def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler):
|
||||||
server_address = ("", 8000)
|
server_address = ("", 8000)
|
||||||
httpd = server_class(server_address, WeatherHandler)
|
httpd = server_class(server_address, WeatherHandler)
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
class WeatherHandler(BaseHTTPRequestHandler):
|
class WeatherHandler(BaseHTTPRequestHandler):
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
return self.render(404)
|
return self.weather_handler()
|
||||||
|
|
||||||
|
def weather_handler(self):
|
||||||
|
coordinates = [48.712, 44.514]
|
||||||
|
url = (
|
||||||
|
"https://api.open-meteo.com/v1/forecast?latitude="
|
||||||
|
+ str(coordinates[0])
|
||||||
|
+ "&longitude="
|
||||||
|
+ str(coordinates[1])
|
||||||
|
+ "¤t=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m"
|
||||||
|
)
|
||||||
|
raw_data = urllib.request.urlopen(url).read()
|
||||||
|
print(raw_data)
|
||||||
|
return self.render(200, raw_data)
|
||||||
|
|
||||||
|
def render(self, response_code: int, response_body: dict | None = None):
|
||||||
|
self.send_response(response_code)
|
||||||
|
if response_body is not None:
|
||||||
|
self.send_header("Content-type", "application/json")
|
||||||
|
self.end_headers()
|
||||||
|
if response_body is not None:
|
||||||
|
self.wfile.write(response_body)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user