Mercurial > pycweather
changeset 0:086863cd711d
pycweather: initial commit
| author | Vlad Glagolev <enqlave@gmail.com> |
|---|---|
| date | Thu, 06 Nov 2008 22:45:06 +0300 |
| parents | |
| children | 5c91081c6c61 |
| files | AUTHORS ChangeLog LICENSE README bin/pycweather pycweather/__init__.py pycweather/dmanager.py pycweather/template.py setup.cfg setup.py |
| diffstat | 10 files changed, 390 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AUTHORS Thu Nov 06 22:45:06 2008 +0300 @@ -0,0 +1,1 @@ +Vlad Glagolev <enqlave::at::gmail::dot::dom>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ChangeLog Thu Nov 06 22:45:06 2008 +0300 @@ -0,0 +1,2 @@ +2008-11-06 Vlad Glagolev <enqlave@gmail.com> + * initial release
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE Thu Nov 06 22:45:06 2008 +0300 @@ -0,0 +1,13 @@ +Copyright (c) 2008 Vlad Glagolev <enqlave@gmail.com>. 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 +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README Thu Nov 06 22:45:06 2008 +0300 @@ -0,0 +1,16 @@ +PycWeather +========== + +PycWeather is a weather display manager for Conky +(http://conky.sourceforge.net/) system monitor. + + +Requirements +------------ +Python >=2.5 +lxml >=2.0 + + +Reporting bugs +-------------- +Please report bugs at: http://dev.enqlave.net/pycweather
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/pycweather Thu Nov 06 22:45:06 2008 +0300 @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# This file is part of PycWeather +# +# Copyright (c) 2008 Vlad Glagolev <enqlave@gmail.com>. 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 +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +""" pycweather: PycWeather primary script """ + +from pycweather import dmanager + + +if __name__ == "__main__": + dmanager.main()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pycweather/__init__.py Thu Nov 06 22:45:06 2008 +0300 @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# +# This file is part of PycWeather +# +# Copyright (c) 2008 Vlad Glagolev <enqlave@gmail.com>. 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 +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +""" pycweather/__init__.py: initialization script """ + +__version__ = "0.1.1"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pycweather/dmanager.py Thu Nov 06 22:45:06 2008 +0300 @@ -0,0 +1,174 @@ +# -*- coding: utf-8 -*- +# +# This file is part of PycWeather +# +# Copyright (c) 2008 Vlad Glagolev <enqlave@gmail.com>. 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 +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +""" pycweather/dmanager.py: weather display manager """ + +from cStringIO import StringIO +import getopt +import os +import sys +import urllib2 + +from lxml.etree import parse, tostring, fromstring, XMLSyntaxError + +from pycweather import __version__ +from pycweather.template import XSL + + +# correct url to the XOAP service +XOAP_URL = "http://xoap.weather.com/" + +# default values stay for Moscow (RU) location, 0 days to display (means only +# current day), metric measurement system and internal XSL stylesheet usage +_CODE = "RSXX0063" +_DAYS = 1 +_UNIT = "m" +_XSL = None + + +def usage(): + print """Usage: %s [options]\n + -h, --help show this help + -v, --version version information + -c, --code <code> location ID code (default is %s) + -d, --days <days> number of days to display [1-10] (default is %d) + -u, --unit <unit> measurement system [m]etric|[i]mperial (default is %s) + -s, --search <word> search for the specified location (city, state, etc.) + -i, --int dump internal XSL stylesheet to stdout + -x, --xsl <file> custom XSL file\n""" % (sys.argv[0], _CODE, _DAYS, _UNIT) + + +def version(): + print """PycWeather version: + %s. (major) + %s. (minor) + %s (revision)""" % tuple(__version__.split(".")) + exit(0) + + +def search(location): + data = urllib2.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 + exit(2) + + 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: %s -c <code>" % sys.argv[0] + + exit(0) + + +def preview(xml, xsl): + try: + xsl_file = parse(xsl) if xsl else fromstring(XSL) + except XMLSyntaxError: + print "XML syntax error occured while parsing XSL stylesheet" + exit(2) + + document = parse(StringIO(tostring(xml))) + + print document.xslt(xsl_file) + + +def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], "hvc:d:u:s:ix:", ["help", \ + "version", "code=", "days=", "unit=", \ + "search=", "int", "xsl="]) + except getopt.error, msg: + print msg + usage() + exit(2) + + for o, a in opts: + if o in ("-h", "--help"): + usage() + exit(0) + elif o in ("-v", "--version"): + version() + 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"): + search(a) + elif o in ("-i", "--int"): + print XSL + exit(0) + elif o in ("-x", "--xsl"): + xsl = a + + try: + code + except NameError: + code = _CODE + + try: + days + except NameError: + days = _DAYS + + try: + unit + except NameError: + unit = _UNIT + + try: + xsl + + if not os.access(xsl, os.R_OK): + print "Error reading custom XSL file, using internal stylesheet..." + xsl = _XSL + except NameError: + xsl = _XSL + + try: + data = urllib2.urlopen(XOAP_URL + \ + "weather/local/%s?cc=*&dayf=%d&unit=%s" % (code, + days, unit)) + except: + print "Unable to connect to %s" % XOAP_URL + exit(2) + + tree = data.read() + + try: + xml = fromstring(tree) + except XMLSyntaxError: + print "XML syntax error occured while parsing content: ", tree + exit(2) + + if xml.tag == "error": + print "Error: %s" % xml.xpath("err")[0].text + else: + preview(xml, xsl)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pycweather/template.py Thu Nov 06 22:45:06 2008 +0300 @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +# +# This file is part of PycWeather +# +# Copyright (c) 2008 Vlad Glagolev <enqlave@gmail.com>. 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 +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +""" pycweather/template.py: XSL stylesheet for displaying weather """ + +from pycweather import __version__ + + +XSL = """<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> + <xsl:output method="text" disable-output-escaping="yes"/> + <xsl:variable name="nl"> + <xsl:text> </xsl:text> + </xsl:variable> + <xsl:template match="weather"> + <xsl:apply-templates select="cc"/> + <xsl:apply-templates select="dayf"/> + <xsl:comment>PycWeather %s</xsl:comment> + </xsl:template> + <xsl:template match="cc"> + <xsl:text>Location: </xsl:text><xsl:value-of select="obst"/><xsl:text> (</xsl:text><xsl:value-of select="../loc/lat"/><xsl:text>, </xsl:text><xsl:value-of select="../loc/lon"/><xsl:text>)</xsl:text><xsl:value-of select="$nl"/> + <xsl:text>Temperature: </xsl:text><xsl:value-of select="tmp"/>°<xsl:value-of select="../head/ut"/><xsl:value-of select="$nl"/> + <xsl:if test="tmp != flik"> + <xsl:text>Windchill: </xsl:text><xsl:value-of select="flik"/>°<xsl:value-of select="../head/ut"/><xsl:value-of select="$nl"/> + </xsl:if> + <xsl:text>Conditions: </xsl:text><xsl:value-of select="t"/><xsl:value-of select="$nl"/> + <xsl:text>Wind: </xsl:text> + <xsl:choose> + <xsl:when test="wind/s = 'calm'"> + <xsl:text>0</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="wind/s"/> + </xsl:otherwise> + </xsl:choose> + <xsl:value-of select="../head/us"/> + <xsl:text> (</xsl:text><xsl:value-of select="wind/t"/><xsl:text>)</xsl:text> + </xsl:template> + <!-- MULTIPLE DAYS DISPLAY --> + <xsl:template match="dayf"> + <!-- don't repeat the first one --> + <xsl:apply-templates select="child::day[position() > 1]"/> + </xsl:template> + <xsl:template match="day"> + <xsl:value-of select="$nl"/> + <xsl:value-of select="@dt"/><xsl:text>, </xsl:text><xsl:value-of select="@t"/> + <xsl:if test="@d = 1"> + <xsl:text> (Tomorrow)</xsl:text> + </xsl:if> + <xsl:text>: </xsl:text> + <xsl:apply-templates select="part"/> + </xsl:template> + <xsl:template match="part"> + <xsl:choose> + <xsl:when test="@p = 'd'"> + <xsl:text>Day (</xsl:text> + <xsl:value-of select="../hi"/>°<xsl:value-of select="../../../head/ut"/> + </xsl:when> + <xsl:otherwise> + <xsl:text>Night (</xsl:text> + <xsl:value-of select="../low"/>°<xsl:value-of select="../../../head/ut"/> + </xsl:otherwise> + </xsl:choose> + <xsl:text>, </xsl:text> + <xsl:apply-templates select="t"/> + <xsl:text>)</xsl:text> + <xsl:if test="@p = 'd'"> + <xsl:text>; </xsl:text> + </xsl:if> + </xsl:template> +</xsl:stylesheet>""" % __version__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.cfg Thu Nov 06 22:45:06 2008 +0300 @@ -0,0 +1,3 @@ +[install] +compile = 1 +optimize = 1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Thu Nov 06 22:45:06 2008 +0300 @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# This file is part of PycWeather +# +# Copyright (c) 2008 Vlad Glagolev <enqlave@gmail.com>. 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 +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +""" setup.py: PycWeather setup script """ + +from distutils.core import setup + +from pycweather import __version__ + +setup( + name = "pycweather", + url = "http://pycweather.enqlave.net/", + version = __version__, + download_url = "http://pycweather.enqlave.net/releases/pycweather-%s.tar.gz" % __version__, + author = "Vlad Glagolev", + author_email = "enqlave@gmail.com", + packages = ["pycweather"], + scripts = ["bin/pycweather"], + data_files = ["AUTHORS", "LICENSE", "README", "ChangeLog"], + description = "Weather display manager for conky", + platforms = ["Linux", "Unix"], + long_description = "PycWeather is pure-pythonic weather display manager \ + for Conky system monitor.", + license = "ISC", + classifiers = [ + "Topic :: Desktop Environment", + "Programming Language :: Python", + "Operating System :: POSIX", + "License :: OSI Approved :: ISC License", + "Natural Language :: English", + "Intended Audience :: End Users/Desktop", + ] +)
