Last active
May 29, 2020 15:59
-
-
Save bonelifer/036486e577e02342308485febeb1bb28 to your computer and use it in GitHub Desktop.
WXForcast SystemD files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WXFORECAST_PUSHOVER_APP_KEY=randomAPPKey | |
WXFORECAST_COORDINATES=31.02,-90.56 | |
PUSHOVER_DEVICE=weather | |
PUSHOVER_USER_KEY=randomGroupKey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
● wxforecast.service - Send Weather Update | |
Loaded: loaded (/etc/systemd/system/wxforecast.service; static; vendor preset: enabled) | |
Active: failed (Result: exit-code) since Fri 2020-05-29 07:00:24 CDT; 3h 56min ago | |
Process: 31417 ExecStopPost=/bin/bash /usr/local/bin/sus.sh (code=exited, status=0/SUCCESS) | |
Process: 31287 ExecStart=/usr/bin/python3 /home/william/CODE/wxforecast/wxforecast.py (code=exited, status=1/FAILURE) | |
Main PID: 31287 (code=exited, status=1/FAILURE) | |
May 29 07:00:24 william python3[31287]: File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 646, in send | |
May 29 07:00:24 william python3[31287]: r = adapter.send(request, **kwargs) | |
May 29 07:00:24 william python3[31287]: File "/usr/local/lib/python3.6/dist-packages/requests/adapters.py", line 516, in send | |
May 29 07:00:24 william python3[31287]: raise ConnectionError(e, request=request) | |
May 29 07:00:24 william python3[31287]: requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.weather.gov', port=443): Max retries exceeded with url: /points/35.0 | |
May 29 07:00:24 william systemd[1]: wxforecast.service: Main process exited, code=exited, status=1/FAILURE | |
May 29 07:00:24 william sudo[31424]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/systemctl suspend | |
May 29 07:00:24 william sudo[31424]: pam_unix(sudo:session): session opened for user root by (uid=0) | |
May 29 07:00:24 william sudo[31424]: pam_unix(sudo:session): session closed for user root | |
May 29 07:00:24 william systemd[1]: wxforecast.service: Failed with result 'exit-code'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
● wxforecast.timer - Send Weather Update | |
Loaded: loaded (/etc/systemd/system/wxforecast.timer; enabled; vendor preset: enabled) | |
Active: active (waiting) since Sun 2020-05-24 18:33:02 CDT; 4 days ago | |
Trigger: Sat 2020-05-30 07:00:00 CDT; 20h left |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/usr/bin/sudo /bin/systemctl suspend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## https://github.com/stacybrock/wxforecast | |
import os | |
import nwswx | |
import requests | |
(LAT, LON) = [c.strip() for c in os.getenv('WXFORECAST_COORDINATES', | |
'39.0693,-94.6716').split(',')] | |
def main(): | |
nws = nwswx.WxAPI('[wxforecast] brock@oregonstate.edu') | |
result = nws.point_forecast(LAT, LON, return_format=nwswx.formats.JSONLD) | |
forecast = result['periods'][0] | |
# create pushover notification | |
title = f"{forecast['shortForecast']}" | |
msg = f"""{forecast['detailedForecast']} | |
Temp: {forecast['temperature']}°{forecast['temperatureUnit']} | |
Wind: {forecast['windSpeed']} {forecast['windDirection']} | |
Details: https://forecast.weather.gov/MapClick.php?lon={LON}&lat={LAT} | |
""" | |
r = requests.post('https://api.pushover.net/1/messages.json', data = { | |
'token': os.environ['WXFORECAST_PUSHOVER_APP_KEY'], | |
'user': os.environ['PUSHOVER_USER_KEY'], | |
'message': msg, | |
'title': title, | |
'device': os.environ['PUSHOVER_DEVICE'] | |
}) | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Send Weather Update | |
Wants=network-online.target | |
After=network-online.target | |
[Service] | |
Type=simple | |
Environment="WXFORECAST_PUSHOVER_APP_KEY=RandomAppKEY" | |
Environment="WXFORECAST_COORDINATES=31.02,-90.56" | |
Environment="PUSHOVER_DEVICE=weather" | |
Environment="PUSHOVER_USER_KEY=randomUserGroupKey" | |
ExecStart=/usr/bin/python3 /home/william/CODE/wxforecast/wxforecast.py | |
ExecStopPost=/bin/bash /usr/local/bin/sus.sh | |
StandardError=journal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Send Weather Update | |
[Timer] | |
OnCalendar=*-*-* 07:00:00 | |
Persistent=true | |
WakeSystem=true | |
Unit=wxforecast.service | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
per online instructions service file is place but not enabled. timer file is enabled.