1.在SqlServer数据库中创建表,保存待发送的微信朋友的备注。
create table weixin_friends
(
ID int primary key identity(1,1) not null ,
FriendNick varchar(50) not null
)
insert into weixin_friends (FriendNick) values('孙聪聪')
2.python程序
定义SqlServer访问类
import pymssql def conn_sqlserver(): conn = pymssql.connect('数据库IP','sa','用户密码','要访问的数据库名') if conn: print('连接成功') return conn ''' 执行Sql语句 ''' def executeSql(sql): conn = conn_sqlserver() cursor = conn.cursor() cursor.execute(sql) conn.commit() cursor.close() conn.close() def executeSqlResult(sql): conn = conn_sqlserver() cursor = conn.cursor() sqlnum = cursor.execute(sql) result = cursor.fetchall() conn.close() return result
3.发送微信
import itchat import sys import sqlserver_conn '''