Plugin tor_: fix "tor_countries" in case of missing cache location
Closes: #1176
This commit is contained in:
parent
0b7a005eb2
commit
ed61eab13a
|
@ -309,15 +309,16 @@ class TorCountries(TorPlugin):
|
||||||
|
|
||||||
def fetch(self):
|
def fetch(self):
|
||||||
"""Generate metrics"""
|
"""Generate metrics"""
|
||||||
|
# Fallback if cache_dir_name is not set, unreadable or any other error
|
||||||
|
countries_num = self.top_countries()
|
||||||
# If possible, read cached data instead of doing the processing twice
|
# If possible, read cached data instead of doing the processing twice
|
||||||
try:
|
if self.cache_dir_name:
|
||||||
with open(self.cache_dir_name) as f:
|
try:
|
||||||
countries_num = json.load(f)
|
with open(self.cache_dir_name) as f:
|
||||||
except (IOError, ValueError):
|
countries_num = json.load(f)
|
||||||
# Fallback if cache_dir_name is not set, unreadable or any other
|
except (IOError, ValueError):
|
||||||
# error
|
# use the fallback value above
|
||||||
countries_num = self.top_countries()
|
pass
|
||||||
|
|
||||||
for c, v in countries_num:
|
for c, v in countries_num:
|
||||||
print("%s.value %d" % (c, v))
|
print("%s.value %d" % (c, v))
|
||||||
|
|
Loading…
Reference in New Issue