python自动发送天气信息给微信好友 撩妹专用

最近根据一些开源脚本,用python写了一个每天定时给微信好友发送天气情况的脚本,可以用于关心女朋友。

#if __name__ == '__main__':#!/usr/bin/python
#coding=utf-8
import schedule
import time
import random
import itchat
import urllib.request
import gzip
import json

message_list = [u' 有些路很远,走下去会很累。可是,不走,会后悔。',
                u'爱情不是依附,爱情是各自独立坚强,然后努力走到一起。',
                u'在无数个失眠的晚上,相信会有很多人,习惯性的闭上眼睛,安静的想念一个人。',
                u'想念一张脸。我也如此,闭上眼,脑海满满都是你的样子,挥之不去。',
                u'爱,或者被爱,都不如相爱。',
                u'你爱我,我会陪你;你不爱我,我给你自由。这就是傻傻的我,那个在乎你的我。',
                u'如果没有如果,时间是否会为我们停留?曾经看过的夕阳,听过的潮落,都被时间掩埋,幻成泡沫。',
                u'喜欢记忆中,你拥抱我的温度。喜欢记忆中,你体贴的话语。喜欢记忆中,你给我依靠的肩膀……',
                u'只要你记得我,我不介意整个世界都把我遗忘了。',
                u'如果爱情是需要不顾一切的去付出,那么很显然,对方并不会太在乎你的感受。因为一个在乎你的人,是不舍得你受到任何伤害的。',
                u'想你的时候,如果你不知道,我会感到孤单。想你的时候,你知道我在想你,我内心已经有了慰藉。想你的时候,如果你也在想我,我就会感觉甜蜜。',
                u'遇见,拉着你的手,无论是在哪里,我都感觉像是朝天堂奔跑,你相信么?',
                u'每晚睡前听你说晚安,是属于我的,最简单而持久的幸福。',
                u'夕阳西下,是我最想念的时候,对着你在的那个城市,说了一声:我想你,不知道,你是否听得到。',
                u'我爱你,不仅仅是一句甜言蜜语,我愿意用行动来证明。“亲爱的,坐稳了!”',
                u'The time that you are my most fatal. 时光深知你是我最致命的爱人',
                u'你可不可以看着我的眼,就当是我的奢望']
@itchat.msg_register(itchat.content.TEXT)
def get_weather_data() :
    city_name = '成都'
    url1 = 'http://wthrcdn.etouch.cn/weather_mini?city='+urllib.parse.quote(city_name)
    url2 = 'http://wthrcdn.etouch.cn/weather_mini?citykey=101010100'
    #网址1只需要输入城市名,网址2需要输入城市代码
    #print(url1)
    weather_data = urllib.request.urlopen(url1).read()
    #读取网页数据
    weather_data = gzip.decompress(weather_data).decode('utf-8')
    #解压网页数据
    weather_dict = json.loads(weather_data)
    #将json数据转换为dict数据
    return weather_dict

def show_weather(weather_data, usrname):
    weather_dict = weather_data
    #将json数据转换为dict数据
    forecast=weather_dict.get('data').get('forecast')
    message='------天气服务------\n'
    message += '城市:' + weather_dict.get('data').get('city') + '\n'
    message += '温度:' + weather_dict.get('data').get('wendu') + '℃ ' + '\n'
    message += '感冒:' + weather_dict.get('data').get('ganmao') + '\n'
    message += '风向:' + forecast[0].get('fengxiang') + '\n'
    message += '风级:' + forecast[0].get('fengli') + '\n'
    message += '高温:' + forecast[0].get('high') + '\n'
    message += '低温:' + forecast[0].get('low') + '\n'
    message += '天气:' + forecast[0].get('type') + '\n'
    message += '日期:' + forecast[0].get('date') + '\n'
    message += '*******************************' + '\n'
    message += '风级:' + forecast[1].get('fengli') + '\n'
    message += '高温:' + forecast[1].get('high') + '\n'
    message += '低温:' + forecast[1].get('low') + '\n'
    message += '天气:' + forecast[1].get('type') + '\n'
    message += '日期:' + forecast[1].get('date') + '\n'
    message += '***********************************' + '\n'
    itchat.send(message, usrname)
    message_concent = random.sample(message_list,1)[0]
    itchat.send(message_concent, usrname)
def job():
	show_weather(get_weather_data(), leilei)
if __name__ == '__main__':
    itchat.auto_login()
    time.sleep(5)
    name = itchat.search_friends(name=u'leilei')
    leilei = name[0]["UserName"]
    runtime="08:01:01"
    while True:    
        if runtime == time.strftime("%H:%M:%S"):
            job()

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值