count.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. import monco
  5. COUNT = ('attended', 'afternoon_attended')
  6. GROUP = ('checked_in_by',)
  7. def info(event):
  8. tickets = event['tickets']
  9. total = 0
  10. data = {}
  11. for ticket in tickets:
  12. if ticket.get('cancelled'):
  13. continue
  14. for key in COUNT:
  15. value = ticket.get(key)
  16. if value:
  17. data.setdefault(key, 0)
  18. data[key] += 1
  19. for key in GROUP:
  20. value = ticket.get(key)
  21. if value:
  22. dbkey = '%s.%s' % (key, value)
  23. data.setdefault(dbkey, 0)
  24. data[dbkey] += 1
  25. total += 1
  26. print('Total registered: %d' % total)
  27. for key, value in sorted(data.items()):
  28. print('%s: %s' % (key, value))
  29. print('')
  30. def run():
  31. try:
  32. db = monco.Monco(dbName='eventman')
  33. events = db.query('events', {'title': sys.argv[1]})
  34. info(events[0])
  35. except:
  36. print('count.py "title of event"')
  37. sys.exit(1)
  38. if __name__ == '__main__':
  39. run()