mirror of
https://gitea.phreedom.club/localhost_frssoft/dybr2fedi.git
synced 2024-11-29 23:11:28 +00:00
60 lines
2.6 KiB
Bash
Executable file
60 lines
2.6 KiB
Bash
Executable file
#!/bin/sh
|
||
|
||
#Пробный образец "моста" Дыбра в gemini
|
||
#На данный момент только для аккаунта Лиэс
|
||
#Односторонний, без возможности взаимодействия с Дыбром
|
||
#Пассивная переодическая проверка на новые статьи с записью id уже отправленных, нужен cron или обернуть в бесконечный цикл
|
||
|
||
|
||
blog_id=1045 # liesliasau Dybr blog id
|
||
|
||
basedir=$(dirname $0)
|
||
baseblogdir=$basedir/blog
|
||
mkdir -p $baseblogdir
|
||
touch $baseblogdir/index.gmi
|
||
|
||
#[Dybr section]
|
||
get_Lies_pages()
|
||
{
|
||
curl --compressed --get --url 'https://dybr.ru/v2/entries' \
|
||
-H 'accept: application/json' \
|
||
-H 'user-agent: Dybr2Fedi,Dybr2Gemini,RSS Bridge' \
|
||
--data-urlencode "filters[blog-id]=$blog_id" \
|
||
--data-urlencode 'filters[state]=published' \
|
||
--data-urlencode 'include=profile,community' \
|
||
--data-urlencode 'page[number]=1' \
|
||
--data-urlencode 'page[size]=10' \
|
||
--data-urlencode 'sort=-published-at'
|
||
}
|
||
|
||
get_Lies_pages > "$basedir"/response.json
|
||
|
||
for i in $(jj -l -i "$basedir"/response.json 'data.#.id'); do
|
||
raw_id=$(echo $i | tr -d '"')
|
||
if [ ! -f $baseblogdir/$raw_id.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")
|
||
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')
|
||
# Unpack inline images...
|
||
placeholders_img=$(echo "$plain_content" | grep -oP '\[\d{10}\]')
|
||
pseudo_index=$(echo "$links_img" | wc -l)
|
||
index=1
|
||
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")
|
||
index=$(expr $index + 1)
|
||
done
|
||
echo "# $title\n$plain_content\n\ntags: $tags\n=> $orig orig" > $baseblogdir/$raw_id.gmi
|
||
touch -d "$published" $baseblogdir/$raw_id.gmi
|
||
echo "=> $raw_id.gmi $title ($published)" | cat - $baseblogdir/index.gmi > $basedir/tmp && mv tmp $baseblogdir/index.gmi
|
||
fi
|
||
done
|
||
|
||
$basedir/rss_atom_gen.sh $baseblogdir > $baseblogdir/atom.xml
|
||
|