Skip to content

Commit

Permalink
Plugin tor_: fix "tor_countries" in case of missing cache location
Browse files Browse the repository at this point in the history
Closes: #1176
  • Loading branch information
sumpfralle committed Feb 17, 2021
1 parent 0b7a005 commit ed61eab
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions plugins/tor/tor_
Expand Up @@ -309,15 +309,16 @@ class TorCountries(TorPlugin):

def fetch(self):
"""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
try:
with open(self.cache_dir_name) as f:
countries_num = json.load(f)
except (IOError, ValueError):
# Fallback if cache_dir_name is not set, unreadable or any other
# error
countries_num = self.top_countries()
if self.cache_dir_name:
try:
with open(self.cache_dir_name) as f:
countries_num = json.load(f)
except (IOError, ValueError):
# use the fallback value above
pass

for c, v in countries_num:
print("%s.value %d" % (c, v))
Expand Down

0 comments on commit ed61eab

Please sign in to comment.