aboutsummaryrefslogtreecommitdiff
path: root/wpq
blob: 370a62e4545f543e24ce18f0fc95b37e23be3937 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/rc
rfork e
ts=`{date -n}
tmpfile=/tmp/wpsearch.$ts
wanthtml=n

fn sigint {
	rm -f $tmpfile
}

fn usage {
	echo usage: $0 [-h] query >[1=2]
	exit usage
}

if(~ $#* 0)
	usage
switch($1){
case -*h*
	wanthtml=y
	shift
}
{
	echo -n '{"result":'
	hget 'https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search='^$"*
	echo -n '}'
} >$tmpfile
targ=`{wpqprompt $tmpfile | tr ' ' '_'}
rm -f $tmpfile
if(~ $wanthtml y)
	plumb 'https://en.wikipedia.org/wiki/'^$targ
if not
	hget 'https://en.wikipedia.org/api/rest_v1/page/pdf/'^$targ | page -w -p145