每天自動給自己發天氣預報的腳本

需求:

每天早上起來可以看看天氣預報,然后順便當個鬧鐘使

思路是這樣的:

模塊一:采用yahoo weather api獲取北京的天氣

模塊二:通過網頁版飛信,模擬飛信登陸,給自己發短信

模塊三:發送信息

?

一。get_yahoo_weather.py

#!/usr/bin/env python
#coding=utf-8
import urllib2
from xml.etree import cElementTree as ET
class GetWeather:def __init__(self):self.weather = self.makexml()def makexml(self):url = "http://weather.yahooapis.com/forecastrss?w=2151330&u=c"res = urllib2.urlopen(url)xmlfile = open("yahoo.xml",'w')xmlfile.writelines(res.read())xmlfile.close()return self.xmlET()def xmlET(self):tree = ET.ElementTree(file="yahoo.xml")forecast = []for elem in tree.iter(tag="{http://xml.weather.yahoo.com/ns/rss/1.0}forecast"):forecast.append(elem.attrib)return self.msg(forecast)def msg(self,forecast):msg_data = ""fmt = "\n%s              %s    %s   %s\n"%("日期","天氣","最高溫","最低溫")msg_data += fmtfor i in forecast:msg_data += "%s        %s    %s    %s"%(i['date'],i['text'],i['high'],i['low'])msg_data +="\n"return msg_dataif __name__ == "__main__":w = GetWeather()print w.weather

二。fetionsimu.py

#!/usr/bin/env python
#coding=utf-8import cookielib
import urllib
import urllib2
import json
import re
import timedef fetion(weather_msg = "no data"):cj = cookielib.LWPCookieJar()opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))urllib2.install_opener(opener)t = time.localtime()print t.tm_year,t.tm_mon,t.tm_mdayprint "logining"urlbase = "http://f.10086.cn/im5/" response_text = urllib2.urlopen(urlbase)response_text = response_text.read()partten = re.compile(r'login/login\.action\?mnative=\d&t=\d+')urlplus = partten.search(response_text)urlcomplete = urlbase + urlplus.group(0)
#    print urlcompleteqheader = {'Referer':urlcomplete}args = {'m':'your phone number','pass':'your password'}logurl = "http://f.10086.cn/im5/login/loginHtml5.action"req = urllib2.Request(logurl,urllib.urlencode(args),qheader)jump = opener.open(req)page = jump.read()
#    print pagepage = json.loads(page)if page['nickname'] == "LGY":print "login successfully"else:print "error in pass or username"sendmsgurl = "http://f.10086.cn/im5/chat/sendNewGroupShortMsg.action"msg_data = {"touserid":page["idUser"],"msg":weather_msg}msg_back = urllib2.Request(sendmsgurl,urllib.urlencode(msg_data),qheader)msg_jump = opener.open(msg_back)msguse = msg_jump.read()msguse = json.loads(msguse)if msguse["info"] == u"發送成功":print "send successfully"else:print msguseprint "send failed"
if __name__ == "__main__":fetion()

三。sendweather.py

#!/usr/bin/env pythonimport time
from get_yahoo_weather import GetWeather
from fetionsimu import fetion
def sendmsg(w):fetion(w)if __name__ == "__main__":w = GetWeather()sendmsg(w.weather)

?

最后加入開機啟動

用crontab -e編輯開機啟動項

0 7 * * * /test/mkfun/sendweather.py > /test/mkfun/sdwthmsg.log 2>&1

然后就ok了。。。

轉載于:https://www.cnblogs.com/lgy6534588/p/3459120.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377488.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377488.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377488.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

YYSSW的完整格式是什么?

YYSSW:是的,肯定的,無論如何 (YYSSW: Yeah Yeah Sure Sure Whatever) YYSSW is an abbreviation of "Yeah Yeah Sure Sure Whatever". YYSSW的縮寫是“ Yeah Yeah Sure Sure Whatever” 。 It is an expression, which is commonl…

Json轉二值圖像

Json文件通過labelme進行標識 image路徑 G:\PyCharm\workspace\unet_42-master\datasets\label_bz\test\image label路徑 G:\PyCharm\workspace\unet_42-master\datasets\label_bz\test\label 待轉換路徑 G:\PyCharm\workspace\unet_42-master\datasets\label_bz\test\mask …

矩形波傅里葉變換對以及三角波傅里葉變換

時域矩形波->頻域sinc 時域三角波->頻域sinc^2:

關于蘋果IPhone/Ipad(IOS)開發者證書申請及安裝、真機調試、發布的參考文章

這是我在申請、安裝IOS開發者證書,真機調試時候參考的文章,非常有用。 1、開發證書與發布證書申請和安裝步驟 http://blog.csdn.net/zougangx/article/details/6074313 2、申請IDP/真機調試/GameCenter 指南/OpenFeint指南: http://xiaomingh…

scrollTop

chrome 不支持 document.documentElement.scrollTopfirefox 不支持 document.body.scrollTop 解決辦法var sTopdocument.body.scrollTopdocument.documentElement.scrollTop; var nowScrollTop document.body.scrollTopdocument.documentElement.scrollTop; document.body.scr…

INTERNET的完整形式是什么?

互聯網:互聯網絡 (INTERNET: Interconnected Network) INTERNET is an abbreviation of Interconnected Network of all the Web Servers Worldwide. It is also known as the World Wide Web or in simple terms the Web. INTERNET是全球所有Web服務器的互連網絡的…

DMA三種方式以及DMA特點

博主聯系方式: QQ:1540984562 QQ交流群:892023501 群里會有往屆的smarters和電賽選手,群里也會不時分享一些有用的資料,有問題可以在群里多問問。 DMA三種方式:數據塊傳送方式、周期挪用方式、交替訪存方式 數據塊傳送…

進程通信

進程間通信就是在不同進程之間傳播或交換信息,進程間控制信息的交換稱為低級通信,進程間大批量數據的交換稱為高級通信。 進程通信分為3種: 1.共享存儲器系統:為了傳送大量數據,在存儲器中劃出一塊共享存儲…

界面邊框圓角

界面邊框圓角的實現方式同樣是在res/drawable中定義一個XML文件&#xff0c;corners.xml的代碼如下&#xff1a; 1<?xml version"1.0" encoding"utf-8"?>2<shape xmlns:android"http://schemas.android.com/apk/res/android"> 3 …

CGPA的完整形式是什么?

CGPA&#xff1a;累積平均績點 (CGPA: Cumulative Grade Point Average) CGPA is an abbreviation of Cumulative Grade Point Average. It is a grading system in education. It is used in measuring the overall academic performance average of a student in schools and…

二、頁面布局

一、界面 我做的界面大概思路&#xff1a;點擊 上傳圖片&#xff0c;顯示待檢驗的照片 點擊 U-net模型檢測 會使用已經訓練好的U-net模型進行預測 點擊 OpenCV統計 會將預測結果進行輪廓檢測&#xff0c;并統計所有輪廓的面積 在 處理結果 這個groupBox中進行顯示 大致界面如…

GNU工具以及GCC對C語言程序的處理流程

GCC是一族工具的集合&#xff0c;包含預處理器、編譯器、匯編器、鏈接器。 對于默認的文件名&#xff0c;GCC可以自動選擇工具自動完成文件處理過程。 從C語言的源程序道可執行文件&#xff0c;實質上是依靠GCC調用一系列工具完成的。 GCC默認處理的文件 文件類型擴展名文件說…

Professional C++讀書筆記05

2012-05-20 Chapter09 1、復制構造函數淺復制時的隱患 若對象中有指針成員&#xff0c;則當對象作為形參傳入時 例如void myFun(Spreadsheet s)…… Spreadsheet s1(5,3); myFun(s1);// s1與s中的指針成員指向同一塊內存&#xff08;s是由s1通過復制構造函數生成的&#xff…

請不要對我說“你要馬上把這個小問題修改好”

“我需要”&#xff0c;“小問題”&#xff0c;“立刻”。你激怒我了。你的每個詞都激怒我了。這種情緒很難翻譯成英語表達&#xff0c;但在荷蘭&#xff0c;有些人就是用這種方式要求你。翻譯成英語&#xff0c;這有點像“你要幾分鐘內把這個東西修改好”。大家都知道的這樣的…

javascript 常量_JavaScript中的常量

javascript 常量JavaScript常數 (JavaScript Constants) Before ES15, the only way to declare variables using the var keyword. JavaScripts inbuilt feature of hoisting variables could be carried out using the var keyword. If youre unfamiliar with variables in J…

GDB與遠程(交叉)GDB調試

GDB提供的功能 1、啟動的程序&#xff0c;可以按照自定義的要求運行程序 2、可以讓被調試的程序在指定的斷點處停住(斷點可以是條件表達式) 3、當程序被停住時&#xff0c;可以檢查這個時候程序中發生的事 4、動態地改變程序的運行環境。 遠程&#xff08;交叉&#xff09;GD…

OTR-Linux控制臺打印顏色區分.

What I write, what I lost. 對于依靠打印來作debug的主要手段的, 能夠區分打印中的debug信息和error信息便顯得非常重要. 原文的介紹有一篇關于控制臺顏色的文章http://www.ibm.com/developerworks/cn/linux/l-tip-prompt/tip01/ 有定義實現各種顏色的方式. 以此為基礎, 方式挺…

c#異常處理_C#中的異常處理

c#異常處理What an exception is? 有什么例外&#xff1f; An exception is a runtime error; that means an abnormal situation which is created at run time and the program doesn’t execute successfully. Due to the exceptions, our program gets crash. 異常是運行…

(轉)走進AngularJs(六) 服務

原文地址&#xff1a;http://www.cnblogs.com/lvdabao/p/3464015.html 今天學習了一下ng的service機制&#xff0c;作為ng的基本知識之一&#xff0c;有必要做一個了解&#xff0c;在此做個筆記記錄一下。 一、認識服務&#xff08;service&#xff09; 服務這個概念其實并不陌…

Linux驅動程序框架以及概述

目錄驅動程序三種基本類型&#xff08;組成&#xff09;設備驅動程序功能驅動程序的內核模塊機制&#xff08;開發模式&#xff09;驅動程序框架三個主要部分1、字符設備驅動程序框架2、塊設備驅動程序框架2、網絡設備驅動程序框架驅動程序三種基本類型&#xff08;組成&#x…