refactor: weather API request changes
This commit is contained in:
parent
37ee688096
commit
0f49adebe1
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
__pycache__
|
__pycache__
|
||||||
|
__data__
|
18
main.sh
18
main.sh
|
@ -1,3 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
/usr/bin/pwd
|
||||||
|
|
||||||
curl localhost:8000 > data.out
|
$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
|
11
services/wthrc.service
Normal file
11
services/wthrc.service
Normal file
|
@ -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
|
|
@ -1,3 +1,3 @@
|
||||||
from server import run
|
from server import weather_run
|
||||||
|
|
||||||
run()
|
weather_run()
|
||||||
|
|
|
@ -4,7 +4,7 @@ import os
|
||||||
from weather import weather_handler
|
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")))
|
server_address = ("", int(os.getenv("PORT", "8000")))
|
||||||
httpd = server_class(server_address, WeatherHandler)
|
httpd = server_class(server_address, WeatherHandler)
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
|
@ -4,14 +4,27 @@ import urllib.request
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def weather_handler(date: str):
|
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]
|
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 = (
|
url = (
|
||||||
"https://api.open-meteo.com/v1/forecast?latitude="
|
api_link
|
||||||
|
+ "latitude="
|
||||||
+ str(coordinates[0])
|
+ str(coordinates[0])
|
||||||
+ "&longitude="
|
+ "&longitude="
|
||||||
+ str(coordinates[1])
|
+ 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()
|
raw_data = urllib.request.urlopen(url).read()
|
||||||
return raw_data
|
return raw_data
|
||||||
|
|
Loading…
Reference in New Issue
Block a user