# -*- coding: utf-8 -*-
import requests, json, itchat
# 每日天气
def getWeather(city, link):
url = link + city
r = requests.get(url).json()
msg = ('\r\n亲爱的,今天是' + r['data']['forecast'][0]['date']
+ '\r\n天气: ' + r['data']['forecast'][0]['type']
+ '\r\n温度: ' + r['data']['forecast'][0]['high'] + '--' + r['data']['forecast'][0]['low']
+ '\r\n风力: ' + r['data']['forecast'][0]['fengli'][9 : -3]
+ '\r\n风向: ' + r['data']['forecast'][0]['fengxiang']
+ '\r\n\r\n' + r['data']['ganmao'])
return str(msg)
# 每日一句
def getWord(link):
r = requests.get(link).json()
msg = '\r\n\r\n' + '每日一句' + '\r\n' + r['content'] + '\r\n' + r['note']
return str(msg)
# 发送微信
def sendWeChat(weather, word, name):
itchat.auto_login(hotReload = True)
users = itchat.search_friends(name = name) #查找好友名字
username = users[0]['UserName'] #获取名字
itchat.send(weather + word, toUserName=username)
if __name__ == '__main__':
city = '南京'
link = 'http://wthrcdn.etouch.cn/weather_mini?city='
link2 = 'http://open.iciba.com/dsapi/'
name = u'Jin'
weather = getWeather(city, link)
word = getWord(link2)
sendWeChat(weather, word, name)
嗯 可以 我来做个
何不做个应用,发到商场,
一来可以造福大众
二来自己可以发家致富
岂不美哉快哉