Check for presence of country_code field to avoid key error exception

This commit is contained in:
Gregory Soutade 2016-02-07 10:17:32 +01:00
parent 19e9b9d4fb
commit 9bb188b6fc

View File

@ -70,11 +70,11 @@ class IWLADisplayTopGeo(IPlugin):
cc = None
host_name = host.split(' ')[0] # hostname or ip
if host_name in self.valid_visitors.keys():
cc = self.valid_visitors[host_name]['country_code']
cc = self.valid_visitors[host_name].get('country_code', None)
else:
for visitor in self.valid_visitors.values():
if visitor['remote_addr'] == host_name:
cc = visitor['country_code']
cc = visitor.get('country_code', None)
break
if not cc or cc == 'ip': return None
icon = '<img src="/%s/flags/%s.png"/>' % (self.icon_path, cc)