eventman/tools/count.py

46 lines
1.1 KiB
Python
Raw Normal View History

2017-04-16 18:02:53 +02:00
#!/usr/bin/env python3
2017-04-23 09:19:56 +02:00
# -*- coding: utf-8 -*-
2017-04-16 18:02:53 +02:00
import sys
import monco
2017-04-23 09:19:56 +02:00
COUNT = ('attended', 'afternoon_attended')
GROUP = ('checked_in_by',)
2017-04-16 18:02:53 +02:00
def info(event):
tickets = event['tickets']
total = 0
2017-04-23 09:19:56 +02:00
data = {}
2017-04-16 18:02:53 +02:00
for ticket in tickets:
if ticket.get('cancelled'):
continue
2017-04-23 09:19:56 +02:00
for key in COUNT:
value = ticket.get(key)
if value:
data.setdefault(key, 0)
data[key] += 1
for key in GROUP:
value = ticket.get(key)
if value:
dbkey = '%s.%s' % (key, value)
data.setdefault(dbkey, 0)
data[dbkey] += 1
2017-04-16 18:02:53 +02:00
total += 1
print('Total registered: %d' % total)
2017-05-07 15:00:31 +02:00
for key, value in sorted(data.items()):
2017-04-23 09:19:56 +02:00
print('%s: %s' % (key, value))
2017-04-16 18:02:53 +02:00
print('')
def run():
try:
db = monco.Monco(dbName='eventman')
events = db.query('events', {'title': sys.argv[1]})
info(events[0])
except:
print('count.py "title of event"')
sys.exit(1)
if __name__ == '__main__':
run()