diff --git a/main.sh b/main.sh deleted file mode 100755 index de3fa21..0000000 --- a/main.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -/usr/bin/pwd - -$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/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..693a447 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Update daemon files +/usr/bin/cp -ur $DIR/services/* ~/.config/systemd/user + +# Daemon launch +/usr/bin/systemctl --user daemon-reload +/usr/bin/systemctl --user enable wthrc.service +echo "Done installer" \ No newline at end of file diff --git a/scripts/main.sh b/scripts/main.sh new file mode 100755 index 0000000..27291ad --- /dev/null +++ b/scripts/main.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +/usr/bin/curl localhost:8000 > ./__data__/data.out \ No newline at end of file diff --git a/scripts/runner.sh b/scripts/runner.sh new file mode 100644 index 0000000..dd6c2cc --- /dev/null +++ b/scripts/runner.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Launch daemon +/usr/bin/systemctl --user restart wthrc.service +echo "Done runner" \ No newline at end of file diff --git a/services/wthrc.service b/services/wthrc.service index 3fda3d8..826b857 100644 --- a/services/wthrc.service +++ b/services/wthrc.service @@ -1,11 +1,11 @@ [Unit] Description=Weather collection service -After=network.target [Service] Type=simple +WorkingDirectory=/home/citrullux/ModernOSLabs/src ExecStart=/usr/bin/python3 /home/citrullux/ModernOSLabs/src/main.py Restart=always [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=default.target \ No newline at end of file diff --git a/src/installer.py b/src/installer.py new file mode 100644 index 0000000..27fe690 --- /dev/null +++ b/src/installer.py @@ -0,0 +1,14 @@ +import filecmp +import subprocess +import os +from time import sleep + + +def install(): + projectDir="/home/citrullux/ModernOSLabs" + delivered=filecmp.cmp(projectDir+"/services/wthrc.service", "/home/citrullux/.config/systemd/user/wthrc.service", shallow=True) + if not delivered: + os.environ["DIR"]=projectDir + subprocess.call(["/usr/bin/sh", projectDir+"/scripts/install.sh"]) + subprocess.call(["/usr/bin/sh", projectDir+"/scripts/runner.sh"]) + sleep(5) diff --git a/src/main.py b/src/main.py index cbf7804..9c79418 100644 --- a/src/main.py +++ b/src/main.py @@ -1,3 +1,5 @@ from server import weather_run +from installer import install +install() weather_run() diff --git a/src/weather.py b/src/weather.py index 7de3725..8b2391e 100644 --- a/src/weather.py +++ b/src/weather.py @@ -3,7 +3,7 @@ import urllib.request @cache -def weather_handler(date: str): +def weather_handler(date: str) -> dict: # print(date) # Request variables api_link = "https://api.open-meteo.com/v1/forecast?" @@ -26,5 +26,5 @@ def weather_handler(date: str): + "&forecast_days=" + days ) - raw_data = urllib.request.urlopen(url).read() + raw_data = urllib.request.urlopen(url, timeout=10).read() return raw_data