mvnic/scrap.sh

31 lines
758 B
Bash
Raw Normal View History

2023-02-11 01:25:05 +05:00
#/bin/bash
START_NID=$1
2023-02-11 02:03:11 +05:00
NID=$START_NID
2023-02-11 01:25:05 +05:00
END_NID=$2
FILENAME=A${1}-A${2}.json
2023-02-12 11:26:30 +05:00
mkdir -p null
2023-02-11 01:29:15 +05:00
while [ "$START_NID" -le "$END_NID" ];
2023-02-11 01:25:05 +05:00
do
2023-02-11 02:03:11 +05:00
echo Scraping: $NID # print
CONTENT=$(curl -si https://fikureggedhirun.com/api/fetch?nic=A$NID > .cache) # curl output with http headers and data
2023-02-11 01:32:39 +05:00
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
2023-02-11 01:25:05 +05:00
if [ "$HTTP_STATUS" = "200" ]
then
2023-02-12 11:26:30 +05:00
if [ "$DATA" = "null" ]
then
echo A$NID > null/A$NID
else
2023-02-11 01:25:05 +05:00
echo $DATA | tee -a $FILENAME
printf "\n" | tee -a $FILENAME
START_NID=$(echo $[$START_NID+1])
2023-02-11 02:03:11 +05:00
printf -v NID "%06d" $START_NID
2023-02-12 11:26:30 +05:00
sleep 1.5
fi
2023-02-11 01:25:05 +05:00
else
echo delaying
sleep 1000
fi
done