forked from abhisheksp/global-hack-7
-
Notifications
You must be signed in to change notification settings - Fork 3
/
register.py
31 lines (25 loc) · 1.09 KB
/
register.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
from cryptography.fernet import Fernet
from firebase_admin import db
cipher_key = ''
with open('cipher_key.txt') as f:
cipher_key = bytes(f.readline(), 'utf-8')
cipher_suite = Fernet(cipher_key)
def register_group(group_id):
print('Registering Facebook group: {}'.format(group_id))
existing_groups = db.reference('/group_ids').get() or []
existing_groups = set(existing_groups)
existing_groups.add(group_id)
existing_groups = list(existing_groups)
root = db.reference('/')
root.update({'group_ids': existing_groups})
return 'Facebook group {} successfully registered'.format(group_id)
def register_number(number):
print('Registering Number: {}'.format(number))
encrypted_number = cipher_suite.encrypt(bytes(number, 'utf-8'))
existing_numbers = db.reference('/numbers').get() or []
existing_numbers = set(existing_numbers)
existing_numbers.add(encrypted_number.decode('utf-8'))
existing_numbers = list(existing_numbers)
root = db.reference('/')
root.update({'numbers': existing_numbers})
return '{} successfully registered'.format(number)