-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBackendDetailed.py
44 lines (41 loc) · 1.96 KB
/
BackendDetailed.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Backend
import datetime, pytz
import HumanTime
import osm.diff as osmdiff
import osm.changeset as oc
class Backend(Backend.Backend):
def __init__(self, config, subcfg):
super(Backend, self).__init__(config, subcfg)
self.print_meta = subcfg.get('print_meta', False)
def print_state(self, db, update_reason):
if update_reason!='new_generation.osmtracker':
return
strfmt = '%Y:%m:%d %H:%M:%S'
#time1 = state.first_timestamp.strftime(strfmt)
#time2 = state.timestamp.strftime(strfmt)
#print('Tracked period: {} - {} UTC. {} changesets.'.format(time1, time2, len(state.area_chgsets)))
self.print_chgsets(db, self.print_meta)
def print_chgsets(self, db, print_meta=False):
for c in db.chgsets_find(state=[db.STATE_CLOSED, db.STATE_OPEN, db.STATE_ANALYSING2,
db.STATE_REANALYSING, db.STATE_DONE]):
cid = c['cid']
meta = db.chgset_get_meta(cid)
info = db.chgset_get_info(cid)
#print 'cset=', pprint.pprint(data)
if 'comment' in meta['tag'].keys():
comment = meta['tag']['comment']
else:
comment = '-no comment-'
if 'source' in meta['tag'].keys():
source = "source='"+meta['tag']['source']+"'"
else:
source = ''
timestamp = oc.Changeset.get_timestamp(meta)[1]
htimestamp = HumanTime.date2human(timestamp)
print u" {} \'{}\' {} ('{}') '{}' state={}".format(cid, meta['user'], htimestamp, timestamp, comment, info['state']).encode('ascii','backslashreplace')
if print_meta:
for k,v in meta.items():
print u' {0}:{1}'.format(k,v).encode('ascii','backslashreplace'),
for k,v in meta.get('tags',{}).items():
print u' {0}:{1}'.format(k,v).encode('ascii','backslashreplace'),
print