def rainbow_prediction_alert(slug): rainbow_cities = json.load(open(os.path.join(GFS_FOLDER, slug, '%s.rainbow_cities.json' % slug))) city_names = [city['name_en'] for city in rainbow_cities] synch_users() users = db.users.find() people = False for user in users: if 'custom_fields' in user and 'name_en' in user['custom_fields']: if user['custom_fields']['name_en'] in city_names: people = True if not 'badge' in user['custom_fields']: user['custom_fields']['badge'] = 0 if user['custom_fields']['language'] == 'ru': message = u"Сегодня днем у вас есть большой шанс увидеть радугу!" else: message = "You have a large chance of rainbows!" logger.debug("%s in rainbow area for this forecast" % user['user_name']) send_alert({ "channel": "raduga_predictions", "to_ids": [user['id']], "payload": { "alert": message, "type": "rainbow_prediction", "vibrate": True, "sound": "default", } }) db.users.update({"id" : user['id']}, {'$inc': {'custom_fields.badge': 1}}) if not people: logger.debug("no people in rainbow areas for this forecast")
# -*- coding: utf-8 -*- import pymongo import sys try: from settings import TEST_USER except ImportError: sys.exit("Define a TEST_USER in local_settings.py") from users import synch_users synch_users() client = pymongo.MongoClient() db = client.raduga from alerts import send_alert user = db.users.find_one({"id" : TEST_USER}) photo = db.photos.find_one({}) if not 'badge' in user['custom_fields']: user['custom_fields']['badge'] = 0 if user['custom_fields']['language'] == 'ru': message = "%s обнаружил радугу возле %s" % (photo['user']['username'], photo['custom_fields']['name_ru']) else: message = "%s spotted a rainbow near %s" % (photo['user']['username'], photo['custom_fields']['name_en']) send_alert({ "channel": "raduga_predictions",