Handle inexact matches on cheese.com

master
Nikola Forró 6 years ago
parent 5a2cd54cc8
commit 340e41d339

@ -16,11 +16,13 @@ class CheeseCom(object):
def query(self, q): def query(self, q):
try: try:
r = requests.get(BASE_URL, params=dict(q=q)) r = requests.get(BASE_URL, params=dict(q=q))
if not r.history:
raise CheeseComError('no exact match')
d = pq(r.content) d = pq(r.content)
if not r.history:
url = d('div[class~="cheese-item"]').eq(0).find('a').eq(0).attr('href')
r = requests.get(BASE_URL + url)
d = pq(r.content)
summary = [] summary = []
for p in d('ul[class="summary-points"]').find('p').items(): for p in d('ul[class~="summary-points"]').find('p').items():
summary.append(html.unescape(p.html(method='text'))) summary.append(html.unescape(p.html(method='text')))
return dict( return dict(
url=d('meta[name="twitter:url"]').attr('content'), url=d('meta[name="twitter:url"]').attr('content'),

Loading…
Cancel
Save