35 lines
1012 B
Bash
Executable File
35 lines
1012 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Usage
|
|
# `./get-type.sh <coin|banknote> <country> <id> <count (optional)>`
|
|
|
|
type=$1
|
|
dir="./public/$1s/$2"
|
|
tmpdir="./public/new-$1s/$2"
|
|
id=$3
|
|
count=${4:-1}
|
|
|
|
if [ -f "$dir/$id.json" ]; then
|
|
echo "Already exists in main dir"
|
|
oldcount=$(cat $dir/$id.json | jq '.count')
|
|
if [ $oldcount == null ]; then
|
|
oldcount=1
|
|
fi
|
|
newcount=$count+$oldcount
|
|
json=$(cat $dir/$id.json | jq '.count='$newcount)
|
|
echo $json | jq > $dir/$id.json
|
|
elif [ -f "$tmpdir/$id.json" ]; then
|
|
echo "Already exists in tmp dir"
|
|
oldcount=$(cat $tmpdir/$id.json | jq '.count')
|
|
if [ $oldcount == null ]; then
|
|
oldcount=1
|
|
fi
|
|
newcount=$count+$oldcount
|
|
json=$(cat $tmpdir/$id.json | jq '.count='$newcount)
|
|
echo $json | jq > $tmpdir/$id.json
|
|
else
|
|
mkdir -p $tmpdir
|
|
curl -X GET "https://api.numista.com/api/v3/types/$id" -H "Numista-API-Key: egr10utzWmYztFrZhJSRGF7Tv64RA3b2S4xdz4di" | jq '.count='$count > $tmpdir/$id.json
|
|
cat $tmpdir/$id.json | jq '.title'
|
|
fi
|