]> git.sven.stormbind.net Git - sven/scripts.git/commitdiff
Migrate envertech portalmonitor from optparse to argparse module.
authorSven Hoexter <sven@stormbind.net>
Thu, 31 Mar 2022 19:30:18 +0000 (21:30 +0200)
committerSven Hoexter <sven@stormbind.net>
Thu, 31 Mar 2022 19:54:55 +0000 (21:54 +0200)
optparse is deprecated, argparse is the replacement

home/portalmonitor.py

index 3acd3f1766e677469fff2021e60f853af0b1253a..fdae4ba21e67bd9c84458cf3a570cb7e00877d86 100755 (executable)
@@ -1,26 +1,26 @@
 #!/usr/bin/env python3
 
+import argparse
 import requests
 import time
 import sys
 import configparser
 from suntime import Sun
-from optparse import OptionParser
 
-parser = OptionParser(usage="usage: %prog [options]")
-parser.add_option("-s",
+parser = argparse.ArgumentParser()
+parser.add_argument("-s",
                   "--status",
                   action="store_true",
                   dest="printStatus",
                   help="Print Status Information",
                   default=False)
-parser.add_option("-f",
+parser.add_argument("-f",
                   "--force",
                   action="store_true",
                   dest="force",
                   help="Force retrieval of Power value",
                   default=False)
-(options, args) = parser.parse_args()
+args = parser.parse_args()
 
 
 def isDaylight(lat, lon, toleranceSeconds):
@@ -88,12 +88,12 @@ conf.read('portalmonitor.ini')
 
 # retrieve current power value as reported by envertecportal
 if isDaylight(conf['config'].getfloat('lat'), conf['config'].getfloat('lon'),
-              conf['config'].getint('toleranceSeconds')) or options.force:
+              conf['config'].getint('toleranceSeconds')) or args.force:
     currentPower = getCurrentPower(conf['config']['userName'],
                                    conf['config']['password'],
                                    conf['config']['stationId'])
 
-    if options.printStatus:
+    if args.printStatus:
         print(f"Current Power: {currentPower}")
 
     if currentPower == 0: