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