happybot/happybot/ichi.py

25 lines
430 B
Python

#!/usr/bin/env python3
import requests as rq
from lxml import html
from sys import argv
if len(argv) != 2:
print('Not enough arguments. Bug zgrep.')
exit(1)
q = argv[1]
r = rq.get('http://ichi.moe/cl/qr/', params={'q': q})
if r.status_code != 200:
print('Non-200 status code. Bug zgrep.')
exit()
# tree
t = html.fromstring(r.content)
ichi = ''.join(t.xpath('//span[@class="ds-text"]//text()'))
print(ichi)