python实现向微信用户发送每日一句 python实现微信聊天机器人


Posted in Python onMarch 27, 2019

分享几个Python针对微信的小工具,供大家参考,具体内容如下

用Python实现向微信用户发送每日一句

# -*- coding:utf-8 -*-
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
#bot = Bot()
#bot = Bot(console_qr=2,cache_path="botoo.pkl")#这里的二维码是用像素的形式打印出来!,如果你在win环境上运行,替换为 bot=Bot()
bot = Bot(cache_path=True)
 
def get_news1():
#获取金山词霸每日一句,英文和翻译
 url = "http://open.iciba.com/dsapi/"
 r = requests.get(url)
 contents = r.json()['content']
 translation= r.json()['translation']
 return contents,translation
def send_news():
 try:
  my_friend = bot.friends().search(u'浩')[0] #你朋友的微信名称,不是备注,也不是微信帐号。
  my_friend.send(get_news1()[0])
  my_friend.send(get_news1()[1][5:])
  my_friend.send(u"以上是金山词霸每日一句,http://www.qq.com\" data-miniprogram-appid=\"wxae430cc3e778834b\" data-miniprogram-path=\"pages/goLogin/goLogin\"")
  t = Timer(10, send_news)#每86400秒(1天),发送1次,不用linux的定时任务是因为每次登陆都需要扫描二维码登陆,很麻烦的一件事,就让他一直挂着吧
  t.start()
 except:
  my_friend = bot.friends().search('回???是如此伤')[0]#你的微信名称,不是微信帐号。
  my_friend.send(u"今天消息发送失败了")
if __name__ == "__main__":
 send_news()

用Python调用图灵机器人接口实现微信聊天机器人

import kivy
 
kivy.require('1.9.1')
from kivy.app import App
from kivy.uix.button import Button
import itchat
import requests
 
class test(App):
 def get_response(msg):
  apiUrl = 'http://www.tuling123.com/openapi/api'
  data = {
   'key': '0646d90819004f2fa565852c0fe3c3af', # Tuling Key
   'info': msg, # 这是我们发出去的消息
   'userid': '123', # 这里你想改什么都可以
  }
  # 我们通过如下命令发送一个post请求
  r = requests.post(apiUrl, data=data).json()
  return r.get('text')
 
 @itchat.msg_register(itchat.content.TEXT)
 def print_content(msg):
  return get_response(msg['Text'])
 
 @itchat.msg_register([itchat.content.TEXT], isGroupChat=True)
 def print_content(msg):
  return get_response(msg['Text'])
 
 itchat.auto_login(True)
 itchat.run()
 
 
if __name__ == '__main__':
 test().run()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
详细介绍Ruby中的正则表达式
Apr 10 Python
详尽讲述用Python的Django框架测试驱动开发的教程
Apr 22 Python
浅谈Python 集合(set)类型的操作——并交差
Jun 30 Python
Python实现iOS自动化打包详解步骤
Oct 03 Python
Python脚本完成post接口测试的实例
Dec 17 Python
Django实现学员管理系统
Feb 26 Python
Python求一批字符串的最长公共前缀算法示例
Mar 02 Python
解决torch.autograd.backward中的参数问题
Jan 07 Python
TensorFlow2.0:张量的合并与分割实例
Jan 19 Python
python机器学习库xgboost的使用
Jan 20 Python
python使用正则表达式匹配txt特定字符串(有换行)
Dec 09 Python
Python读写yaml文件
Mar 20 Python
Pandas读写CSV文件的方法示例
Mar 27 #Python
使用Python的SymPy库解决数学运算问题的方法
Mar 27 #Python
超简单使用Python换脸实例
Mar 27 #Python
python爬虫爬取微博评论案例详解
Mar 27 #Python
Python实现查找字符串数组最长公共前缀示例
Mar 27 #Python
详解python中@的用法
Mar 27 #Python
详解python列表生成式和列表生成式器区别
Mar 27 #Python
You might like
使用网络地址转换实现多服务器负载均衡
2006/10/09 PHP
在PHP3中实现SESSION的功能(三)
2006/10/09 PHP
php header功能的使用
2013/10/28 PHP
php多线程实现方法及用法实例详解
2015/10/26 PHP
PHP爬虫之百万级别知乎用户数据爬取与分析
2016/01/22 PHP
利用php生成验证码
2017/02/23 PHP
CakePHP框架Model关联对象用法分析
2017/08/04 PHP
网页编辑器ckeditor和ckfinder配置步骤分享
2012/05/24 Javascript
探讨JQUERY JSON的反序列化类 using问题的解决方法
2013/12/19 Javascript
js 获取时间间隔实现代码
2014/05/12 Javascript
基于vuejs+webpack的日期选择插件
2020/05/21 Javascript
js仿京东轮播效果 选项卡套选项卡使用
2017/01/12 Javascript
js实现按座位号抽奖
2017/04/05 Javascript
JS实现unicode和UTF-8之间的互相转换互转
2017/07/05 Javascript
security.js实现的RSA加密功能示例
2018/06/06 Javascript
详解js 创建对象的几种方法
2019/03/08 Javascript
解决echarts数据二次渲染不成功的问题
2020/07/20 Javascript
vue-cli3配置favicon.ico和title的流程
2020/10/27 Javascript
[00:20]DOTA2荣耀之路7:-ah fu-抢盾
2018/05/31 DOTA
[02:55]2018DOTA2国际邀请赛勇士令状不朽珍藏Ⅲ饰品一览
2018/08/01 DOTA
python根据开头和结尾字符串获取中间字符串的方法
2015/03/26 Python
Ubuntu下创建虚拟独立的Python环境全过程
2017/02/10 Python
Python实现从SQL型数据库读写dataframe型数据的方法【基于pandas】
2019/03/18 Python
Python加速程序运行的方法
2020/07/29 Python
Pytorch之Tensor和Numpy之间的转换的实现方法
2020/09/03 Python
No module named ‘win32gui‘ 的解决方法(踩坑之旅)
2021/02/18 Python
HTML5拖放效果的实现代码
2016/11/17 HTML / CSS
加拿大领先的牛仔零售商:Bluenotes
2018/01/22 全球购物
家庭睡衣和家庭用品:Little Blue House
2018/03/18 全球购物
struct和class的区别
2015/11/20 面试题
药剂专业学生求职信范文
2013/12/28 职场文书
给老师的检讨书
2014/02/11 职场文书
工地材料员岗位职责
2015/04/11 职场文书
2016秋季田径运动会广播稿
2015/12/21 职场文书
SQL注入详解及防范方法
2021/12/06 MySQL
MySQL运行报错:“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”解决方法
2022/06/14 MySQL