forked from abhisheksp/global-hack-7
-
Notifications
You must be signed in to change notification settings - Fork 3
/
broadcast.py
64 lines (52 loc) · 1.88 KB
/
broadcast.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import requests
from firebase_admin import db
from cipher import cipher
from whatsapp import send_messages
from twitter import tweet
def find_numbers():
numbers_encrypted = db.reference('/numbers').get()
cipher_suite = cipher()
number_decrypter = lambda n: cipher_suite.decrypt(bytes(n, 'utf-8')).decode('utf-8')
numbers = list(map(number_decrypter, numbers_encrypted))
return numbers
def find_group_ids():
group_ids = db.reference('/group_ids').get()
return group_ids
def facebook_group_post(message):
group_ids = find_group_ids()
print('Group IDS: ', group_ids)
url = 'https://cce34c71.ngrok.io/grouppost'
payload = {'message': message, 'groupids': group_ids}
requests.post(url, json=payload)
def save_event(message, from_number, event_metadata):
location = event_metadata['location']
nationality = event_metadata['nationality']
group_name = event_metadata['groupName']
data = {
"event": message,
"patronPhone": from_number,
"location": location,
"nationality": nationality,
"messengerType": 'Whatsapp',
"groupName": group_name
}
root = db.reference()
root.child('events').push(data)
def identify_event_metadata(from_number):
found_patrons = list(db.reference('patron').order_by_child("phone").equal_to(from_number).get().values())
if len(found_patrons) == 0:
return None, False
patron = found_patrons[0]
return patron, True
def broadcast(from_number, message):
print('message: ', message)
numbers = find_numbers()
print('found numbers:', numbers)
send_messages(numbers, message)
tweet(message)
facebook_group_post(message)
metadata, found = identify_event_metadata(from_number)
if not found:
return 'Broadcast successful but unknown Patron'
save_event(message, from_number, metadata)
return 'Broadcast successful!'