Last active
April 30, 2019 13:06
-
-
Save dr0i/72fdc385fc4e72a6930f1644523bbdc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simulates the load created by multiple senders to an LDN Inbox | |
# by getting all yesterdays updates of lobid-resources and their use of gnd ids, | |
# POSTing in a time frame of roughly 10h by exploitmng an AI to computate delays. | |
# | |
# Optional first parameter: a date following the pattern YYYYMMDD (like in 19701010) | |
# | |
# created: 20190412 | |
# author: dr0i | |
DATE=$1 | |
if [ -z $1 ]; then | |
DATE=$(date -d "yesterday" +%Y%m%d) | |
fi | |
echo "get resources created or modified at $DATE" | |
echo "start at $(date)" | |
URL=http://lobid.org/resources/search?q=describedBy.dateCreated:$DATE%20OR%20describedBy.dateModified:$DATE | |
total=$(curl "${URL}&size=1" 2>/dev/null|jq .totalItems); | |
echo "Found so many resources using $URL: | |
$total" | |
# distribute $total in 10h (=36000s), how long to wait between a POST ? | |
float=$(echo "36000 / $total"|bc -l) | |
WAIT=$(LC_NUMERIC=C printf "%0.f" $float) | |
printf "Will wait $WAIT seconds before sending one's resource gnd ids\n" | |
computedResources=0 | |
size=100 | |
INBOX=https://test.skohub.io/inbox?target=http://test.lobid.org/gnd/ | |
IFS=$'\n' | |
while [ $total -gt $computedResources ]; do | |
echo "total=$total , done=$computedResources" | |
resources=$(curl "${URL}&size=$size&from=$computedResources" 2>/dev/null| jq -c '.member[]') | |
for i in $resources; do | |
#echo $resources | |
subjects=$(echo "$i" |jq -c .subject[].componentList[].gndIdentifier 2>/dev/null| grep -v null |tr -d '"'); | |
computedResources=$(expr $computedResources + 1) | |
for a in $subjects; do | |
echo $INBOX$a | |
curl -d $i -H "Content-Type: application/ld+json" -X POST $INBOX$a | |
done | |
if [ ${#subjects} -gt 2 ]; then | |
sleep $WAIT | |
echo "$computedResources/$total done. Wait $WAIT secs" | |
else | |
echo "No subjects found, go to next resource" | |
fi | |
done | |
done | |
echo "end at $(date)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment