1
0
mirror of https://github.com/kmein/niveum synced 2026-03-20 03:51: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 ];
@@ -74,57 +79,70 @@
b="$3" b="$3"
fi fi
luminance=$(calculate_luminance "$r" "$g" "$b") luminance=$(calculate_luminance "$r" "$g" "$b")
threshold="0.1" threshold="0.1"
echo "$r $g $b" echo "$r $g $b"
if [ "$(echo "$luminance" | awk -v threshold="$threshold" '{print ($1 > threshold)}')" -eq 1 ]; then if [ "$(echo "$luminance" | awk -v threshold="$threshold" '{print ($1 > threshold)}')" -eq 1 ]; then
color1="black" color1="black"
color2="#333" color2="#333"
else else
color1="white" color1="white"
color2=lightgrey color2=lightgrey
fi fi
magick -size 1400x846 \ magick -size 1400x846 \
xc:"$hex_color" \ xc:"$hex_color" \
-font "${pkgs.gentium}/share/fonts/truetype/GentiumBookPlus-Bold.ttf" \ -font "${pkgs.gentium}/share/fonts/truetype/GentiumBookPlus-Bold.ttf" \
-fill "$color1" \ -fill "$color1" \
-pointsize 150 -gravity west \ -pointsize 150 -gravity west \
-annotate +100-160 "$compact_word" \ -annotate +100-160 "$compact_word" \
-font "${pkgs.gentium}/share/fonts/truetype/GentiumBookPlus-Regular.ttf" \ -font "${pkgs.gentium}/share/fonts/truetype/GentiumBookPlus-Regular.ttf" \
-fill "$color2" \ -fill "$color2" \
-pointsize 60 -gravity west \ -pointsize 60 -gravity west \
-annotate +100+00 "$transliteration" \ -annotate +100+00 "$transliteration" \
-fill "$color1" \ -fill "$color1" \
-annotate +100+120 "$definition" \ -annotate +100+120 "$definition" \
-fill "$color2" \ -fill "$color2" \
-pointsize 40 -gravity southwest \ -pointsize 40 -gravity southwest \
-annotate +100+60 "t.me/TLGWotD" \ -annotate +100+60 "t.me/TLGWotD" \
-pointsize 40 -gravity southeast \ -pointsize 40 -gravity southeast \
-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" \
-F "chat_id=\"$chat_id\"" \
-F "photo=@$photo_path" \
-F parse_mode=Markdown \
-F caption="$caption"
curl -X POST "https://api.telegram.org/bot$TOKEN/sendPhoto" \ mastodon_upload_response=$(curl -X POST "https://botsin.space/api/v2/media" \
-F "chat_id=\"$chat_id\"" \ -H "Authorization: Bearer $MASTODON_TOKEN" \
-F "photo=@$photo_path" \ -F "file=@$photo_path" \
-F parse_mode=Markdown \ -F "description=$word $definition")
-F caption="*$word* $definition mastodon_image_id=$(echo $mastodon_upload_response | jq -r .id)
curl -X POST "https://botsin.space/api/v1/statuses" \
First occurrence (century): $first_occurrence -H "Authorization: Bearer $MASTODON_TOKEN" \
Number of occurrences (in all Ancient Greek texts): $total_occurrences" -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