Add print hackernews stories

This commit is contained in:
lucic71 2022-07-27 23:49:10 +03:00
commit ba2e2e5b08
2 changed files with 38 additions and 0 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# scripts
This is a collection of my scripts.

35
print-hn-stories/print.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/sh
TOPSTORIES=`curl -s "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"`
URLS=""
i=0
n=30
for id in $TOPSTORIES
do
# First element is '[', skip it.
if [ "$i" -eq 0 ]; then
i=$((i+1))
continue
fi
# Don't print more than n stories
if [ "$i" -gt "$n" ]; then
break
fi
# Delete trailing comma
storyid=`echo $id | cut -d, -f1`
STORY=`curl -s "https://hacker-news.firebaseio.com/v0/item/$storyid.json?print=pretty"`
URL=`echo $STORY | jq -r '.url'`
URLS="$URLS $URL"
# TODO: filter urls
i=$((i+1))
done
# For some fucking reason, wkhtmltopdf crashes on OpenBSD.
wkhtmltopdf $URLS output.pdf