diff --git a/tgetwx.py b/tgetwx.py index 3d11797..ba44c15 100755 --- a/tgetwx.py +++ b/tgetwx.py @@ -3,11 +3,11 @@ # Copyright (c) 2014 TundraWare Inc., Des Plaines, IL 60018 USA # All Rights Reserved. For Terms Of Use See: tgetwx-license.txt # For Program Updates See: http://www.tundraware.com/Software/tgetwx -# $Id: tgetwx.py,v 1.100 2014/02/19 18:30:01 tundra Exp $ +# $Id: tgetwx.py,v 1.101 2014/02/19 20:30:40 tundra Exp $ # Embed the source control ID string for use by program -CVSID='$Id: tgetwx.py,v 1.100 2014/02/19 18:30:01 tundra Exp $' +CVSID='$Id: tgetwx.py,v 1.101 2014/02/19 20:30:40 tundra Exp $' ##### # Program Information @@ -29,7 +29,7 @@ # List Of All Legal Options - Update This When You Add More!!!! ##### -OPTIONSLIST = '-f:hv' +OPTIONSLIST = 'Hhv' #----------------------------------------------------------# @@ -46,9 +46,10 @@ #----------------------------------------------------------# import getopt +import json import os import sys -# import tconfpy # Uncomment this and code below to parse config files +import urllib2 #----------------------------------------------------------# @@ -68,11 +69,11 @@ ##### - ##### # Literals ##### +WEATHERURL = 'http://api.openweathermap.org/data/2.5/weather?q=%s' #----------------------------------------------------------# @@ -120,9 +121,9 @@ uTable = [PROGVER, "usage: " + PROGNAME + " [%s]" % optionslist, " where,", - " -f file configuration file to use", - " -h print this help information", - " -v print detailed version information", + " -H Generate HTML (default: text)", + " -h Print this help information", + " -v Print detailed version information", ] @@ -130,7 +131,7 @@ # Global Variables & Data Structures # #----------------------------------------------------------# -CFGFILE = os.path.join(os.getenv("HOME"), "." + "tgetwx") # conf file +HTMLOUT = False #--------------------------- Code Begins Here ---------------------------------# @@ -143,7 +144,7 @@ #----------------------------------------------------------# -# Supporting Function Definitions # +# General Utility Functions # #----------------------------------------------------------# @@ -160,35 +161,6 @@ ##### -# Print A Debug Message -##### - -def DebugMsg(msg): - PrintStderr(PROGNAME + " " + dDEBUG + ": " + msg) - -# End of 'DebugMsg()' - - -##### -# Dump The State Of The Program -##### - -def DumpState(): - - # Dump the command line - DebugMsg(ColumnPad(["Command Line", sys.argv])) - - # Names of all the state variables we want dumped - state = [ - ] - - for k in state: - DebugMsg(ColumnPad([k, eval(k)])) - -# End of 'DumpState()' - - -##### # Print An Error Message ##### @@ -199,16 +171,6 @@ ##### -# Print An Info Message -##### - -def InfoMsg(imsg): - PrintStderr(PROGNAME + " " + iINFO + ": " + imsg) - -# End of 'InfoMsg()' - - -##### # Print To stderr ##### @@ -240,6 +202,22 @@ #----------------------------------------------------------# +# Program-Specific Functions # +#----------------------------------------------------------# + + +def ReportWeather(location, EmitHTML): + + f = urllib2.urlopen(WEATHERURL % location) + json_string = f.read() + parsed_json = json.loads(json_string) + print parsed_json.keys() + f.close() + +# End of 'ReportWeather()' + + +#----------------------------------------------------------# # Program Entry Point # #----------------------------------------------------------# @@ -261,8 +239,8 @@ for opt, val in opts: - if opt == "-f": - CFGFILE=val + if opt == "-H": + HTMLOUT = True if opt == "-h": Usage() @@ -272,22 +250,9 @@ PrintStdout(CVSID) sys.exit(0) -# Processing of the configuration file below requires installation of -# the freely available TundraWare Inc. 'tconfpy' parser and then -# uncommenting the code below. The parser can be found at: -# -# http://www.tundraware.com/Software/tconfpy -# -# Process the configuration file -# -#retval = tconfpy.ParseConfig(CFGFILE, CallingProgram="%s %s " % (PROGNAME, VERSION)) -# -# Print any errors or warning generated by the parse -# -# for x in (retval.ErrMsgs, retval.WarnMsgs): -# for y in x: -# print y -# -# If there were any errors, we're done -#if retval.ErrMsgs: -# sys.exit(0) + +# Command line arguments are presumed to be locations to lookup + +for location in args: + + ReportWeather(location, HTMLOUT)