# HG changeset patch # User Vlad Glagolev # Date 1324883289 -14400 # Node ID 5e26e170a1211f10ecabb70a223df77900b56db3 # Parent 100d7f29aa6fe2edf2a09c2a9dc7b793624d7308 version 0.3.0 diff -r 100d7f29aa6f -r 5e26e170a121 ChangeLog --- a/ChangeLog Mon Dec 26 10:53:20 2011 +0400 +++ b/ChangeLog Mon Dec 26 11:08:09 2011 +0400 @@ -1,3 +1,8 @@ +2011-12-26 Vlad Glagolev + * version 0.3.0 + * switched to AccuWeather RSS provider + * added ConkyWeather font usage to XSL + 2009-08-09 Vlad Glagolev * version 0.2.0 * fixed max-day limit to 5 as supported by weather.com diff -r 100d7f29aa6f -r 5e26e170a121 MANIFEST.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MANIFEST.in Mon Dec 26 11:08:09 2011 +0400 @@ -0,0 +1,10 @@ +# +# MANIFEST.in +# Manifest template for creating the source distribution. +# + +include ChangeLog +include AUTHORS +include LICENSE +include README +include MANIFEST.in diff -r 100d7f29aa6f -r 5e26e170a121 pycweather/__init__.py --- a/pycweather/__init__.py Mon Dec 26 10:53:20 2011 +0400 +++ b/pycweather/__init__.py Mon Dec 26 11:08:09 2011 +0400 @@ -2,7 +2,7 @@ # # This file is part of PycWeather # -# Copyright (c) 2008-2009 Vlad Glagolev +# Copyright (c) 2008-2011 Vlad Glagolev # All rights reserved. # # Permission to use, copy, modify, and distribute this software for any @@ -19,4 +19,4 @@ """ pycweather/__init__.py: initialization script """ -__version__ = "0.2.1" +__version__ = "0.3.0" diff -r 100d7f29aa6f -r 5e26e170a121 pycweather/dmanager.py --- a/pycweather/dmanager.py Mon Dec 26 10:53:20 2011 +0400 +++ b/pycweather/dmanager.py Mon Dec 26 11:08:09 2011 +0400 @@ -2,7 +2,7 @@ # # This file is part of PycWeather # -# Copyright (c) 2008-2009 Vlad Glagolev +# Copyright (c) 2008-2011 Vlad Glagolev # All rights reserved. # # Permission to use, copy, modify, and distribute this software for any @@ -27,23 +27,17 @@ from pycweather import weather -# default values stay for Moscow (RU) location, 1 days to display (means only -# current day), metric measurement system and internal XSL stylesheet usage -_CODE = "RSXX0063" -_DAYS = 1 -_UNIT = "m" +# default values stay for Moscow (RU) location and internal XSL stylesheet usage +_CODE = "ASI|RU|RS052|MOSCOW|" def usage(): print """Usage: %s [options]\n -h, --help show this help -v, --version version information - -a, --auth authority data in format: partner-id:license-key -c, --code location ID code (default is %s) - -d, --days number of days to display [1-5] (default is %d) - -u, --unit measurement system [m]etric|[i]mperial (default is %s) - -s, --search search for the specified location (city, state, etc.) - -x, --xsl custom XSL file\n""" % (sys.argv[0], _CODE, _DAYS, _UNIT) + -m, --metric use metric measurement system + -x, --xsl custom XSL file\n""" % (sys.argv[0], _CODE) def version(): @@ -56,15 +50,15 @@ def main(template): try: - opts, args = getopt.getopt(sys.argv[1:], "hva:c:d:u:s:x:", ["help", \ - "version", "auth=", "code=", "days=", \ - "unit=", "search=", "xsl="]) + opts, args = getopt.getopt(sys.argv[1:], "hvc:mx:", ["help", \ + "version", "code=", "metric", "xsl="]) except getopt.error, msg: print msg usage() exit(2) forecast = weather.Weather() + metric = 0 for o, a in opts: if o in ("-h", "--help"): @@ -72,17 +66,10 @@ exit(0) elif o in ("-v", "--version"): version() - elif o in ("-a", "--auth"): - forecast.auth(a) elif o in ("-c", "--code"): code = a - elif o in ("-d", "--days"): - days = int(a) if a != "" else _DAYS - elif o in ("-u", "--unit"): - unit = a - elif o in ("-s", "--search"): - forecast.search(a) - exit(0) + elif o in ("-m", "--metric"): + metric = 1 elif o in ("-x", "--xsl"): xsl = a @@ -92,24 +79,10 @@ code = _CODE try: - days - except NameError: - days = _DAYS - - try: - unit - except NameError: - unit = _UNIT - - try: xsl except NameError: xsl = template forecast.load(xsl) - if forecast.id and forecast.key: - forecast.preview(code, days, unit) - else: - print "Get partner ID and license key at: " + \ - "http://registration.weather.com/ursa/xmloap/step1" + forecast.preview(code, metric) diff -r 100d7f29aa6f -r 5e26e170a121 pycweather/weather.py --- a/pycweather/weather.py Mon Dec 26 10:53:20 2011 +0400 +++ b/pycweather/weather.py Mon Dec 26 11:08:09 2011 +0400 @@ -2,7 +2,7 @@ # # This file is part of PycWeather # -# Copyright (c) 2009 Vlad Glagolev +# Copyright (c) 2009-2011 Vlad Glagolev # All rights reserved. # # Permission to use, copy, modify, and distribute this software for any @@ -27,45 +27,14 @@ from pycweather import __version__ -# correct url to the XOAP service -XOAP_URL = "http://xoap.weather.com/" +# correct url to AccuWeather RSS service +RSS_URL = "http://rss.accuweather.com/rss/liveweather_rss.asp" class Weather: def __init__(self): self.xsl = None - self.id = None - self.key = None - - def auth(self, credentials): - try: - self.id, self.key = credentials.split(":") - except: - print "Invalid credentials" - - def search(self, location): - data = urlopen(XOAP_URL + "search/search?where=%s" % location) - - tree = data.read() - - try: - xml = fromstring(tree) - except XMLSyntaxError: - print "XML syntax error occured while parsing content: ", tree - - return -1 - - if not xml.getchildren(): - print "No location has been found!" - elif xml.tag == "error": - print "Error: %s" % xml.getchildren()[0].text - else: - print "Code | Location\n--------+----------" - for loc in xml.xpath("loc"): - print loc.get("id") + ": " + loc.text - - print "--\nTo catch weather information use: pycweather -c " def load(self, xsl_file): try: @@ -75,13 +44,11 @@ except: print "Unable to read XSL file" - def preview(self, code, days, unit): + def preview(self, code, metric): try: - data = urlopen(XOAP_URL + \ - "weather/local/%s?cc=*&dayf=%d&unit=%s&par=%s&key=%s" % \ - (code, days, unit, self.id, self.key)) + data = urlopen(RSS_URL + "?metric=%d&locCode=%s" % (metric, code)) except: - print "Unable to connect to %s" % XOAP_URL + print "Unable to connect to %s" % RSS_URL return -1 @@ -94,11 +61,10 @@ return -1 - if xml.tag == "error": - print "Error: %s" % xml.xpath("err")[0].text - - return -1 + if xml.xpath("channel/description")[0].text == "Invalid Location": + print "Wrong location code, get one at www.accuweather.com" + exit(2) else: document = parse(StringIO(tostring(xml))) - print document.xslt(self.xsl) + print document.xslt(self.xsl) diff -r 100d7f29aa6f -r 5e26e170a121 setup.py --- a/setup.py Mon Dec 26 10:53:20 2011 +0400 +++ b/setup.py Mon Dec 26 11:08:09 2011 +0400 @@ -33,7 +33,7 @@ author_email = "enqlave@gmail.com", packages = ["pycweather"], scripts = ["bin/pycweather"], - data_files = [('share/pycweather', ["share/template.xsl"])], + data_files = [('share/pycweather', ["share/template.xsl", "share/ConkyWeather.ttf"])], description = "Weather display manager for conky", platforms = ["Linux", "Unix"], long_description = "PycWeather is pure-pythonic weather display manager \ diff -r 100d7f29aa6f -r 5e26e170a121 share/template.xsl --- a/share/template.xsl Mon Dec 26 10:53:20 2011 +0400 +++ b/share/template.xsl Mon Dec 26 11:08:09 2011 +0400 @@ -3,7 +3,7 @@ This file is part of PycWeather -Copyright (c) 2009 Vlad Glagolev . All rights reserved. +Copyright (c) 2009-2011 Vlad Glagolev . All rights reserved. Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -20,63 +20,136 @@ --> + - - - - PycWeather - - - Location: (, ) - Temperature: ° - - Windchill: ° - - Conditions: - Wind: + + + - - 0 + + + + - + - - () - - - - + + + PycWeather 0.3.0 + Location: + Update Time: + + - + + - , - - (Tomorrow) - - : - - - + + + + + + - - Day ( - ° + + a + + + b + + + c + + + c + + + c + + + d + + + e + + + e + + + 0 + + + h + + + g + + + l + + + k + + + i + + p + + + o + + + r + + + E + + + u + + + v + + + 5 + + + 6 + + + A + + + B + + + C + + + G + + + K + + + O + + - Night ( - ° + - - , - - ) - - ; + -- + + + : +