This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / 2configs / services / radio / weather.nix
2.0 kB 60 lines
1{ config, lib, pkgs, ... }: 2let 3 weather_for_ips = pkgs.writers.writePython3Bin "weather_for_ips" { 4 libraries = [ pkgs.python3Packages.geoip2 ]; 5 flakeIgnore = [ "E501" ]; 6 } ./weather_for_ips.py; 7 8 weather_report = pkgs.writers.writeDashBin "weather_report" '' 9 set -efux 10 export PATH="${lib.makeBinPath [ 11 pkgs.coreutils 12 pkgs.curl 13 pkgs.jq 14 ]}" 15 curl -fSsz /tmp/GeoLite2-City.mmdb -o /tmp/GeoLite2-City.mmdb http://c.r/GeoLite2-City.mmdb 16 MAXMIND_GEOIP_DB="/tmp/GeoLite2-City.mmdb"; export MAXMIND_GEOIP_DB 17 OPENWEATHER_API_KEY=$(cat "$CREDENTIALS_DIRECTORY/openweather_api"); export OPENWEATHER_API_KEY 18 ( 19 curl -sS 'http://admin:hackme@localhost:8000/admin/listclients.json?mount=/radio.ogg' 20 curl -sS 'http://admin:hackme@localhost:8000/admin/listclients.json?mount=/radio.mp3' 21 curl -sS 'http://admin:hackme@localhost:8000/admin/listclients.json?mount=/radio.opus' 22 ) | jq -rs ' 23 [ 24 .[][].source|values|to_entries[].value | 25 (.listener//[]) [] | 26 (.useragent | capture("client-ip=(?<ip>[a-f0-9.:]+)")).ip // .ip 27 ] | 28 unique[] | 29 select(. != "127.0.0.1") | 30 select(. != "::1") 31 ' | 32 ${weather_for_ips}/bin/weather_for_ips 33 ''; 34in { 35 systemd.services.weather = { 36 path = [ 37 weather_report 38 pkgs.retry 39 pkgs.jq 40 pkgs.curl 41 ]; 42 script = '' 43 set -xefu 44 retry -t 5 -d 10 -- weather_report | 45 jq \ 46 --arg from "$(date -u +'%FT%TZ')" \ 47 --arg to "$(date -u +'%FT%TZ' -d '+1 hours')" \ 48 --slurp --raw-input --compact-output --ascii-output \ 49 '{text: ., from: $from, to: $to, priority: 100}' | 50 retry -t 5 -d 10 -- curl -fSs -d@- http://radio-news.r 51 ''; 52 startAt = "*:58:00"; 53 serviceConfig = { 54 User = "radio-news"; 55 LoadCredential = [ 56 "openweather_api:${config.krebs.secret.directory}/openweather_api_key" 57 ]; 58 }; 59 }; 60}