Skip to content

Instantly share code, notes, and snippets.

@Lerie82
Created May 14, 2018 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lerie82/3019d4e0e6793f1598b3dd52daa075d4 to your computer and use it in GitHub Desktop.
Save Lerie82/3019d4e0e6793f1598b3dd52daa075d4 to your computer and use it in GitHub Desktop.
#!/bin/bash
counter=10
curl https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty > /var/www/html/pbr/tmp/hnews
cat /var/www/html/pbr/tmp/hnews |grep -o '[0-9]\{7,8\}' > /var/www/html/pbr/tmp/hnews2
truncate -s 0 /var/www/html/pbr/tmp/hnews
echo '[' >> /var/www/html/pbr/tmp/hnews
cat /var/www/html/pbr/tmp/hnews2 | while read -r line;
do
curl https://hacker-news.firebaseio.com/v0/item/$line.json?print=pretty >> /var/www/html/pbr/tmp/hnews
counter=$((counter-1))
if [ $counter -eq 0 ]
then
echo ']' >> /var/www/html/pbr/tmp/hnews
exit 1
else
echo ',' >> /var/www/html/pbr/tmp/hnews
fi
done
rm /var/www/html/pbr/tmp/hnews2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment