1
0
mirror of https://github.com/kmein/niveum synced 2026-03-21 20:31:07 +01:00

tlg-wotd: also post on mastodon

This commit is contained in:
2024-10-04 17:07:06 +02:00
parent 1e74d0470c
commit 729f1180b7
3 changed files with 58 additions and 42 deletions

View File

@@ -22,8 +22,6 @@ in {
command = "${autorenkalender}/bin/autorenkalender"; command = "${autorenkalender}/bin/autorenkalender";
}; };
age.secrets.telegram-token-kmein.file = ../../secrets/telegram-token-kmein.age;
niveum.passport.services = [ niveum.passport.services = [
{ {
title = "Autorenkalender"; title = "Autorenkalender";

View File

@@ -19,7 +19,8 @@
chat_id=@tlgwotd chat_id=@tlgwotd
export TOKEN="$(cat "$CREDENTIALS_DIRECTORY/token")" export TELEGRAM_TOKEN="$(cat "$CREDENTIALS_DIRECTORY/telegram-token")"
export MASTODON_TOKEN="$(cat "$CREDENTIALS_DIRECTORY/mastodon-token")"
json_data=$(curl -sSL http://stephanus.tlg.uci.edu/Iris/Wotd | recode html..utf8) json_data=$(curl -sSL http://stephanus.tlg.uci.edu/Iris/Wotd | recode html..utf8)
@@ -28,6 +29,10 @@
definition=$(echo "$json_data" | jq -r '.definition | sub("<.*>"; "") | rtrimstr(" ")') definition=$(echo "$json_data" | jq -r '.definition | sub("<.*>"; "") | rtrimstr(" ")')
first_occurrence=$(echo "$json_data" | jq -r '.firstOccurrence') first_occurrence=$(echo "$json_data" | jq -r '.firstOccurrence')
total_occurrences=$(echo "$json_data" | jq -r '.totalOccurrences') total_occurrences=$(echo "$json_data" | jq -r '.totalOccurrences')
caption="*$word* $definition
First occurrence (century): $first_occurrence
Number of occurrences (in all Ancient Greek texts): $total_occurrences"
transliteration=$(${pkgs.writers.writePython3 "translit.py" { transliteration=$(${pkgs.writers.writePython3 "translit.py" {
libraries = [ niveumPackages.cltk ]; libraries = [ niveumPackages.cltk ];
@@ -105,26 +110,39 @@
-annotate +100+60 "$(date -I)" \ -annotate +100+60 "$(date -I)" \
"$photo_path" "$photo_path"
ls -la /tmp
curl -X POST "https://api.telegram.org/bot$TOKEN/sendPhoto" \ curl -X POST "https://api.telegram.org/bot$TOKEN/sendPhoto" \
-F "chat_id=\"$chat_id\"" \ -F "chat_id=\"$chat_id\"" \
-F "photo=@$photo_path" \ -F "photo=@$photo_path" \
-F parse_mode=Markdown \ -F parse_mode=Markdown \
-F caption="*$word* $definition -F caption="$caption"
First occurrence (century): $first_occurrence mastodon_upload_response=$(curl -X POST "https://botsin.space/api/v2/media" \
Number of occurrences (in all Ancient Greek texts): $total_occurrences" -H "Authorization: Bearer $MASTODON_TOKEN" \
-F "file=@$photo_path" \
-F "description=$word $definition")
mastodon_image_id=$(echo $mastodon_upload_response | jq -r .id)
curl -X POST "https://botsin.space/api/v1/statuses" \
-H "Authorization: Bearer $MASTODON_TOKEN" \
-d "status=$caption" \
-d "media_ids[]=$mastodon_image_id"
''; '';
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
DynamicUser = true; DynamicUser = true;
StateDirectory = "tlgwotd"; StateDirectory = "tlgwotd";
PrivateTmp = true; PrivateTmp = true;
LoadCredential = "token:${config.age.secrets.telegram-token-kmein.path}"; LoadCredential = [
"telegram-token:${config.age.secrets.telegram-token-kmein.path}"
"mastodon-token:${config.age.secrets.mastodon-token-tlgwotd.path}"
];
}; };
}; };
age.secrets = {
telegram-token-kmein.file = ../../secrets/telegram-token-kmein.age;
mastodon-token-tlgwotd.file = ../../secrets/mastodon-token-tlgwotd.age;
};
niveum.passport.services = [ niveum.passport.services = [
{ {
title = "Thesaurus Linguae Graecae Word of the Day"; title = "Thesaurus Linguae Graecae Word of the Day";

Submodule secrets updated: cd5d126839...c1618c86c3