parent
78c189ceff
commit
38f03b98bb
@ -0,0 +1,26 @@
|
||||
import requests
|
||||
|
||||
from pyquery import PyQuery as pq
|
||||
|
||||
|
||||
BASE_URL = 'https://www.cheese.com'
|
||||
|
||||
|
||||
class CheeseComError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class CheeseCom(object):
|
||||
def query(self, q):
|
||||
try:
|
||||
r = requests.get(BASE_URL, params=dict(q=q))
|
||||
if not r.history:
|
||||
raise CheeseComError('no exact match')
|
||||
d = pq(r.content)
|
||||
return dict(
|
||||
url=d('meta[name="twitter:url"]').attr('content'),
|
||||
name=d('meta[name="twitter:title"]').attr('content'),
|
||||
description=d('meta[name="twitter:description"]').attr('content'),
|
||||
image=d('meta[name="twitter:image"]').attr('content'))
|
||||
except Exception as e:
|
||||
raise CheeseComError(str(e))
|
Loading…
Reference in new issue