Skip to content

Instantly share code, notes, and snippets.

@LuchoLopez
Created October 12, 2012 06:44
Show Gist options
  • Save LuchoLopez/3877659 to your computer and use it in GitHub Desktop.
Save LuchoLopez/3877659 to your computer and use it in GitHub Desktop.
A little and simple weather application :)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###########################################################
# Created by Luis Lopez <luislopez72@gmail.com>
# pyweather v0.1
# note: You must install notify-send.
###########################################################
from urllib2 import urlopen
from re import search,findall
from os import system
# To get your zone code, please visit http://weather.yahoo.com/ search for your
# zone's weather and get it from URL ;)
# Example: http://weather.yahoo.com/uruguay/montevideo/montevideo-12799862/
zonecode="12799862"
weather = urlopen("http://weather.yahooapis.com/forecastrss?w=%s&u=c"%(zonecode))
data = weather.read()
weather.close()
if not data:
print "Error al obtener datos"
exit()
tags = findall('<yweather:.+>', data)
data = {}
for tag in tags:
key = search('<yweather:(?P<name>[a-zA-Z]+).*/>', tag).group('name')
values = findall('([a-zA-Z]+)="([^"]+)"', tag)
data [key] = dict((x,y) for (x,y) in values)
msg = """## Actual ##
Estado: {condition[text]}
Temperatura: {condition[temp]}C
Humedad: {atmosphere[humidity]}%
Viento: {wind[speed]}Km/h
Amanecer: {astronomy[sunrise]}
Ocaso: {astronomy[sunset]}
## {forecast[date]} ##
Estado: {forecast[text]}
Maxima: {forecast[high]}C
Minima: {forecast[low]}C"""
notify = "notify-send -u normal 'EL TIEMPO\n'" + '"' + msg.format(**data) + '"'
system(notify)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment