1、发送微信消息
需要安装PIL库
PIL是一个功能非常强大的Python图像处理标准库,但是呢由于PIL支持Python2.7,所以使用Python3的程序员又在PIL的基础上分离出来了一个分支,创建了另外一个库Pillow,是可以支持Python3的。
Pillow兼容了PIL的大部分语法,使用起来也非常的简单。
因博主用的是3.7的版本,以下教程为安装Pillow,已安装可跳过
在cmd命令行模式下,输入命令:pip install pillow 即可。(前提是先要把python程序安装好)
这里有个坑要注意:需要先找到python3.7安装目录下的pip包,然后再执行命令,否则会报错无法执行。执行的目录位置如下:
可能在安装的过程中遇到各种总题 ,我将我遇到的问题整理了一下
因为我安装的Python3.7是在python卸载掉的情况下安装的,我也不清楚有没有卸载干净,结果遇到的第一个问题是需要将pip升级
出现以下错误提示
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
解决方案:
pip install --upgrade pip
我升级时各种不成功,各种错误都有,比如
ModuleNotFoundError: No module named 'pip'
Requirement already up-to-date
我都不知道问题在哪里,终于找到一篇文章的解决方案成功了,分享给大家,链接为https://blog.csdn.net/qq_21437451/article/details/81490932
cmd下,输入如下命令:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py --force-reinstall
pip show pip
如果无法验证也不要紧,直接重回上面的步骤安装Pillow,即输入命令:pip install pillow
如果无法安装成功,需要去python3.7的安装目录下找到Lib文件夹下的site-packages文件夹下是否有pip-19.1.1.dist-info文件夹(版本不一样的话可能是18.1.1之类的),如果有这个文件夹请删除,不过最后先备份一份,免得问题不是在这里就尴尬了,再运行,就可以安装成功了,博主我就是这么安装成功的,嘻嘻,放个链接,可能对你们有用https://blog.csdn.net/u012145252/article/details/82628419
发送消息的代码如下
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
import random
bot=Bot()
def Send_News(contents,friendName,sendTime):
try:
my_friend = bot.friends().search(friendName)[0]
contents = list(contents)
for c in contents:
my_friend.send(c)
t = Timer(sendTime,Send_News,[contents,friendName,sendTime])
t.start()
except:
my_friend = bot.friends().search(friendName)[0]
my_friend.send(u"发送失败")
print("发送失败")
# 发送的内容
content = ['从来没想过','不能再和你牵手','委屈时候没有你','陪着我心痛','一切都是我 太过娇纵','以为你会懂','一直忘了说','我有多感动']
# friendName必须是你朋友的微信名称,不是备注,也不是微信帐号。
friendName = "一条鱼鱼的冒泡理论。"
* 做了个定时发送,如不需要可以去掉
sendTime = 10
Send_News(content,friendName,sendTime)
群聊和朋友圈的代码有时候我再奉上,如有疑问请在下方留言,谢谢