This repository has no description
1.8 kB
56 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 (
18 curl -sS 'http://admin:hackme@localhost:8000/admin/listclients.json?mount=/radio.ogg'
19 curl -sS 'http://admin:hackme@localhost:8000/admin/listclients.json?mount=/radio.mp3'
20 curl -sS 'http://admin:hackme@localhost:8000/admin/listclients.json?mount=/radio.opus'
21 ) | jq -rs '
22 [
23 .[][].source|values|to_entries[].value |
24 (.listener//[]) [] |
25 (.useragent | capture("client-ip=(?<ip>[a-f0-9.:]+)")).ip // .ip
26 ] |
27 unique[] |
28 select(. != "127.0.0.1") |
29 select(. != "::1")
30 ' |
31 ${weather_for_ips}/bin/weather_for_ips
32 '';
33in {
34 systemd.services.weather = {
35 path = [
36 weather_report
37 pkgs.retry
38 pkgs.jq
39 pkgs.curl
40 ];
41 script = ''
42 set -xefu
43 retry -t 5 -d 10 -- weather_report |
44 jq \
45 --arg from "$(date -u +'%FT%TZ')" \
46 --arg to "$(date -u +'%FT%TZ' -d '+1 hours')" \
47 --slurp --raw-input --compact-output --ascii-output \
48 '{text: ., from: $from, to: $to, priority: 100}' |
49 retry -t 5 -d 10 -- curl -fSs -d@- http://radio-news.r
50 '';
51 startAt = "*:58:00";
52 serviceConfig = {
53 User = "radio-news";
54 };
55 };
56}