Script takes config file from command line now.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Mon, 11 Jun 2018 18:19:49 +0000 (20:19 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Mon, 11 Jun 2018 18:19:49 +0000 (20:19 +0200)
owm.py

diff --git a/owm.py b/owm.py
index 1e03670c7dbeb9a8b4e92b86e1b98216ae4c7d7c..b21a61495807f9759a461d4d25ce740a45ac6efd 100755 (executable)
--- a/owm.py
+++ b/owm.py
@@ -7,6 +7,7 @@
 # 3319578 for Obsteig, AT
 
 from pprint import pprint
 # 3319578 for Obsteig, AT
 
 from pprint import pprint
+import argparse
 import requests
 import configparser
 import os
 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
     data['precipitation'] = w['rain']['3h'] if 'rain' in w else 'N/A'
 
     return data
-        
 
 
-def main():
+
+def main(configfile):
     config = configparser.ConfigParser()
     config = configparser.ConfigParser()
-    config.read(os.path.expanduser('~/seewasser.ini'))
+    config.read(configfile)
     apikey = config.get('openweathermap', 'apikey');
     cityid = config.get('openweathermap', 'cityid');
 
     apikey = config.get('openweathermap', 'apikey');
     cityid = config.get('openweathermap', 'cityid');
 
@@ -98,6 +99,10 @@ def main():
         str(weather['cloudiness'])
     )
 
         str(weather['cloudiness'])
     )
 
-    
+
 if __name__ == '__main__':
 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)