mirror of
https://gitea.phreedom.club/localhost_frssoft/dybr2fedi.git
synced 2024-11-23 20:11:27 +00:00
Init
This commit is contained in:
commit
2604a159f2
49
auth_helper.sh
Executable file
49
auth_helper.sh
Executable file
|
@ -0,0 +1,49 @@
|
|||
#!/bin/sh
|
||||
default_auth_browser=links
|
||||
|
||||
mkdir -m 711 -p .app_sessions
|
||||
|
||||
|
||||
echo 'Input instance (example.example)'
|
||||
read instance
|
||||
|
||||
instance_point="https://$instance/api/v1"
|
||||
|
||||
auth_api_create_client()
|
||||
{
|
||||
if [ ! -e ".app_sessions/$instance" ]; then
|
||||
curl -s --compressed --url "$instance_point/apps" \
|
||||
--data-urlencode 'client_name=dybr2fedi bridge' \
|
||||
--data-urlencode 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' \
|
||||
--data-urlencode 'scopes=read write follow' \
|
||||
--output ".app_sessions/$instance" \
|
||||
--create-file-mode 0600
|
||||
fi
|
||||
}
|
||||
|
||||
auth_api_get_code()
|
||||
{
|
||||
auth_api_create_client
|
||||
client_id=$(jj -i ".app_sessions/$instance" client_id)
|
||||
default_auth_browser "https://$instance/oauth/authorize?client_id=$client_id&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=read+write+follow"
|
||||
echo 'Input token-code:'
|
||||
read pass
|
||||
}
|
||||
|
||||
auth_api_get_token()
|
||||
{
|
||||
auth_api_get_code
|
||||
clear
|
||||
client_id=$(jj -i ".app_sessions/$instance" client_id)
|
||||
client_secret=$(jj -i ".app_sessions/$instance" client_secret)
|
||||
token=$(curl -s --compressed --url "https://$instance/oauth/token" \
|
||||
--data-urlencode 'grant_type=authorization_code' \
|
||||
--data-urlencode "client_id=$client_id" \
|
||||
--data-urlencode "client_secret=$client_secret" \
|
||||
--data-urlencode "redirect_uri=urn:ietf:wg:oauth:2.0:oob" \
|
||||
--data-urlencode 'scope=read write follow' \
|
||||
--data-urlencode "code=$pass" | jj access_token)
|
||||
echo > .auth
|
||||
chmod 600 .auth
|
||||
echo "$token" > .auth
|
||||
}
|
79
dybr2fedi.sh
Executable file
79
dybr2fedi.sh
Executable file
|
@ -0,0 +1,79 @@
|
|||
#!/bin/sh
|
||||
|
||||
#Пробный образец "моста" Дыбра в Федивёрс
|
||||
#На данный момент только для аккаунта Лиэс
|
||||
#Односторонний, без возможности взаимодействия с Дыбром
|
||||
#Пассивная переодическая проверка на новые статьи с записью id уже отправленных, нужен cron или обернуть в бесконечный цикл
|
||||
|
||||
|
||||
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'
|
||||
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"
|
||||
}
|
||||
#
|
||||
|
||||
#[Dybr section]
|
||||
get_Lies_pages()
|
||||
{
|
||||
curl --compressed --get --url 'https://dybr.ru/v2/entries' \
|
||||
-H 'accept: application/json' \
|
||||
-H 'user-agent: Dybr2Fedi 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 > response.json
|
||||
|
||||
for i in $(jj -l -i "$basedir"/response.json 'data.#.id' | tac); do
|
||||
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' ' ')
|
||||
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
|
||||
#
|
||||
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"
|
||||
fi
|
||||
done
|
||||
#
|
Loading…
Reference in a new issue