mvnic/scrap.sh
2023-02-11 01:32:39 +05:00

23 lines
631 B
Bash
Executable File

#/bin/bash
START_NID=$1
END_NID=$2
FILENAME=A${1}-A${2}.json
while [ "$START_NID" -le "$END_NID" ];
do
echo Scraping: $START_NID # print
CONTENT=$(curl -si https://fikureggedhirun.com/api/fetch?nic=A$START_NID > .cache) # curl output with http headers and data
DATA=$(cat .cache | tail -n1) # get the json data from last line
HTTP_STATUS=$(cat .cache | head -n1 | awk '{print $2}') # get the http code from first line
if [ "$HTTP_STATUS" = "200" ]
then
echo $DATA | tee -a $FILENAME
printf "\n" | tee -a $FILENAME
START_NID=$(echo $[$START_NID+1])
sleep 5
else
echo delaying
sleep 1000
fi
done