Date and Time
import json
import re
from subprocess import Popen
from time import sleep
import requests
def set_current_time():
"""Set system clock to the current time if wrong."""
try:
res = requests.get("http://worldtimeapi.org/api/ip")
data = res.text
time_regex = r"\d+:\d+:\d+"
datetime = json.loads(data)['datetime']
date = re.search(time_regex,datetime).group()
Popen(['time',date],shell = True)
return date
except requests.exceptions.ConnectionError:
print('Connection error, please wait retrying,')
sleep(3000)
dt = set_current_time()
dt
# '17:18:27'
Last updated