<s> """<STR_LIT>""" <EOL> import getopt <EOL> import json <EOL> import requests <EOL> import os <EOL> import sys <EOL> import urllib <EOL> from keys import FORECAST_API_KEY <EOL> FORECAST_URL = '<STR_LIT>' <EOL> FORECAST_DATPOINT_URL = '<STR_LIT>' <EOL> class Usage ( Exception ) : <EOL> def __init__ ( self , msg ) : <EOL> self . msg = msg <EOL> def main ( argv = None ) : <EOL> OPT_STR = '<STR_LIT>' <EOL> OPT_LIST = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> timestamp = None <EOL> if argv is None : <EOL> argv = sys . argv <EOL> try : <EOL> try : <EOL> progname = argv [ <NUM_LIT:0> ] <EOL> opts , args = getopt . getopt ( argv [ <NUM_LIT:1> : ] , <EOL> OPT_STR , <EOL> OPT_LIST ) <EOL> except getopt . error , msg : <EOL> raise Usage ( msg ) <EOL> for o , a in opts : <EOL> if o in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> print __doc__ <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif o in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> timestamp = a <EOL> if len ( args ) == <NUM_LIT:2> : <EOL> forecast = get_forecast ( args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> ] , timestamp = timestamp ) <EOL> print forecast <EOL> else : <EOL> raise Usage ( '<STR_LIT>' ) <EOL> except Usage , err : <EOL> print >> sys . stderr , err . msg <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> return <NUM_LIT> <EOL> def get_forecast ( latitude , longitude , timestamp = None ) : <EOL> values = { <EOL> '<STR_LIT>' : FORECAST_API_KEY , <EOL> '<STR_LIT>' : latitude , <EOL> '<STR_LIT>' : longitude , <EOL> } <EOL> if timestamp is None : <EOL> api_url = FORECAST_URL <EOL> else : <EOL> api_url = FORECAST_DATPOINT_URL <EOL> values [ '<STR_LIT>' ] = timestamp <EOL> url = api_url % values <EOL> response = requests . get ( url ) <EOL> data = json . loads ( response . text ) <EOL> return data <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
