forked from hellokuku/xiaohuangji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimsimi.py
30 lines (24 loc) · 800 Bytes
/
simsimi.py
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
#-*-coding:utf-8-*-
import requests
import cookielib
class SimSimi:
def __init__(self):
r = requests.get('http://www.simsimi.com/talk.htm')
self.cookies = r.cookies
self.headers = {
'Referer': 'http://www.simsimi.com/talk.htm'
}
self.url = 'http://www.simsimi.com/func/req?lc=ch&msg=%s'
def chat(self, message=''):
if message.strip():
r = requests.get(self.url % message.strip(), headers=self.headers, cookies=self.cookies)
self.cookies = r.cookies
try:
return r.json()['response']
except:
return u'呵呵'
else:
return u'叫我干嘛'
if __name__ == '__main__':
simi = SimSimi()
print simi.chat('最后一个问题')