Python calls simsimi

Source: Internet
Author: User

Extracted directly from the human web code. Https://github.com/insun/xiaohuangji is too lazy to apply for SIMSIMI_KEY, if forged User-Agent and Referer can also get the json string #! /Usr/bin/env python #-*-coding: UTF-8-*-# read data from simsimi import requestsimport cookielibimport socketimport randomimport syssys. path. append ('.. ') reload (sys) sys. setdefaultencoding ('utf-8') try: from settings import simsimi_key1_t: SIMSIMI_KEY = ''class SimSimi: def _ init _ (self): self. session = requests. session () self. chat_url = 'HTTP: // www.simsimi.com/func/req? Lc = ch & msg = % s 'self. api_url = 'HTTP: // api.simsimi.com/request.p? Key = % s & lc = ch & ft = 1.0 & text = % s 'if not SIMSIMI_KEY: self. initSimSimiCookie () def initSimSimiCookie (self): self. session. headers. update ({'user-agent': 'mozilla/5.0 (X11; Ubuntu; Linux i686; rv: 18.0) Gecko/20100101 Firefox/100'}) self. session. get ('HTTP: // www.simsimi.com/talk.htm') self. session. headers. update ({'Referer': 'http: // www.simsimi.com/talk.htm'}) self. session. get ('HTTP: // www.simsimi.com/talk.ht M? Lc = ch ') self. session. headers. update ({'Referer': 'http: // www.simsimi.com/talk.htm? Lc = Ch'}) def getSimSimiResult (self, message, method = 'normal'): if method = 'normal': r = self. session. get (self. chat_url % message) else: url = self. api_url % (SIMSIMI_KEY, message) r = requests. get (url) return r def chat (self, message = ''): if message: r = self. getSimSimiResult (message, 'normal' if not SIMSIMI_KEY else 'api ') try: answer = r. json () ['response'] return answer. encode ('utf-8') encode t: Return random. choice (['Ha ','... ',' = ',' =. = ']) Else: return' What Do I Do? 'simsimi = simsimi () def handle (data, bot): return SimSimi. chat (data ['message']) if _ name _ = '_ main _': print handle ({'message': 'Last question '}, none) print handle ({'message': 'Another question '}, None) print handle ({'message':' actually I have three problems '}, None) refer: python simulates simsimi chat room to call simsimi api: http://lidongbest5.com/blog/12/ github xiaohuangji: https://github.com/hupili/xiaohuangji

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.