背景:利用Python来登入你个人的手机微信,之后向朋友发送消息,发送的消息可以来源于网页。下面的例子就是取得当前日元的汇率,之后发送自己的某一个朋友的手机上

环境:Python3,JetBrains PyCharm Community Edition 2018.2.4 x64,window7

实现的效果如下:

汇率的消息来源于网页

具体实现:

import json
from threading import Timer
from wxpy import *
import requests
import urllib.parse def get_news():
'''获取金山词霸每日一句'''
url = 'http://open.iciba.com/dsapi'
r = requests.get(url)
content = r.json()['content']
note = r.json()['note']
return content, note def send_news():
val = getRequest()
mssage = u'今天的日元汇率为:%s' % val
bot = Bot() # 连接微信,会出现一个登陆微信的二维码
try:
# my_friends =bot.friends().search(u'XXX')[0]#这里是你微信好友的昵称
friends = bot.friends()
for i in friends:
name = i
if "XXX" == name.name:
print(name)
else:
print(name)
break
# my_friend.send(contents[0])
# my_friend.send(contents[1])
name.send(mssage)
t = Timer(86400, send_news) # 这里是一天发送一次,86400s = 24h
t.start()
except:
my_friend = bot.friends().search('filehelper')[0]
my_friend.send(u'今天消息发送失败了') def getRequest():
_header = getHeader()
_data = urllib.parse.urlencode(getData()).encode('utf-8')
url = 'https://webapi.huilv.cc/api/trend/yaho'
response = requests.post(url, data=_data, headers=_header) print(response.encoding)
print(response.apparent_encoding)
r = response.text
result_text = json.loads(r, encoding='utf-8')
val = result_text["obj"][len(result_text["obj"]) -1 ]["huilv"]
return val def getHeader():
header = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Referer': 'https://www.huilv.cc/zoushitu?a=JPYCNY&time=d1',
'Sec-Fetch-Mode': 'cors',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'
}
return header def getData():
paydata = {
'pinzhong': 'JPYCNY',
'longs': 'd1'
}
return paydata if __name__ == '__main__':
get_news()
send_news()

python 实现微信发送消息的更多相关文章

  1. python实现通过企业微信发送消息

    实现了通过企业微信发送消息,平时用于运维的告警还是不错的,相对于邮件来说,实时性更高,不过就是企业微信比较麻烦,此处不做过多解释. 企业微信api的详细请看:http://work.weixin.qq ...

  2. .netcore--Controller后台实现企业微信发送消息

    一.获得企业微信管理端权限,登录企业企业微信管理端界面,并创建应用,如下图中的[网站消息推送] 二.参见企业微信API文献,根据corpid=ID&corpsecret=SECRET(其中企业 ...

  3. python实现微信发送服务器监控报警消息代码实现

    这篇文章主要介绍了python3.8 微信发送服务器监控报警消息代码实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 ! python版本 > ...

  4. python实现定时发送消息

    #!/usr/bin/env python#-*- coding:utf-8 -*- @Author : wujf @Time:2018/8/21 15:59# 自动发送消息from threadin ...

  5. python给邮箱发送消息

    首先要用到两个模块  并且大同你的发送邮箱smtp 最开始测试没打通了好久 smtplib是提供邮箱smtp服务, email是提供你发送消息的格式之类服务 import smtplib from e ...

  6. python特定时间发送消息到微信公众号

    #!/usr/bin/env python# -*- coding: utf-8 -*-# __author__ = 'James'# 导入模块from wxpy import *import tim ...

  7. python登录网页版微信发送消息

    # coding=utf-8 import datetime import time from selenium import webdriver url = "https://wx2.qq ...

  8. python之微信自动发送消息

    代码如下: from __future__ import unicode_literals from threading import Timer from wxpy import * import ...

  9. zabbix微信发送消息脚本

    cat /usr/local/zabbix/share/zabbix/alertscripts/sed_messages_weixin.py python2.x #!/usr/bin/env pyth ...

随机推荐

  1. Centos7 yum安装postgresql 9.5

    添加RPM yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos ...

  2. MapReduce如何解决数据倾斜?

    数据倾斜是日常大数据查询中隐形的一个BUG,遇不到它时你觉得数据倾斜也就是书本博客上的一个无病呻吟的偶然案例,但当你遇到它是你就会懊悔当初怎么不多了解一下这个赫赫有名的事故. https://www. ...

  3. async-validator 表单验证注意事项

    1. this.$refs[formName].validate()里面的内容不执行 解决问题出处:https://segmentfault.com/q/1010000009679079 问题描述:1 ...

  4. Linux 字符集的查看及修改

    一·查看字符集 字符集在系统中体现形式是一个环境变量,以CentOS6.5为例,其查看当前终端使用字符集的方式可以有以下几种方式: 第一种: [root@Testa-www tmp]# echo $L ...

  5. 洛谷 P2212 [USACO14MAR]浇地Watering the Fields 题解

    P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an ir ...

  6. render函数、createElement函数与vm.$slots

    1.render函数.createElement函数 Vue.component('es-header', { render: function (createElement) { return cr ...

  7. Web前端社交账号注册按钮

    [外链图片转存失败(img-vXBQK5k4-1564155857781)(https://upload-images.jianshu.io/upload_images/11158618-ceccff ...

  8. shell脚本编程基础之函数

    函数 作用:代码重用 定义函数: 方法1: function FUNCTION_NAME { #函数名和定义变量名一样,只能包含数字字母下划线,并且不能以数字开头 command } 方法2: FUN ...

  9. Noip2019暑期训练2 反思

    经过两次测试,通过深刻的反思,我主要发现了以下易犯错误: 1.做题目时过于追求速度,导致好几处代码都出现手误打错的现象!而且,千万不要图快.图方便就复制粘贴,非常容易出错!(例如T3-party中直接 ...

  10. 缺陷描述(Description)

    [tips1] 缺陷报告的用途在于: 记录bug 对bug进行分类(发现者.日期.版本.模块.严重程度.优先级) 跟踪bug(new-open-fixed-closed) 对bug进行统计分析.总结 ...