Added json and dictionary checking to eliminate terminations when the DMR-MARC database can't download.
This commit is contained in:
parent
7f5a223637
commit
192d36a94c
@ -22,6 +22,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
from os.path import isfile, getmtime
|
from os.path import isfile, getmtime
|
||||||
|
from os import remove
|
||||||
from time import time
|
from time import time
|
||||||
from urllib import URLopener
|
from urllib import URLopener
|
||||||
from csv import reader as csv_reader
|
from csv import reader as csv_reader
|
||||||
@ -114,7 +115,13 @@ def mk_id_dict(_path, _file):
|
|||||||
if _file.endswith(('.json','.JSON')):
|
if _file.endswith(('.json','.JSON')):
|
||||||
try:
|
try:
|
||||||
with open(_path+_file, 'rU') as _handle:
|
with open(_path+_file, 'rU') as _handle:
|
||||||
|
|
||||||
|
try:
|
||||||
ids = json.loads(_handle.read().decode('utf-8', 'ignore'))
|
ids = json.loads(_handle.read().decode('utf-8', 'ignore'))
|
||||||
|
except (ValueError):
|
||||||
|
remove(_path+_file)
|
||||||
|
return dict
|
||||||
|
|
||||||
if 'repeaters' in ids:
|
if 'repeaters' in ids:
|
||||||
ids = ids['repeaters']
|
ids = ids['repeaters']
|
||||||
id_type = 'locator'
|
id_type = 'locator'
|
||||||
@ -130,8 +137,12 @@ def mk_id_dict(_path, _file):
|
|||||||
else:
|
else:
|
||||||
return dict
|
return dict
|
||||||
|
|
||||||
|
try:
|
||||||
for row in range(len(ids)):
|
for row in range(len(ids)):
|
||||||
dict[int(ids[row][id_type])] = ids[row][id_value].encode('ascii','ignore')
|
dict[int(ids[row][id_type])] = ids[row][id_value].encode('ascii','ignore')
|
||||||
|
except (ValueError, KeyError):
|
||||||
|
remove(_path+_file)
|
||||||
|
return dict;
|
||||||
|
|
||||||
_handle.close
|
_handle.close
|
||||||
return dict
|
return dict
|
||||||
|
Loading…
x
Reference in New Issue
Block a user