Modify terminal reqject templatte

This commit is contained in:
ibuler
2017-01-03 00:11:44 +08:00
parent 0907f5021e
commit b670259ab6
5 changed files with 16 additions and 7 deletions

View File

@@ -35,14 +35,15 @@ def get_ip_city(ip, timeout=10):
url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=%s&format=json' % ip
try:
r = requests.get(url, timeout=timeout)
print(r)
except requests.Timeout:
r = None
city = 'Unknown'
if r and r.status_code == 200:
try:
data = r.json()
if data['code'] == 0:
city = data['data']['country'] + data['data']['city']
if not isinstance(data, int) and data['ret'] == 1:
city = data['country'] + ' ' + data['city']
except ValueError:
pass
return city