Fixes for mapsme5 challenge and find-coords
This commit is contained in:
parent
131205eb06
commit
06f7945c98
2 changed files with 13 additions and 3 deletions
|
@ -13,7 +13,7 @@ def find_coord(obj_type, obj_id):
|
|||
try:
|
||||
response = urllib2.urlopen('{0}/{1}/{2}'.format(API_ENDPOINT, typs[obj_type], obj_id))
|
||||
except urllib2.HTTPError as e:
|
||||
if e.code == 404:
|
||||
if e.code == 410:
|
||||
return None
|
||||
raise e
|
||||
obj = etree.parse(response).getroot()[0]
|
||||
|
@ -26,11 +26,11 @@ def find_coord(obj_type, obj_id):
|
|||
|
||||
if __name__ == '__main__':
|
||||
database.connect()
|
||||
q = Change.select().where(Change.changes.startswith('[null,') & (Change.action == 'm')).limit(10)
|
||||
q = Change.select().where(Change.changes.startswith('[null,') & (Change.action == 'm')).limit(100)
|
||||
for row in q:
|
||||
changes = json.loads(row.changes)
|
||||
if not changes[0]:
|
||||
coord = find_coord(row.obj_type, row.obj_id)
|
||||
changes[0] = (coord, coord)
|
||||
row.changes = changes
|
||||
row.changes = json.dumps(changes, ensure_ascii=False)
|
||||
row.save()
|
||||
|
|
|
@ -101,6 +101,14 @@ def the_one_and_only_page():
|
|||
changeset = request.args.get('changeset', None)
|
||||
if changeset is not None and changeset.isdigit():
|
||||
params['changeset'] = changeset
|
||||
mapsme5 = request.args.get('mapsme5', None) == '1'
|
||||
if mapsme5:
|
||||
params['mapsme5'] = 1
|
||||
mmlist = []
|
||||
with open(os.path.join(config.DATABASE_PATH, 'mapsme5.lst'), 'r') as f:
|
||||
for line in f:
|
||||
if line.strip():
|
||||
mmlist.append(line.strip())
|
||||
|
||||
# Construct queries
|
||||
q = {}
|
||||
|
@ -134,6 +142,8 @@ def the_one_and_only_page():
|
|||
pdate = datetime.strptime(date + ' UTC', '%d.%m.%Y %Z')
|
||||
pdate1 = pdate + timedelta(days=1)
|
||||
q[k] = q[k].where((Change.timestamp >= pdate) & (Change.timestamp < pdate1))
|
||||
if mapsme5:
|
||||
q[k] = q[k].where(Change.user << mmlist)
|
||||
|
||||
# Calculate statistics
|
||||
stats = {}
|
||||
|
|
Loading…
Add table
Reference in a new issue