1
0
api/scpt/card_sqlite.zsh

70 lines
1.8 KiB
Bash
Raw Normal View History

2023-04-06 04:08:53 +00:00
#!/bin/zsh
host=https://api.syui.ai
api=localhost:8080
2023-04-18 12:18:38 +00:00
host_users="$host/users?itemsPerPage=2550"
2023-04-06 04:08:53 +00:00
d=${0:a:h}
dd=${0:a:h:h}
pass=`cat $dd/token.json|jq -r .password`
2023-04-13 07:50:11 +00:00
host_at=bsky.social
if [ -f $d/user.json ] && [ "$1" = "-s" ];then
rm $d/user.json
fi
function did() {
unset did
url="https://$host_at/xrpc/com.atproto.repo.listRecords?repo=${name}.${host_at}&collection=app.bsky.actor.profile"
if [ "`curl -sL $url| jq -r .error`" = "null" ];then
t=`curl -sL $url | jq -r ".records|.[]|.uri"|cut -d / -f 3`
did=$t
else
#did=`curl -sL "search.bsky.social/search/posts?q=$name" | jq -r ".[0].user.did"`
did="null"
fi
echo "{\"name\":\"$name\",\"did\":\"$did\"}," >> $d/user.json
}
2023-04-06 04:08:53 +00:00
function l_users() {
2023-04-13 07:50:11 +00:00
curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"$name\",\"password\":\"$pass\",\"did\":\"$did\"}" $api/users
#sleep 1
2023-04-06 04:08:53 +00:00
}
function l_cards() {
curl -X POST -H "Content-Type: application/json" -d "{\"owner\":$id,\"card\":$card,\"status\":\"$s\",\"cp\":$cp,\"password\":\"$pass\"}" $api/cards
2023-04-13 07:50:11 +00:00
#sleep 1
2023-04-06 04:08:53 +00:00
}
data=`curl -sL "$host_users"|jq .`
n=`echo $data|jq length`
n=$((n - 1))
for ((i=0;i<=$n;i++))
do
name=`echo $data|jq ".[$i]"|jq -r .username`
id=`echo $data|jq ".[$i]"|jq -r .id`
2023-04-18 12:18:38 +00:00
did=`echo $data|jq ".[$i]"|jq -r .did`
2023-04-13 07:50:11 +00:00
echo "{\"username\":\"$name\", \"password\":\"$pass\",\"did\":\"$did\"} localhost:8080/users"
2023-04-06 04:08:53 +00:00
if [ "$1" = "-a" ];then
l_users
fi
2023-04-18 12:18:38 +00:00
data_card=`curl -sL "$host/users/$id/card?itemsPerPage=2550"`
2023-04-06 04:08:53 +00:00
nn=`echo $data_card|jq length`
nn=$((nn - 1))
2023-04-13 07:50:11 +00:00
if [ "$1" != "-s" ];then
for ((ii=0;ii<=$nn;ii++))
do
card=`echo $data_card|jq -r ".[$ii].card"`
s=`echo $data_card|jq -r ".[$ii].status"`
cp=`echo $data_card|jq -r ".[$ii].cp"`
echo "{\"owner\":$id,\"card\":\"$card\",\"status\":\"$s\",\"cp\":\"$cp\", \"password\":\"$pass\"} localhost:8080/cards"
if [ "$1" = "-a" ];then
l_cards
fi
done
fi
2023-04-06 04:08:53 +00:00
done