1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python自动发送天气信息给微信好友 撩妹专用

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

时间:2021-05-14 04:17:37

相关推荐

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

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

#if __name__ == '__main__':#!/usr/bin/python#coding=utf-8import scheduleimport timeimport randomimport itchatimport urllib.requestimport gzipimport jsonmessage_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 = '/weather_mini?city='+urllib.parse.quote(city_name)url2 = '/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_dictdef 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()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。