Last active
December 10, 2015 08:08
-
-
Save wong2/4405430 to your computer and use it in GitHub Desktop.
小黄鸡
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*-coding:utf-8-*- | |
import requests | |
import cookielib | |
class SimSimi: | |
def __init__(self): | |
self.session = requests.Session() | |
self.session.get('http://www.simsimi.com/talk.htm') | |
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 = self.session.get(self.url % message.strip(), headers=self.headers) | |
try: | |
return r.json()['response'] | |
except: | |
return u'呵呵' | |
else: | |
return u'叫我干嘛' | |
if __name__ == '__main__': | |
simi = SimSimi() | |
print simi.chat('最后一个问题') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
哈哈,不错,好玩儿