Gemini edition

This commit is contained in:
localhost_frssoft 2023-01-08 03:19:10 +03:00
parent 2bfbe337d4
commit 74631a55ad
1 changed files with 12 additions and 44 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh
#Пробный образец "моста" Дыбра в Федивёрс
#Пробный образец "моста" Дыбра в gemini
#На данный момент только для аккаунта Лиэс
#Односторонний, без возможности взаимодействия с Дыбром
#Пассивная переодическая проверка на новые статьи с записью id уже отправленных, нужен cron или обернуть в бесконечный цикл
@ -9,36 +9,8 @@
blog_id=1045 # liesliasau Dybr blog id
basedir=$(dirname $0)
log_sended_articles="$basedir"/sended_dybr_ids
touch $log_sended_articles
#[Fedi section]
instance_point='https://expired.mentality.rip/api/v1'
if [ ! -f "$basedir"/.auth ]; then
export basedir
"$basedir"/auth_helper.sh
if [ ! -f "$basedir"/.auth ]; then
echo 'Failed, access denied'
else
echo 'OK! Success'
fi
fi
auth=$(cat "$basedir"/.auth | tr -d '\n')
post_request()
{
curl -s --compressed -X POST -H "Authorization: Bearer $auth" "$@"
}
write_api_status()
{
post_request --url "$instance_point"/statuses \
--data-urlencode "status@-" \
--data-urlencode "spoiler_text=$title" \
--data-raw "content_type=text/plain" \
--data-raw "visibility=unlisted"
}
#
baseblogdir=$basedir/blog
mkdir -p $baseblogdir
#[Dybr section]
get_Lies_pages()
@ -56,10 +28,13 @@ get_Lies_pages()
get_Lies_pages > "$basedir"/response.json
for i in $(jj -l -i "$basedir"/response.json 'data.#.id' | tac); do
for i in $(jj -l -i "$basedir"/response.json 'data.#.id'); do
raw_id=$(echo $i | tr -d '"')
if [ ! -f $baseblogdir/$i.gmi ]; then
orig=$(echo $i | sed -e 's/"//g; s|^|https://dybr.ru/blog/liesliasau/|g')
title=$(jj -i "$basedir"/response.json "data.#[id=$i].attributes.title")
tags=$(jj -l -i "$basedir"/response.json "data.#[id=$i].attributes.tags" | tr ' -' '_' | tr -d '.!'| sed -e 's/"//g ; s/^/\#/g' | tr '\n' ' ')
published=$(jq -r ".[] | .[] | select(.id==$i) | .attributes[\"created-at\"]" "$basedir"/response.json)
tags=$(jj -l -i "$basedir"/response.json "data.#[id=$i].attributes.tags" | sed -e 's/"//g' | tr '\n' ',')
content=$(jj -i "$basedir"/response.json "data.#[id=$i].attributes.content")
links_img=$(echo "$content" | pup 'img attr{src}' | sed 's|^|https://dybr.ru|g')
plain_content=$(echo "$content" | w3m -T text/html -cols 65535 -dump -o display_link_number=1 | sed -e 's|\[MORE=.*\]||g ; s|\[/MORE\]||g ; s|\[S:|~~|g ; s|:S\]|~~|g')
@ -70,19 +45,12 @@ for i in $(jj -l -i "$basedir"/response.json 'data.#.id' | tac); do
while [ $index -le $pseudo_index ]; do
placeholder=$(echo "$placeholders_img" | sed $index!d | tr -d '[]')
img=$(echo "$links_img" | sed $index!d)
plain_content=$(echo "$plain_content" | sed "s|\[$placeholder\]| $img |g")
plain_content=$(echo "$plain_content" | sed "s|\[$placeholder\]|=> $img |g")
index=$(expr $index + 1)
done
#
grep -F $i $log_sended_articles
sended=$?
if [ $sended -gt 0 ]; then
export title
echo "$plain_content\n\n$tags\norig: $orig" | write_api_status
echo $i >> $log_sended_articles
sleep 60
elif [ $sended -eq 0 ]; then
echo "Already sended"
echo "# $title\n$plain_content\n\ntags: $tags\n=> $orig orig" > $baseblogdir/$raw_id.gmi
echo "=> $raw_id.gmi $title ($published)" >> $baseblogdir/index.gmi
fi
done
#