<s> import os <EOL> import json <EOL> from copy import deepcopy <EOL> from . types import Units , TimeFormats , DateFormats <EOL> WEATHER_CONF_FILE = "<STR_LIT>" <EOL> class Settings ( object ) : <EOL> """<STR_LIT>""" <EOL> _DUMMY_API_KEY = '<STR_LIT>' <EOL> _settings = { <EOL> '<STR_LIT>' : _DUMMY_API_KEY , <EOL> '<STR_LIT>' : Units . ENGLISH , <EOL> '<STR_LIT:time>' : TimeFormats . CIVILIAN , <EOL> '<STR_LIT:date>' : DateFormats . DATE <EOL> } <EOL> def __init__ ( self , args = None ) : <EOL> self . file_path = os . path . expanduser ( WEATHER_CONF_FILE ) <EOL> self . settings = deepcopy ( self . _settings ) <EOL> if not os . path . exists ( self . file_path ) : <EOL> self . generate_default_weatherrc ( ) <EOL> else : <EOL> with open ( self . file_path ) as weatherrc : <EOL> saved_settings = json . load ( weatherrc ) <EOL> for key in saved_settings : <EOL> self . _override ( key , saved_settings ) <EOL> if args is not None : <EOL> self . _override ( "<STR_LIT>" , args ) <EOL> self . _override ( "<STR_LIT:time>" , args ) <EOL> self . _override ( "<STR_LIT:date>" , args ) <EOL> def _override ( self , key , args ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if key in args and args [ key ] is not None : <EOL> self . settings [ key ] = args [ key ] <EOL> except TypeError : <EOL> if getattr ( args , key , self . settings [ key ] ) is not None : <EOL> self . settings [ key ] = getattr ( args , key , self . settings [ key ] ) <EOL> def generate_default_weatherrc ( self ) : <EOL> """<STR_LIT>""" <EOL> with open ( self . file_path , "<STR_LIT:w>" ) as weatherrc : <EOL> weatherrc . write ( json . dumps ( self . settings , sort_keys = True , <EOL> indent = <NUM_LIT:4> , separators = ( '<STR_LIT:U+002C>' , '<STR_LIT>' ) ) ) <EOL> def __getattr__ ( self , attr ) : <EOL> """<STR_LIT>""" <EOL> return self . settings [ attr ] </s>
