diff --git a/.gitignore b/.gitignore index ed8ebf5..413672f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -__pycache__ \ No newline at end of file +__pycache__ +__data__ \ No newline at end of file diff --git a/data.out b/data.out deleted file mode 100644 index 59d10de..0000000 --- a/data.out +++ /dev/null @@ -1 +0,0 @@ -{"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 index f0a3284..de3fa21 100755 --- a/main.sh +++ b/main.sh @@ -1,3 +1,19 @@ #!/bin/bash +/usr/bin/pwd -curl localhost:8000 > data.out \ No newline at end of file +$str=`/usr/bin/diff --exclude=multi-user.target.wants -r ./services ~/.config/systemd/user` + +echo $str + +# Update daemon files +#/usr/bin/cp -ur ./services/* ~/.config/systemd/user + +# Daemon launching +#/usr/bin/systemctl --user daemon-reload +#/usr/bin/systemctl --user is-active wthrc.service +#/usr/bin/systemctl --user restart wthrc.service + +# Wait for restart +#/usr/bin/sleep 5 + +/usr/bin/curl localhost:8000 > ./__data__/data.out \ No newline at end of file diff --git a/services/wthrc.service b/services/wthrc.service new file mode 100644 index 0000000..3fda3d8 --- /dev/null +++ b/services/wthrc.service @@ -0,0 +1,11 @@ +[Unit] +Description=Weather collection service +After=network.target + +[Service] +Type=simple +ExecStart=/usr/bin/python3 /home/citrullux/ModernOSLabs/src/main.py +Restart=always + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/src/main.py b/src/main.py index aabce6b..cbf7804 100644 --- a/src/main.py +++ b/src/main.py @@ -1,3 +1,3 @@ -from server import run +from server import weather_run -run() +weather_run() diff --git a/src/server.py b/src/server.py index 6b9ef89..2c9e01b 100644 --- a/src/server.py +++ b/src/server.py @@ -4,7 +4,7 @@ import os from weather import weather_handler -def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler): +def weather_run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler): server_address = ("", int(os.getenv("PORT", "8000"))) httpd = server_class(server_address, WeatherHandler) httpd.serve_forever() diff --git a/src/weather.py b/src/weather.py index 65276f2..7de3725 100644 --- a/src/weather.py +++ b/src/weather.py @@ -4,14 +4,27 @@ import urllib.request @cache def weather_handler(date: str): - print(date) + # print(date) + # Request variables + api_link = "https://api.open-meteo.com/v1/forecast?" coordinates = [48.712, 44.514] + weather_values = "temperature_2m,relative_humidity_2m,rain,snowfall,weather_code,wind_speed_10m,wind_direction_10m" + timezone = "Europe/Moscow" + days = "3" url = ( - "https://api.open-meteo.com/v1/forecast?latitude=" + api_link + + "latitude=" + str(coordinates[0]) + "&longitude=" + str(coordinates[1]) - + "¤t=temperature_2m,relative_humidity_2m,rain,snowfall,weather_code,wind_speed_10m,wind_direction_10m&hourly=temperature_2m,relative_humidity_2m,rain,snowfall,weather_code,wind_speed_10m,wind_direction_10m&timezone=Europe/Moscow&forecast_days=3" + + "¤t=" + + weather_values + + "&hourly=" + + weather_values + + "&timezone=" + + timezone + + "&forecast_days=" + + days ) raw_data = urllib.request.urlopen(url).read() return raw_data