Mar-31-2019, 08:49 PM
Hi,
This link displays the local country data and the server response is immediate:
However, getting the same data from using the below code, takes some time. Why the delay?
TIA
This link displays the local country data and the server response is immediate:
However, getting the same data from using the below code, takes some time. Why the delay?
TIA
#!/usr/bin/python
import requests as req
from xml.etree import ElementTree as ET
import os, time
def get_tz():
url = 'http://geoip.ubuntu.com/lookup'
#read file
r = req.get(url)
if(r.status_code == req.codes.ok):
root = ET.fromstring(r.content)
# parse an xml file by name
TZ = "'" + root[12].text + "'"
t = r.elapsed # returns datetime.timedelta(0, 1, 666890)
#print('elapsed time: {}'.format(t))
print(TZ)
#update time
os.environ['TZ'] = TZ
time.tzset()
get_tz()
