From ffa8829c3ed925563d8a9ffca2d90f125c8bb8d9 Mon Sep 17 00:00:00 2001 From: Ilya Zverev Date: Sun, 5 Feb 2017 16:22:58 +0100 Subject: [PATCH] Fix geocoding and add a pause option --- mmwatch/server/geocode.py | 12 ++++++++++-- mmwatch/www/mmwatch.py | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/mmwatch/server/geocode.py b/mmwatch/server/geocode.py index 6695248..0aabb8b 100644 --- a/mmwatch/server/geocode.py +++ b/mmwatch/server/geocode.py @@ -28,7 +28,9 @@ def add_countries(): return database.connect() with database.atomic(): - q = Change.select().where((Change.country >> None) & (Change.action != 'a') & (~Change.changes.startswith('[[null, null]'))).limit(config.GEOCODE_BATCH) + q = Change.select().where((Change.country >> None) & (Change.action != 'a') & (~Change.changes.startswith('[[null, null]'))).limit( + config.GEOCODE_BATCH + 200) + count = config.GEOCODE_BATCH for ch in q: coord = ch.changed_coord() if coord is not None: @@ -37,7 +39,13 @@ def add_countries(): ch.country = country[:150] ch.save() else: - print('Empty coordinates: {0} {1} {2}'.format(ch.id, ch.action, ch.changes.encode('utf-8'))) + # print('Empty coordinates: {0} {1} {2}'.format(ch.id, ch.action, ch.changes.encode('utf-8'))) + pass + + # We request more because of these empty coordinates errors + count -= 1 + if count <= 0: + break if __name__ == '__main__': diff --git a/mmwatch/www/mmwatch.py b/mmwatch/www/mmwatch.py index e16b900..6586b59 100644 --- a/mmwatch/www/mmwatch.py +++ b/mmwatch/www/mmwatch.py @@ -75,9 +75,16 @@ def purl(params, **kwargs): return url_for('the_one_and_only_page', **p2) +def is_disabled(): + return os.path.exists(os.path.join(config.BASE_DIR, 'pause')) + + @app.route('/') @cached() def the_one_and_only_page(): + if is_disabled(): + return "The service is disabled for updates.
Please come back in a couple minutes." + # Parse query params params = {} page = request.args.get('page', '1')