From 2be0fe6ec57e79cd4844187153d7740711ba17ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=90=D0=B1?= =?UTF-8?q?=D0=B4=D1=80=D0=B0=D1=85=D0=BC=D0=B0=D0=BD=D0=BE=D0=B2?= <565963@gmail.com> Date: Mon, 9 Sep 2024 10:46:04 +0300 Subject: [PATCH] fix: results provided --- src/__pycache__/server.cpython-310.pyc | Bin 2188 -> 1617 bytes src/server.py | 26 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/__pycache__/server.cpython-310.pyc b/src/__pycache__/server.cpython-310.pyc index 22ab8e30648cf613d99d0233b02a968c498f319f..66b0a0ba22e35175aec8239176f5a661d48c2427 100644 GIT binary patch literal 1617 zcmZuyOK%)S5bnp!>|`JIf(RBUBoYTpi^y&g<%9?rM-U%iiLfQ4gSGs#* zyxKk4KVCh3?7E}T<3@}3ak3h$H%Ptp@U zY6!MVdW|zUhxC|zdpp!}XK(N6H}ZKYwb=Jdk+nPUULtTN#>(R2MEf8jlagxsu?e=h$|oP(hT0 zTHDT~4rL{-trkNel!Rq>VoV`k64inj{`g=p$x}IqVx!6=DZd|ll?$n|uXn!;_w_)l zXi%H?i(|`GnRysJ5{EWvo2m}55zH$C*SBEmhd?A5Q9(vbP{B?KBpcI9MviDgVqMXY zo^ZFx*b%vT}VJnxnLSmAQuC9%x9H9AD9_gkR@d6B^~ytT|cUm6s&F!Do4v? zTwSv!Z7{N)$b%=J?_t~;kMrsD=GFZ6>m65|WASiS&YuEe;QD!3stDx7!73EhB( z*&vndt>nfAnKMHV*@Dm5k}jMjnRDaL_z9(W0Z;fdzQo45F+A9Q_WP^%zuVb5$lpBq z>6g#G*qYwMTIr7lgRqGEc_FjAsWdY0M|nDUaesgv5QW-&nuI1crI3#lW@*~mO!DlY z)|^$EXPZ%}l+4T{Bhx~v(3DCB57G~h;!Fg(kWvKq@1>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xANhZg=Toix_O!0y|cd#yE21MLm=!k_9}8>8nM~to|WTkx_6rGeccAP zld^z1ham9O^q}O&Lj%#O8QVj*ko938cv90Pr2vPMDV68op@yd=gUx61+oRom)#B4+F9WRhpYRApt+ds3Cf%$usw_VsS4A=ZK? ztE=lZJ3SOB(9&yWsj(s2=c6nac*sl%?V3}x$EV{7k^yOlkh_k&gkaF&6ss4dlfRn?gkB6OlMclCe14TRid6LDFzO6PfN0ql*tbiZd6{ebpLk$nO!;?*y(!IrTuQC!z3xvu}Bgf zCCRwt)7;o`l02KHd9xx-R>(CB;5i#Adn@gLPib(L=KH4zu(va{%2wlZFe>wp55dEQ zxD&=3*57S6>R2;>n;oMgA*Crj_NOHcdC~-~WBf_;>|n>1L#wT(wnnc>%0y*lV}CLB c=>NNm4sSHUeQD^kl`|&mHo@0TqC1=ZzbknT(f|Me diff --git a/src/server.py b/src/server.py index 0811aae..3cb25cb 100644 --- a/src/server.py +++ b/src/server.py @@ -1,11 +1,35 @@ from http.server import BaseHTTPRequestHandler, HTTPServer import json +import urllib.request + def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler): server_address = ("", 8000) httpd = server_class(server_address, WeatherHandler) httpd.serve_forever() + class WeatherHandler(BaseHTTPRequestHandler): def do_GET(self): - return self.render(404) \ No newline at end of file + 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)