-
Notifications
You must be signed in to change notification settings - Fork 50
/
fftf_leaderboard.py
executable file
·74 lines (55 loc) · 2.13 KB
/
fftf_leaderboard.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
65
66
67
68
69
70
71
72
73
74
import hashlib
import json
import grequests
class FFTFLeaderboard():
debug_mode = False
pool_size = 1
def __init__(self, debug_mode, pool_size):
self.debug_mode = debug_mode
def log_call(self, params, campaign, request):
if params['fftfCampaign'] == None or params['fftfReferer'] == None:
return
i = int(request.values.get('call_index'))
kwds = {
'campaign_id': campaign['id'],
'member_id': params['repIds'][i],
'zipcode': params['zipcode'],
'phone_number': hashlib.sha256(params['userPhone']).hexdigest(),
'call_id': request.values.get('CallSid', None),
'status': request.values.get('DialCallStatus', 'unknown'),
'duration': request.values.get('DialCallDuration', 0)
}
data = json.dumps(kwds)
self.post_to_leaderboard(
params['fftfCampaign'],
'call',
data,
params['fftfReferer'],
params['fftfSession'])
def log_complete(self, params, campaign, request):
if params['fftfCampaign'] == None or params['fftfReferer'] == None:
return
self.post_to_leaderboard(
params['fftfCampaign'],
'calls_complete',
'yay',
params['fftfReferer'],
params['fftfSession'])
def post_to_leaderboard(self, fftf_campaign, stat, data, host, session):
debug_mode = self.debug_mode
def finished(res, **kwargs):
if debug_mode:
print "FFTF Leaderboard call complete: %s" % res
data = {
'campaign': fftf_campaign,
'stat': stat,
'data': data,
'host': host,
'session': session
}
if self.debug_mode:
print "FFTF Leaderboard sending: %s" % data
url = 'https://leaderboard.fightforthefuture.org/log'
req = grequests.post(url, data=data, hooks=dict(response=finished))
job = grequests.send(req, grequests.Pool(self.pool_size))
return