summaryrefslogtreecommitdiffstats
path: root/lass/2configs/services/radio/weather.nix
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2023-09-09 19:42:08 +0200
committermakefu <github@syntax-fehler.de>2023-09-09 19:42:08 +0200
commit29d72c898d674d2c18fc0f4a76b5e623de0c3dfe (patch)
treefc4b0695c986a1cda6f1fbbbcbe716e203c54fa3 /lass/2configs/services/radio/weather.nix
parente157ffa72856e4378aa23b096b2efff233f3cb3d (diff)
parent083229d0211096daec08673f743ccc45b1d8a0ac (diff)
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'lass/2configs/services/radio/weather.nix')
-rw-r--r--lass/2configs/services/radio/weather.nix60
1 files changed, 0 insertions, 60 deletions
diff --git a/lass/2configs/services/radio/weather.nix b/lass/2configs/services/radio/weather.nix
deleted file mode 100644
index dca8a7843..000000000
--- a/lass/2configs/services/radio/weather.nix
+++ /dev/null
@@ -1,60 +0,0 @@
-{ config, lib, pkgs, ... }:
-let
- weather_for_ips = pkgs.writers.writePython3Bin "weather_for_ips" {
- libraries = [ pkgs.python3Packages.geoip2 ];
- flakeIgnore = [ "E501" ];
- } ./weather_for_ips.py;
-
- weather_report = pkgs.writers.writeDashBin "weather_report" ''
- set -efux
- export PATH="${lib.makeBinPath [
- pkgs.coreutils
- pkgs.curl
- pkgs.jq
- ]}"
- curl -fSsz /tmp/GeoLite2-City.mmdb -o /tmp/GeoLite2-City.mmdb http://c.r/GeoLite2-City.mmdb
- MAXMIND_GEOIP_DB="/tmp/GeoLite2-City.mmdb"; export MAXMIND_GEOIP_DB
- OPENWEATHER_API_KEY=$(cat "$CREDENTIALS_DIRECTORY/openweather_api"); export OPENWEATHER_API_KEY
- (
- curl -sS 'http://admin:hackme@localhost:8000/admin/listclients.json?mount=/radio.ogg'
- curl -sS 'http://admin:hackme@localhost:8000/admin/listclients.json?mount=/radio.mp3'
- curl -sS 'http://admin:hackme@localhost:8000/admin/listclients.json?mount=/radio.opus'
- ) | jq -rs '
- [
- .[][].source|values|to_entries[].value |
- (.listener//[]) [] |
- (.useragent | capture("client-ip=(?<ip>[a-f0-9.:]+)")).ip // .ip
- ] |
- unique[] |
- select(. != "127.0.0.1") |
- select(. != "::1")
- ' |
- ${weather_for_ips}/bin/weather_for_ips
- '';
-in {
- systemd.services.weather = {
- path = [
- weather_report
- pkgs.retry
- pkgs.jq
- pkgs.curl
- ];
- script = ''
- set -xefu
- retry -t 5 -d 10 -- weather_report |
- jq \
- --arg from "$(date -u +'%FT%TZ')" \
- --arg to "$(date -u +'%FT%TZ' -d '+1 hours')" \
- --slurp --raw-input --compact-output --ascii-output \
- '{text: ., from: $from, to: $to, priority: 100}' |
- retry -t 5 -d 10 -- curl -fSs -d@- http://radio-news.r
- '';
- startAt = "*:58:00";
- serviceConfig = {
- User = "radio-news";
- LoadCredential = [
- "openweather_api:${toString <secrets>}/openweather_api_key"
- ];
- };
- };
-}