Created
February 18, 2018 21:24
-
-
Save hiranya911/400f2d90302b80ca6d7eb7fbbac1347a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import firebase_admin | |
from firebase_admin import db | |
from firebase_admin import messaging | |
# Load Firebase configuration from environment. | |
firebase_admin.initialize_app() | |
users_ref = db.reference('users') | |
# Query for the users whose settings/alerts field is set to `true`. | |
users = users_ref.order_by_child('settings/alerts').equal_to(True).get() | |
tokens = [u['token'] for u in users.values() if 'token' in u] | |
# Split into sublists of length 1000 or less. | |
max_tokens = 1000 | |
token_sublists = [tokens[i:i+max_tokens] for i in xrange(0, len(tokens), max_tokens)] | |
for sublist in token_sublists: | |
resp = messaging.subscribe_to_topic(sublist, 'releases') | |
print('Successfully subscribed {0} tokens'.format(resp.success_count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment