29 lines
713 B
Python
29 lines
713 B
Python
#!/usr/bin/python
|
|
import requests, re, time, os
|
|
|
|
def update():
|
|
url = "http://127.0.0.1:8080/update"
|
|
response = requests.get(url)
|
|
print(response)
|
|
|
|
if __name__ == '__main__':
|
|
regex_time = re.compile(r'([1-9][0-9]*)([smhd])')
|
|
formatted_time = os.environ.get('WAIT_TIME')
|
|
units = {
|
|
's':1,
|
|
'm':60,
|
|
'h':3600,
|
|
'd':86400
|
|
}
|
|
match = re.search(regex_time, formatted_time)
|
|
if bool(match):
|
|
raw_time = float(match.group(1))*units[match.group(2)]
|
|
while True:
|
|
try:
|
|
update()
|
|
except:
|
|
print("update failed")
|
|
time.sleep(raw_time)
|
|
else:
|
|
print("WAIT_TIME incorrect")
|