Plan 9 from Bell Labs’s /usr/web/sources/contrib/josh/rc/µb/read

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/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

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].