-
Notifications
You must be signed in to change notification settings - Fork 16
/
manage.py
91 lines (62 loc) · 1.82 KB
/
manage.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import re
from flask.ext.script import Manager
from forms import create_app, app
forms_app = create_app()
manager = Manager(forms_app)
@manager.command
def run(port=5000):
app.run(port=int(port))
@manager.command
def show_list():
print 'Listing all referer / email pairs and counts...'
values = []
for key in app.REDIS.keys('*counter*'):
count = int(app.REDIS.get(key))
keyhash = key.split('_')[-1]
email, host = app._get_values_for_hash(keyhash)
values.append((count, email, host))
values.sort(key=lambda x: x[0], reverse=True)
total = {}
total['Pairs'] = len(values)
total['Sent'] = sum([x[0] for x in values])
total['Unique'] = len(set([x[1] for x in values]))
def format_dict(d):
return ', '.join([k+': '+str(d[k]) for k in d])
print '\n---\n'
print 'Totals - ', format_dict(total)
print '\n---\n'
for v in values: print v
print '\n---\n'
print 'Totals - ', format_dict(total)
print 'Done'
def _matchhosts(name):
r = app.REDIS
keys = r.keys('forms_hash_host_*')
hosts = filter(lambda x: re.match(r".*%s"%name, r.get(x)), keys)
return map(lambda x: x.split("_")[-1], hosts)
def _print(hostid):
r = app.REDIS
keys = r.keys("*%s*" % hostid)
results = dict((k,r.get(k)) for k in keys)
print results
def _del(hostid):
r = app.REDIS
keys = r.keys("*%s*" % hostid)
for k in keys:
r.delete(k)
@manager.command
def print_hosts(name):
count = 0
for host in _matchhosts(name):
_print(host)
count +=1
print "found %d items" % count
@manager.command
def delete_hosts(name):
count = 0
for host in _matchhosts(name):
_del(host)
count +=1
print "deleted %d items" % count
if __name__ == "__main__":
manager.run()