当前位置: 首页 > news >正文

docker做网站百度爱采购平台官网

docker做网站,百度爱采购平台官网,自媒体网站开发,中国电信软件开发工程师待遇最近,同学搞了个微信自动回复,只要再群里说话,就会回复,感觉挺好玩,现把代码分享下如下,先看看效果,如下图 左边的是机器人,右边的是我和它聊的。 现在开始把! 首先需要去…

最近,同学搞了个微信自动回复,只要再群里说话,就会回复,感觉挺好玩,现把代码分享下如下,先看看效果,如下图

左边的是机器人,右边的是我和它聊的。

 

现在开始把!

首先需要去图灵申请个apikey,图灵官网http://www.turingapi.com/

 

配置文件Wxpy.ini如下

[tuling]
#此处是从图灵申请的apikey
apikey="*****"[wechat]
#utf-8 gbk
charset="utf-8"#好友昵称,目前仅支持一个,不需要则留空
friend=""#群组昵称,目前仅支持一个,不需要则留空
group=""#自动回复消息前缀
prefix=" "#自动回复消息后缀
subfix=" "

 

代码文件Wxpy.py如下:

#coding:utf-8
__author__ = '***'
import time
import sys
import os
import ctypes
import Tkinter
import tkMessageBox
import json
import requests
import re
import subprocess
import datetime
import ConfigParser
import wxpydef msgBox(title, info):newTitle = title.decode('utf-8')newInfo = info.decode('utf-8')print newTitle, newInfotop = Tkinter.Tk()top.withdraw()tkMessageBox.showinfo(title, info)#tkMessageBox.askyesno(title, info)#ctypes.windll.user32.MessageBoxA(0, newInfo, newTitle, 0)#os.system('msg %username% /TIME:2 '+info)def test():print "%s."%sys._getframe().f_code.co_nametry :time.sleep(0.3)except Exception,e:print ereturndef chatbot_init():bot = ChatBot("Terminal", storage_adapter = "chatterbot.storage.JsonFileStorageAdapter", logic_adapters = [ "chatterbot.logic.MathematicalEvaluation", "chatterbot.logic.TimeLogicAdapter", "chatterbot.logic.BestMatch" ], input_adapter = "chatterbot.input.TerminalAdapter", output_adapter = "chatterbot.output.TerminalAdapter", database = "./database.db" ) def tuling_api(api_key, info):url = 'http://www.tuling123.com/openapi/api?key='+api_key+'&info='+infoprint urlres = requests.get(url)res.encoding = 'utf-8'jsonRes = json.loads(res.text)#str to dict#print('tuling_api: ' + jsonRes['text'])return jsonRes['text']if "__main__" == __name__:# if(len(sys.argv) < 4):# msgBox("error", "para error!")# deviceName=sys.argv[1]try:reload(sys)sys.setdefaultencoding('utf-8')#api_key='302dbb3ed3f845e5863c9ca7210acc2a'api_key = ''targetFriend = ''targetGroup = ''strPrefix = ''strSubfix = ''charset = ''cf = ConfigParser.ConfigParser()cf.read('Wxpy.ini')api_key = cf.get('tuling','apikey').strip('"').strip()targetFriend = cf.get('wechat','friend').strip('"').strip()targetGroup = cf.get('wechat','group').strip('"').strip()strPrefix = cf.get('wechat','prefix').strip('"')strSubfix = cf.get('wechat','subfix').strip('"')charset = cf.get('wechat','charset').strip('"').strip()targetAutoReply = []print len(api_key), api_keyprint len(targetFriend), targetFriend.decode(charset)print len(targetGroup), targetGroup.decode(charset)print len(charset), charsetif(len(api_key) == 0 or ( len(targetFriend) == 0 and len(targetGroup) == 0) ):msgBox('参数错误', '请参照使用说明 然后重新打开软件')sys.exit(1)#tuling = wxpy.Tuling(api_key='302dbb3ed3f845e5863c9ca7210acc2a')bot = wxpy.Bot(cache_path=True)friends_stat = bot.friends().stats()#print friends_statfor province, count in friends_stat["province"].iteritems():#print "province '%s', count %s"%(province, count)passfor city, count in friends_stat["city"].iteritems():#print "city '%s', count %s"%(city, count)passfor sex, count in friends_stat["sex"].iteritems():#print "sex '%s', count %s"%(sex, count)passmyGroup = Nonegroups = bot.groups()count=0for group in groups:#print group.user_nameif group.nick_name!=None:#print group.nick_nameif len(targetGroup) != 0 and group.nick_name.find(targetGroup.decode(charset)) != -1:print 'Got it in groups.++++++++++++++++++++++++++++++++++++++'myGroup = grouptargetAutoReply.append(myGroup)count+=1print "groupCnt=%d."%countmyFriend = Nonefriends = bot.friends()count=0for friend in friends:#print friend.user_nameif friend.nick_name!=None:#print friend.nick_nameif len(targetFriend) != 0 and friend.nick_name.find(targetFriend.decode(charset)) != -1:print 'Got it in friends.------------------------------------'myFriend = friendtargetAutoReply.append(myFriend)passcount+=1print "friendCnt=%d."%counttmpStr = strPrefix + 'Hi.' + strSubfix# + str(datetime.datetime.now())if myGroup != None:myGroup.send(tmpStr.decode('utf-8','ignore'))if myFriend != None:myFriend.send(tmpStr.decode('utf-8','ignore'))#bot.file_helper.send(tmpStr.decode('utf-8','ignore'))print '-----------------------------------'# 打印来自其他好友、群聊和公众号的消息
        @bot.register()def print_others(msg):print 'From others: '#print msgprint msg.sender.name,msg.text,msg.type# # 回复 groups 的消息 (优先匹配后注册的函数!)# @bot.register(myGroup)# def auto_reply_groups(msg):# print 'From auto_reply_groups:'# #print msg# print msg.sender.name,msg.text,msg.type# #msg.sender.mark_as_read()# if msg.type == 'Text': #如果是文字,就利用图灵机器人api回复,return和msg.reply_msg效果一样# print 'Text.'# #replyText = tuling.do_reply(msg)# #replyText = tuling.reply_text(msg)# replyText = tuling_api(api_key, msg.text)# replyText = strPrefix + replyText + strSubfix# print '===<', replyText# #msg.sender.send(replyText)# msg.reply_msg(replyText)# #return replyText# elif msg.type == 'Picture': #如果接受到图片,就自动回复同样的图片# print ('this is Picture:{}'.format(msg.file_name))# savaPath = msg.file_name# msg.get_file(savaPath)# msg.reply_image(savaPath)# else:#其它的就转发回给发送人# msg.forward(msg.sender)# 回复 friends 的消息 (优先匹配后注册的函数!)
        @bot.register(targetAutoReply)def auto_reply(msg):if len(targetAutoReply) == 0:returnprint 'From auto_reply:'#print msgprint msg.sender.name,msg.text,msg.type#msg.sender.mark_as_read()if msg.type == 'Text': #如果是文字,就利用图灵机器人api回复,return和msg.reply_msg效果一样print 'Text..'if msg.text.startswith(strPrefix) and msg.text.endswith(strSubfix):return#replyText = tuling.do_reply(msg)replyText = tuling_api(api_key, msg.text)replyText = strPrefix + replyText + strSubfixprint '===<', replyText#msg.sender.send(replyText)
                msg.reply_msg(replyText)#return replyTextelif msg.type == 'Picture': #如果接受到图片,就自动回复同样的图片print ('this is Picture:{}'.format(msg.file_name))savaPath = msg.file_namemsg.get_file(savaPath)msg.reply_image(savaPath)else:#其它的就转发回给发送人
                msg.forward(msg.sender)# # 自动接受新的好友请求@bot.register(msg_types=wxpy.FRIENDS)def auto_accept_friends(msg):print 'From auto_accept_friends:'#print msgprint msg.sender.name,msg.text,msg.type# # 接受好友请求# #new_friend = msg.card.accept()# # 向新的好友发送消息# #new_friend.send('哈哈,我自动接受了你的好友请求')
        wxpy.embed()# # 进入Python命令行,让程序保持运行while(1):passexcept Exception,e:print efinally:sys.exit(1)

有兴趣的可以玩玩,感觉挺好玩。 

转载于:https://www.cnblogs.com/kumufengchun/p/10280884.html

http://www.lbrq.cn/news/2433835.html

相关文章:

  • 做艺术品的网站烘焙甜点培训学校
  • 网站开发怎么实现用户一对一发文字图片深度搜索
  • app推广拉新工作可靠吗seo 培训教程
  • 福建省政府网站建设与管理seo前景
  • 域名服务器都有了怎么做网站seo视频教程百度云
  • 电商网站的银行支付接入该怎么做长沙网站seo分析
  • 建网站需要多少钱和什么条件才能建百度不让访问危险网站怎么办
  • 兰州疫情最新情况通报seo权威入门教程
  • 电影网站logo设计seo排名公司
  • 山东省建设厅网站维护电话百度竞价推广出价技巧
  • 意识形态网站建设希爱力双效片副作用
  • 免费网站建立软文发布平台排名
  • 手机摄影网站如何做优化排名
  • 山西省建设厅政务中心网站百度seo建议
  • 泰安网站建设有哪些百度网站快速优化
  • 网站设计制作 联系郑州网站seo优化
  • 网站建设需要准备什么软件建立一个网站需要花多少钱
  • 做网站找云无限巩义网络推广公司
  • 上海做网站的的公司seo招聘
  • 网站建设能挣钱网站注册域名
  • 微信小程序怎么关闭未成年模式宁波谷歌seo推广公司
  • 做私彩网站产品软文范例软文
  • 哪些网站可以接工程做推广的十种方式
  • 一流的网站建设流程图推荐友情链接
  • 长沙哪里可以做网站网络营销论文
  • 做二手手机交易网站湖南seo公司
  • 最专业网站建设公司哪家好怎么开网站详细步骤
  • 网页设计与网站建设课程设计百度号码认证申诉平台
  • 软件网站怎么做潍坊网站建设解决方案
  • 免费制作公司网站重庆网站排名
  • 外网访问内部私有局域网方案,解决运营商只分配内网IP不给公网IP问题
  • Java中关于线程池的解析
  • LeetCode 658.找到K个最接近的元素
  • Python可迭代归约函数深度解析:从all到sorted的进阶指南
  • 【c++】leetcode438 找到字符串中所有字母异位词
  • 易语言+懒人精灵/按键中控群控教程(手机、主板机、模拟器通用)