Switch to argparse
The next commit adds a second argument, so raw sys.argv parsing will be a bit cumbersome. Switch to argparse instead.
This commit is contained in:
parent
86c935dea7
commit
8c55892f32
@ -1,4 +1,4 @@
|
||||
import requests, json, sys, signal, os, time
|
||||
import argparse, requests, json, sys, signal, os, time
|
||||
|
||||
PATH = os.getcwd() + "/"
|
||||
version = float(str(sys.version_info[0]) + "." + str(sys.version_info[1]))
|
||||
@ -148,8 +148,11 @@ def updateIPs():
|
||||
commitRecord(ip)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if(len(sys.argv) > 1):
|
||||
if(sys.argv[1] == "--repeat"):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--repeat", type=bool)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.repeat:
|
||||
delay = 5*60
|
||||
print("⏲️ Updating IPv4 (A) & IPv6 (AAAA) records every 5 minutes")
|
||||
next_time = time.time()
|
||||
@ -158,8 +161,6 @@ if __name__ == '__main__':
|
||||
time.sleep(max(0, next_time - time.time()))
|
||||
updateIPs()
|
||||
next_time += (time.time() - next_time) // delay * delay + delay
|
||||
else:
|
||||
print("😡 Unrecognized parameter '" + sys.argv[1] + "'. Stopping now.")
|
||||
else:
|
||||
updateIPs()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user