XZZ/worker/bing.py
2020-02-28 22:58:14 +08:00

25 lines
823 B
Python

from zzcore import StdAns
from config import BINGKEY
import requests
class Ans(StdAns):
def GETMSG(self):
if len(self.parms) < 2:
return '不加参数是坏文明!'
url = 'https://api.cognitive.microsoft.com/bing/v7.0/search'
params = {
'q':self.raw_msg['message'][5:],
'count': 1,
}
headers = {
'Ocp-Apim-Subscription-Key': BINGKEY,
}
try:
resp = requests.get(url=url,params=params,headers=headers).json()
result = resp['webPages']['value'][0]
msg = '咱帮你🔍到了这个\nTitle: ' + result['name']+'\nLink: '+result['displayUrl']+'\n'+result['snippet']
except:
msg = '什么东西坏掉了,大概是bing吧...不可能是咱!'
return msg