From 8402acd68c7f3d0e834fa78dbde5f07630573add 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 11:23:33 +0300 Subject: [PATCH] add: gitignore --- .gitignore | 1 + data.out | 1 + main.sh | 1 + src/__pycache__/server.cpython-310.pyc | Bin 1887 -> 1367 bytes src/server.py | 23 +++-------------------- src/weather.py | 16 ++++++++++++++++ 6 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 .gitignore create mode 100644 data.out mode change 100644 => 100755 main.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/data.out b/data.out new file mode 100644 index 0000000..59d10de --- /dev/null +++ b/data.out @@ -0,0 +1 @@ +{"latitude":48.6875,"longitude":44.5,"generationtime_ms":0.1379251480102539,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":50.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C","wind_speed_10m":"km/h"},"current":{"time":"2024-09-09T08:15","interval":900,"temperature_2m":25.0,"wind_speed_10m":15.0},"hourly_units":{"time":"iso8601","temperature_2m":"°C","relative_humidity_2m":"%","wind_speed_10m":"km/h"},"hourly":{"time":["2024-09-09T00:00","2024-09-09T01:00","2024-09-09T02:00","2024-09-09T03:00","2024-09-09T04:00","2024-09-09T05:00","2024-09-09T06:00","2024-09-09T07:00","2024-09-09T08:00","2024-09-09T09:00","2024-09-09T10:00","2024-09-09T11:00","2024-09-09T12:00","2024-09-09T13:00","2024-09-09T14:00","2024-09-09T15:00","2024-09-09T16:00","2024-09-09T17:00","2024-09-09T18:00","2024-09-09T19:00","2024-09-09T20:00","2024-09-09T21:00","2024-09-09T22:00","2024-09-09T23:00","2024-09-10T00:00","2024-09-10T01:00","2024-09-10T02:00","2024-09-10T03:00","2024-09-10T04:00","2024-09-10T05:00","2024-09-10T06:00","2024-09-10T07:00","2024-09-10T08:00","2024-09-10T09:00","2024-09-10T10:00","2024-09-10T11:00","2024-09-10T12:00","2024-09-10T13:00","2024-09-10T14:00","2024-09-10T15:00","2024-09-10T16:00","2024-09-10T17:00","2024-09-10T18:00","2024-09-10T19:00","2024-09-10T20:00","2024-09-10T21:00","2024-09-10T22:00","2024-09-10T23:00","2024-09-11T00:00","2024-09-11T01:00","2024-09-11T02:00","2024-09-11T03:00","2024-09-11T04:00","2024-09-11T05:00","2024-09-11T06:00","2024-09-11T07:00","2024-09-11T08:00","2024-09-11T09:00","2024-09-11T10:00","2024-09-11T11:00","2024-09-11T12:00","2024-09-11T13:00","2024-09-11T14:00","2024-09-11T15:00","2024-09-11T16:00","2024-09-11T17:00","2024-09-11T18:00","2024-09-11T19:00","2024-09-11T20:00","2024-09-11T21:00","2024-09-11T22:00","2024-09-11T23:00","2024-09-12T00:00","2024-09-12T01:00","2024-09-12T02:00","2024-09-12T03:00","2024-09-12T04:00","2024-09-12T05:00","2024-09-12T06:00","2024-09-12T07:00","2024-09-12T08:00","2024-09-12T09:00","2024-09-12T10:00","2024-09-12T11:00","2024-09-12T12:00","2024-09-12T13:00","2024-09-12T14:00","2024-09-12T15:00","2024-09-12T16:00","2024-09-12T17:00","2024-09-12T18:00","2024-09-12T19:00","2024-09-12T20:00","2024-09-12T21:00","2024-09-12T22:00","2024-09-12T23:00","2024-09-13T00:00","2024-09-13T01:00","2024-09-13T02:00","2024-09-13T03:00","2024-09-13T04:00","2024-09-13T05:00","2024-09-13T06:00","2024-09-13T07:00","2024-09-13T08:00","2024-09-13T09:00","2024-09-13T10:00","2024-09-13T11:00","2024-09-13T12:00","2024-09-13T13:00","2024-09-13T14:00","2024-09-13T15:00","2024-09-13T16:00","2024-09-13T17:00","2024-09-13T18:00","2024-09-13T19:00","2024-09-13T20:00","2024-09-13T21:00","2024-09-13T22:00","2024-09-13T23:00","2024-09-14T00:00","2024-09-14T01:00","2024-09-14T02:00","2024-09-14T03:00","2024-09-14T04:00","2024-09-14T05:00","2024-09-14T06:00","2024-09-14T07:00","2024-09-14T08:00","2024-09-14T09:00","2024-09-14T10:00","2024-09-14T11:00","2024-09-14T12:00","2024-09-14T13:00","2024-09-14T14:00","2024-09-14T15:00","2024-09-14T16:00","2024-09-14T17:00","2024-09-14T18:00","2024-09-14T19:00","2024-09-14T20:00","2024-09-14T21:00","2024-09-14T22:00","2024-09-14T23:00","2024-09-15T00:00","2024-09-15T01:00","2024-09-15T02:00","2024-09-15T03:00","2024-09-15T04:00","2024-09-15T05:00","2024-09-15T06:00","2024-09-15T07:00","2024-09-15T08:00","2024-09-15T09:00","2024-09-15T10:00","2024-09-15T11:00","2024-09-15T12:00","2024-09-15T13:00","2024-09-15T14:00","2024-09-15T15:00","2024-09-15T16:00","2024-09-15T17:00","2024-09-15T18:00","2024-09-15T19:00","2024-09-15T20:00","2024-09-15T21:00","2024-09-15T22:00","2024-09-15T23:00"],"temperature_2m":[14.8,14.4,14.1,13.9,15.2,17.3,19.7,22.4,24.7,25.7,26.3,27.2,27.2,26.6,26.1,25.1,22.1,21.4,20.7,18.9,18.6,18.6,18.6,18.6,18.2,18.1,17.9,17.6,17.8,18.9,20.4,22.5,24.4,26.0,26.8,27.5,27.6,26.0,24.9,23.4,22.2,21.1,20.4,19.7,19.1,18.7,18.4,18.2,17.8,17.5,17.2,17.1,17.5,18.8,20.3,22.8,25.1,26.7,28.0,28.4,28.8,28.6,27.9,26.5,24.9,23.9,23.1,22.4,21.4,20.4,19.4,18.5,17.5,16.7,16.3,16.1,17.0,18.8,20.9,22.7,24.6,26.2,27.4,28.2,28.6,28.3,27.5,26.5,25.4,24.2,23.0,22.0,21.1,20.1,19.1,18.1,17.2,16.5,16.0,16.1,17.1,18.7,20.5,22.7,25.2,27.1,28.1,28.6,28.6,28.1,27.1,26.0,24.6,23.1,21.7,20.7,20.0,19.2,18.3,17.4,16.7,16.1,15.6,15.7,17.0,19.0,21.0,23.0,25.1,26.9,28.3,29.3,29.6,28.9,27.5,26.0,24.3,22.4,20.8,19.6,18.6,17.7,16.8,15.9,15.2,14.7,14.3,14.7,16.3,18.5,20.7,22.8,24.7,26.2,26.9,27.0,26.8,26.1,25.0,23.8,22.4,21.0,19.7,18.9,18.2,17.5,16.5,15.6],"relative_humidity_2m":[59,61,62,62,56,47,38,29,24,26,27,26,27,28,29,33,49,49,55,68,70,68,69,69,69,67,66,64,63,56,50,42,37,31,30,29,29,34,37,43,44,50,51,53,53,56,60,62,63,64,65,65,63,57,52,44,37,32,27,26,24,23,26,30,35,38,39,40,43,46,48,51,56,59,59,59,54,46,41,37,33,30,27,24,23,23,25,27,30,33,36,38,40,43,47,51,55,58,61,61,57,51,44,38,32,27,24,23,23,24,26,29,32,37,40,42,44,46,49,53,55,56,57,56,52,47,42,38,35,32,29,26,24,24,26,27,28,29,31,34,38,42,47,52,56,59,60,59,54,47,41,36,31,27,25,24,24,25,26,28,31,35,38,40,43,45,48,51],"wind_speed_10m":[4.1,4.0,4.6,4.5,5.6,7.9,9.1,10.9,14.5,16.3,16.5,17.8,17.6,15.6,13.5,10.2,7.4,3.3,5.0,6.5,3.8,5.2,6.7,8.4,7.7,8.0,9.5,8.7,10.2,13.8,14.8,16.9,17.2,17.4,18.7,19.3,19.3,18.4,20.8,9.7,8.4,7.2,5.6,6.5,6.5,6.9,6.5,7.3,7.6,8.0,7.8,6.6,6.9,9.1,9.7,12.6,15.1,16.1,17.4,17.1,17.4,17.2,15.8,12.1,11.5,12.6,12.3,12.0,9.8,7.6,7.5,6.9,6.6,7.0,7.3,6.8,8.3,9.9,11.9,13.1,14.3,15.5,17.0,18.9,19.7,18.5,16.2,14.6,14.4,14.8,14.8,13.0,10.8,8.6,6.9,6.1,6.1,6.4,7.2,8.2,9.4,10.9,12.4,13.7,15.8,17.5,17.8,17.4,16.2,13.7,10.6,8.6,8.4,8.4,8.5,8.0,7.6,6.9,5.7,4.8,4.5,8.5,8.7,9.8,12.3,15.2,17.9,19.8,21.5,22.9,23.2,23.6,23.3,22.6,21.3,20.4,18.6,16.3,14.5,13.6,13.4,13.2,11.8,10.4,9.7,10.4,11.9,13.3,14.8,16.6,18.7,21.5,25.4,28.1,28.6,27.6,25.7,22.9,19.5,16.6,14.9,14.1,13.3,12.3,11.4,10.8,10.2,10.1]}} \ No newline at end of file diff --git a/main.sh b/main.sh old mode 100644 new mode 100755 index e69de29..11878b4 --- a/main.sh +++ b/main.sh @@ -0,0 +1 @@ +curl localhost:8000 > data.out \ No newline at end of file diff --git a/src/__pycache__/server.cpython-310.pyc b/src/__pycache__/server.cpython-310.pyc index 7a4ab02fc69beb1ad9a26f59a91e5c16abbbb5d4..016e5a6b86d85aa2a77406d761cbe92cbc7fa405 100644 GIT binary patch delta 275 zcmcc5cb$tbpO=@50SNZ5yO%bVc_N<-qt`@jNw-|)C}u{66owS$9F|ROVEs zG^P}m6xJ5TC^mP76t)!h7KRk|RHkO;DE1VNUWaduXsxA!V z@|UM3mSm(B#b+eurR1a*O}u-Vk!|uu#>0%flS`TUSc_PJ+9r!I8#4-Q_F(2^l#>GT zi=;sWFPz{5vBZId=;UISyva)J5^P26KrYYZ|16>=ewrLbOhDc(?u?R>0=?qYqO#PY nB4&^t7LYJI)Cpj#iugg|?30z*)%ZZ3=V1_FW%3W$Sc)KMWhGb$TWDpG%6~wOGnbem1MfHQ{pL3_Z{C}4xgVucR4nEcG4Px3 zokSa#8pt2tst=Ju6{`AbKx`6dwl;~0uiLudiEr2@Xh1rcYE<7t_S9pA8r0lVs0n1G z+Bv{<3i4t-NAr7RgzN$(&lIb0B=53NW>SX(_W}^U<~nWH|xE;d`k1_PSa`S1yZlSwlkc3`)|Q5l~B4 zNr-0B_oOkDWNZpB6%(0iLt}=N)djdn!2dynBkiHEctrqL2FeJDLLiE}co$KXqXD9% zF4&qvwVE=C_0!m>DZ7~C4fTKw@F6Dl`p+-dp06x*qw46x=Le6L zcIJAV_v3|D%jtW~s1Mpj6AFt=X1kN0^`o$R!W>PQ z^;tJz3_`xhA?O2hc*3B4H@Lm!g|t14`v9~(KNrmQqJ;U|=T!{k4V%#JC4omhzJ0d! zY^SAXTAz6#&(xT+Oc%%a-pkBj@G60rXNDl;3o^pMp%$4GH_N+G#OTlqMd#y86&iL) zyx@GlYJ$5eESAkQv57FwA$*K6{+mRSt85UDE)k#8^N0A>hRmOQ) z&1MX26Bv_iWSXSO#*H`%v(ib%&C`V0O(`f#nEVAxc2$w KD>|-TME?L>uGM=0 diff --git a/src/server.py b/src/server.py index 8561a08..6b9ef89 100644 --- a/src/server.py +++ b/src/server.py @@ -1,12 +1,11 @@ from datetime import datetime -from functools import cache from http.server import BaseHTTPRequestHandler, HTTPServer -import json -import urllib.request +import os +from weather import weather_handler def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler): - server_address = ("", 8000) + server_address = ("", int(os.getenv("PORT", "8000"))) httpd = server_class(server_address, WeatherHandler) httpd.serve_forever() @@ -27,19 +26,3 @@ class WeatherHandler(BaseHTTPRequestHandler): self.end_headers() if response_body is not None: self.wfile.write(response_body) - - -@cache -def weather_handler(date: str): - print(date) - 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 raw_data diff --git a/src/weather.py b/src/weather.py index e69de29..6746b13 100644 --- a/src/weather.py +++ b/src/weather.py @@ -0,0 +1,16 @@ +from functools import cache +import urllib.request + +@cache +def weather_handler(date: str): + print(date) + 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() + return raw_data \ No newline at end of file