summaryrefslogtreecommitdiffstats
path: root/lass/2configs/radio
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2023-01-06 12:17:36 +0100
committertv <tv@krebsco.de>2023-01-06 12:17:36 +0100
commit2cd5ed169963725cabda22635f5b4439be5e9ad0 (patch)
treebc11f3954b96f2fad2349661a1e8c4569ea84160 /lass/2configs/radio
parent221d5dc01244ffce0c14426e90b76f392d4c5dfa (diff)
parent0b2952f4ed9572521f7c4a21904943ac33c602b0 (diff)
Merge remote-tracking branch 'prism/master'
Diffstat (limited to 'lass/2configs/radio')
-rw-r--r--lass/2configs/radio/default.nix10
-rw-r--r--lass/2configs/radio/radio.liq6
-rw-r--r--lass/2configs/radio/weather.nix13
-rw-r--r--lass/2configs/radio/weather_for_ips.py49
4 files changed, 46 insertions, 32 deletions
diff --git a/lass/2configs/radio/default.nix b/lass/2configs/radio/default.nix
index dfb3d7e0..46540969 100644
--- a/lass/2configs/radio/default.nix
+++ b/lass/2configs/radio/default.nix
@@ -3,7 +3,7 @@
let
name = "radio";
- music_dir = "/home/radio/music";
+ music_dir = "/var/music";
skip_track = pkgs.writers.writeBashBin "skip_track" ''
set -eu
@@ -303,10 +303,10 @@ in {
'';
};
services.syncthing.declarative.folders."the_playlist" = {
- path = "/home/radio/music/the_playlist";
+ path = "/var/music/the_playlist";
devices = [ "mors" "phone" "prism" "omo" ];
};
- krebs.acl."/home/radio/music/the_playlist"."u:syncthing:X".parents = true;
- krebs.acl."/home/radio/music/the_playlist"."u:syncthing:rwX" = {};
- krebs.acl."/home/radio/music/the_playlist"."u:radio:rwX" = {};
+ krebs.acl."/var/music/the_playlist"."u:syncthing:X".parents = true;
+ krebs.acl."/var/music/the_playlist"."u:syncthing:rwX" = {};
+ krebs.acl."/var/music/the_playlist"."u:radio:rwX" = {};
}
diff --git a/lass/2configs/radio/radio.liq b/lass/2configs/radio/radio.liq
index 70d31604..1366287a 100644
--- a/lass/2configs/radio/radio.liq
+++ b/lass/2configs/radio/radio.liq
@@ -10,7 +10,7 @@ def stringify_attrs(attrs) =
out
end
-def filter_graveyard(req) =
+def filter_music(req) =
filename = request.filename(req)
if string.match(pattern = '.*/\\.graveyard/.*', filename) then
false
@@ -27,7 +27,7 @@ end
env = environment()
port = string.to_int(env["RADIO_PORT"], default = 8000)
-all_music = playlist(env["MUSIC"], check_next = filter_graveyard)
+all_music = playlist(env["MUSIC"], check_next = filter_music)
wishlist = request.queue()
tracks = fallback(track_sensitive = true, [wishlist, all_music])
tracks = blank.eat(tracks)
@@ -36,7 +36,7 @@ last_metadata = ref([])
def on_metadata(m) =
last_metadata := m
print("changing tracks")
- out = process.read(env["HOOK_TRACK_CHANGE"], env = m)
+ out = process.read(env["HOOK_TRACK_CHANGE"], env = m, timeout = 5.0)
print(out)
end
tracks.on_metadata(on_metadata)
diff --git a/lass/2configs/radio/weather.nix b/lass/2configs/radio/weather.nix
index 704bf721..ad96d8ec 100644
--- a/lass/2configs/radio/weather.nix
+++ b/lass/2configs/radio/weather.nix
@@ -18,11 +18,14 @@ let
MAXMIND_GEOIP_DB="/tmp/GeoLite2-City.mmdb"; export MAXMIND_GEOIP_DB
OPENWEATHER_API_KEY=$(cat "$CREDENTIALS_DIRECTORY/openweather_api"); export OPENWEATHER_API_KEY
ss -no 'sport = :8000' |
- jc --ss | jq -r '.[] |
- select(
- .local_address != "[::ffff:127.0.0.1]"
- and .local_address != "[::1]"
- ) | .peer_address | gsub("[\\[\\]]"; "")
+ jc --ss | jq -r '
+ [
+ .[] |
+ select(
+ .local_address != "[::ffff:127.0.0.1]"
+ and .local_address != "[::1]"
+ ) | .peer_address | gsub("[\\[\\]]"; "")
+ ] | unique[]
' |
${weather_for_ips}/bin/weather_for_ips
'';
diff --git a/lass/2configs/radio/weather_for_ips.py b/lass/2configs/radio/weather_for_ips.py
index 1f8489bd..447c6389 100644
--- a/lass/2configs/radio/weather_for_ips.py
+++ b/lass/2configs/radio/weather_for_ips.py
@@ -3,32 +3,43 @@ import fileinput
import json
import requests
import os
+import random
geoip = geoip2.database.Reader(os.environ['MAXMIND_GEOIP_DB'])
seen = {}
output = []
for ip in fileinput.input():
- location = geoip.city(ip.strip())
- if location.city.geoname_id not in seen:
- seen[location.city.geoname_id] = True
- weather_api_key = os.environ['OPENWEATHER_API_KEY']
- url = (
- f'https://api.openweathermap.org/data/2.5/onecall'
- f'?lat={location.location.latitude}'
- f'&lon={location.location.longitude}'
- f'&appid={weather_api_key}'
- f'&units=metric'
- )
- resp = requests.get(url)
- weather = json.loads(resp.text)
+ if "80.147.140.51" in ip:
output.append(
- f'Weather report for {location.city.name}, {location.country.name}. '
- f'It is {weather["current"]["weather"][0]["description"]} outside '
- f'with a temperature of {weather["current"]["temp"]:.1f} degrees, '
- f'a wind speed of {weather["current"]["wind_speed"]:.1f} meters per second '
- f'and a humidity of {weather["current"]["humidity"]} percent. '
- f'The probability of precipitation is {weather["hourly"][0]["pop"] * 100:.0f} percent. '
+ 'Weather report for c-base, space.'
+ 'It is empty space outside '
+ 'with a temperature of -270 degrees, '
+ 'a lightspeed of 299792 kilometers per second '
+ 'and a humidity of Not a Number percent. '
+ f'The probability of reincarnation is {random.randrange(0, 100)} percent.'
)
+ else:
+ location = geoip.city(ip.strip())
+ if location.city.geoname_id not in seen:
+ seen[location.city.geoname_id] = True
+ weather_api_key = os.environ['OPENWEATHER_API_KEY']
+ url = (
+ f'https://api.openweathermap.org/data/2.5/onecall'
+ f'?lat={location.location.latitude}'
+ f'&lon={location.location.longitude}'
+ f'&appid={weather_api_key}'
+ f'&units=metric'
+ )
+ resp = requests.get(url)
+ weather = json.loads(resp.text)
+ output.append(
+ f'Weather report for {location.city.name}, {location.country.name}. '
+ f'It is {weather["current"]["weather"][0]["description"]} outside '
+ f'with a temperature of {weather["current"]["temp"]:.1f} degrees, '
+ f'a wind speed of {weather["current"]["wind_speed"]:.1f} meters per second '
+ f'and a humidity of {weather["current"]["humidity"]} percent. '
+ f'The probability of precipitation is {weather["hourly"][0]["pop"] * 100:.0f} percent. '
+ )
print('\n'.join(output))