1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/configs/bots/celan.nix

85 lines
2.3 KiB
Nix
Raw Normal View History

2022-11-25 11:27:16 +01:00
{
pkgs,
lib,
config,
2022-11-25 11:27:16 +01:00
...
2025-12-27 22:22:54 +01:00
}:
{
2024-10-05 14:42:44 +02:00
niveum.bots.celan = {
2022-11-25 11:27:16 +01:00
enable = true;
time = "08:00";
2024-10-05 14:42:44 +02:00
telegram = {
enable = true;
tokenFile = config.age.secrets.telegram-token-kmein.path;
2025-12-27 22:22:54 +01:00
chatIds = [ "@PaulCelan" ];
2024-10-05 14:42:44 +02:00
};
mastodon = {
enable = true;
tokenFile = config.age.secrets.mastodon-token-celan.path;
language = "de";
};
2025-12-27 22:22:54 +01:00
command = toString (
pkgs.writers.writePython3 "random-celan.py" { libraries = [ pkgs.python3Packages.lxml ]; } ''
from lxml import etree
import random
2024-12-16 17:17:43 +01:00
2025-12-27 22:22:54 +01:00
def xml_text(elements):
return "".join("".join(t.itertext()) for t in elements).strip()
2024-12-16 17:17:43 +01:00
2025-12-27 22:22:54 +01:00
tree = etree.parse('${
pkgs.fetchurl {
url = "http://c.krebsco.de/celan.tei.xml";
hash = "sha256-HgNmJYfhuwyfm+FcNtnnYWpJpIIU1ElHLeLiIFjF9mE=";
}
}')
root = tree.getroot()
2024-12-16 17:17:43 +01:00
2025-12-27 22:22:54 +01:00
tei = {"tei": "http://www.tei-c.org/ns/1.0"}
2024-12-16 17:17:43 +01:00
2025-12-27 22:22:54 +01:00
poems = root.xpath(".//tei:lg[@type='poem']", namespaces=tei)
2024-12-16 17:17:43 +01:00
2025-12-27 22:22:54 +01:00
poem = random.choice(poems)
2024-12-16 17:17:43 +01:00
2025-12-27 22:22:54 +01:00
for stanza in poem.xpath("./tei:lg[@type='stanza']", namespaces=tei):
for line in stanza.xpath('./tei:l', namespaces=tei):
if line.text:
print(line.text.strip())
print()
2024-12-16 17:17:43 +01:00
2025-12-27 22:22:54 +01:00
current_element = poem
while current_element is not None:
if current_element.tag == "{http://www.tei-c.org/ns/1.0}text":
text_element = current_element
2024-12-16 17:17:43 +01:00
2025-12-27 22:22:54 +01:00
title = xml_text(text_element.xpath("./tei:front/tei:docTitle",
namespaces=tei))
print(f"Aus: #{title.replace(" ", "_")}", end=" ")
2024-12-16 17:17:43 +01:00
2025-12-27 22:22:54 +01:00
if date := xml_text(text_element.xpath("./tei:front/tei:docDate",
namespaces=tei)):
print(f"({date})")
break
current_element = current_element.getparent()
2024-12-16 17:17:43 +01:00
2025-12-27 22:22:54 +01:00
print("\n\n#PaulCelan #Celan #Lyrik #poetry")
''
);
2022-11-25 11:27:16 +01:00
};
2024-10-05 14:42:44 +02:00
age.secrets = {
mastodon-token-celan.file = ../../secrets/mastodon-token-celan.age;
};
systemd.timers.bot-celan.timerConfig.RandomizedDelaySec = "10h";
2022-11-25 11:27:16 +01:00
niveum.passport.services = [
{
title = "Paul Celan Bot";
description = "sends a random poem by Paul Celan to Telegram.";
link = "https://t.me/PaulCelan";
}
];
}