From: Philipp Spitzer Date: Mon, 11 Jun 2018 18:19:49 +0000 (+0200) Subject: Script takes config file from command line now. X-Git-Url: https://git.toastfreeware.priv.at/chrisu/seepark.git/commitdiff_plain/4428ee8f58bcd9b4176a685021497f5eb8bfb105 Script takes config file from command line now. --- diff --git a/owm.py b/owm.py index 1e03670..b21a614 100755 --- a/owm.py +++ b/owm.py @@ -7,6 +7,7 @@ # 3319578 for Obsteig, AT from pprint import pprint +import argparse import requests import configparser import os @@ -67,11 +68,11 @@ def extractweatherdata(w): data['precipitation'] = w['rain']['3h'] if 'rain' in w else 'N/A' return data - -def main(): + +def main(configfile): config = configparser.ConfigParser() - config.read(os.path.expanduser('~/seewasser.ini')) + config.read(configfile) apikey = config.get('openweathermap', 'apikey'); cityid = config.get('openweathermap', 'cityid'); @@ -98,6 +99,10 @@ def main(): str(weather['cloudiness']) ) - + if __name__ == '__main__': - main() + default_config_file = os.path.expanduser('~/seewasser.ini') + parser = argparse.ArgumentParser(description='Get OpenWeathermap data') + parser.add_argument('--config', default=default_config_file, help='configuration file') + args = parser.parse_args() + main(args.config)