nr data get nr False if nr try nr int nr replace log debug Nr is str n

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
nr = data.get('nr', False)
if nr:
try:
nr = int(nr.replace(' ', ''))
log.debug('Nr is :' + str(nr))
except:
log.error('Nr is not int:' + nr)
else:
log.error('Nr not in raw_data.')
search_query = {"nr": data['nr']}
old = db.find_one(search_query)
data['nr'] = nr
if not(old is None):
old.update(data)
self.updates += 1
print(self.updates)
# import ipdb; ipdb.set_trace()
db.update(
search_query,
old
)
log.info('Updated')
else:
log.debug('saved to mongo')
db.insert(data)