2022-08-14 05:40:14 +00:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
2023-01-08 00:19:10 +00:00
|
|
|
|
#Пробный образец "моста" Дыбра в gemini
|
2022-08-14 05:40:14 +00:00
|
|
|
|
#На данный момент только для аккаунта Лиэс
|
|
|
|
|
#Односторонний, без возможности взаимодействия с Дыбром
|
|
|
|
|
#Пассивная переодическая проверка на новые статьи с записью id уже отправленных, нужен cron или обернуть в бесконечный цикл
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blog_id=1045 # liesliasau Dybr blog id
|
|
|
|
|
|
|
|
|
|
basedir=$(dirname $0)
|
2023-01-08 00:19:10 +00:00
|
|
|
|
baseblogdir=$basedir/blog
|
|
|
|
|
mkdir -p $baseblogdir
|
2023-01-08 00:52:29 +00:00
|
|
|
|
touch $baseblogdir/index.gmi
|
2022-08-14 05:40:14 +00:00
|
|
|
|
|
|
|
|
|
#[Dybr section]
|
|
|
|
|
get_Lies_pages()
|
|
|
|
|
{
|
|
|
|
|
curl --compressed --get --url 'https://dybr.ru/v2/entries' \
|
|
|
|
|
-H 'accept: application/json' \
|
2023-01-08 00:52:29 +00:00
|
|
|
|
-H 'user-agent: Dybr2Fedi,Dybr2Gemini,RSS Bridge' \
|
2022-08-14 05:40:14 +00:00
|
|
|
|
--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'
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-14 12:30:41 +00:00
|
|
|
|
get_Lies_pages > "$basedir"/response.json
|
2022-08-14 05:40:14 +00:00
|
|
|
|
|
2023-01-08 00:19:10 +00:00
|
|
|
|
for i in $(jj -l -i "$basedir"/response.json 'data.#.id'); do
|
|
|
|
|
raw_id=$(echo $i | tr -d '"')
|
2023-01-08 00:52:29 +00:00
|
|
|
|
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
|
2023-01-08 01:05:24 +00:00
|
|
|
|
echo "=> $raw_id.gmi $title ($published)" | cat - $baseblogdir/index.gmi > $basedir/tmp && mv tmp $baseblogdir/index.gmi
|
2022-08-14 05:40:14 +00:00
|
|
|
|
fi
|
|
|
|
|
done
|
2023-01-08 15:05:37 +00:00
|
|
|
|
|
|
|
|
|
$basedir/rss_atom_gen.sh $baseblogdir > $baseblogdir/atom.xml
|
2023-01-08 00:19:10 +00:00
|
|
|
|
|