#!/bin/rc
rfork en
flagfmt='p,r,h url'
args='[user]'
if(! ifs=() eval `{aux/getflags $*} || ! ~ $#* 0 1){
aux/usage
exit usage
}
conflicting=($flagp $flagr)
if(~ $#conflicting 2){
echo 'can only use one of -p or -r' >[1=2]
exit usage
}
if(~ $#µblog 1)
url=$µblog
if(~ $#flagh 1)
url=$flagh
if(! ~ $#url 1){
echo 'set $µblog or give -h url' >[1=2]
exit usage
}
# Lacking JSON, scrape HTML. Not using API.
url=`{sed 's/\/api//' /env/url | sed 's/https/http/'}
if(~ $#µsr 1)
user=$µsr
if(~ $#1 1)
user=$1
q=/$user/all
if(~ $#flagp 1)
q=/
if(~ $#flagr 1)
q=/$user/replies
hget $url^$q | htmlfmt > /tmp/µbread.$pid
sam -d /tmp/µbread.$pid >[2] /dev/null <<'!'
0,/Notices/-1d
/^Pagination/,$d
,p
!
rm /tmp/µbread.$pid
|