Révision ed61eab1
Plugin tor_: fix "tor_countries" in case of missing cache location
Closes: #1176
| plugins/tor/tor_ | ||
|---|---|---|
| 309 | 309 |
|
| 310 | 310 |
def fetch(self): |
| 311 | 311 |
"""Generate metrics""" |
| 312 |
|
|
| 312 |
# Fallback if cache_dir_name is not set, unreadable or any other error |
|
| 313 |
countries_num = self.top_countries() |
|
| 313 | 314 |
# If possible, read cached data instead of doing the processing twice |
| 314 |
try:
|
|
| 315 |
with open(self.cache_dir_name) as f:
|
|
| 316 |
countries_num = json.load(f)
|
|
| 317 |
except (IOError, ValueError):
|
|
| 318 |
# Fallback if cache_dir_name is not set, unreadable or any other
|
|
| 319 |
# error
|
|
| 320 |
countries_num = self.top_countries()
|
|
| 315 |
if self.cache_dir_name:
|
|
| 316 |
try:
|
|
| 317 |
with open(self.cache_dir_name) as f:
|
|
| 318 |
countries_num = json.load(f)
|
|
| 319 |
except (IOError, ValueError):
|
|
| 320 |
# use the fallback value above
|
|
| 321 |
pass
|
|
| 321 | 322 |
|
| 322 | 323 |
for c, v in countries_num: |
| 323 | 324 |
print("%s.value %d" % (c, v))
|
Formats disponibles : Unified diff