duplicates.py 968 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. import monco
  5. def info(event, key, short=False):
  6. tickets = event['tickets']
  7. data = {}
  8. for ticket in tickets:
  9. if ticket.get('cancelled'):
  10. continue
  11. value = ticket.get(key)
  12. email = ticket.get('email')
  13. if not (value and email):
  14. continue
  15. data.setdefault(value, []).append(email)
  16. for key, value in data.items():
  17. if len(value) < 2:
  18. continue
  19. output = '%s (%d persons)' % (key, len(value))
  20. if not short:
  21. output += ': %s' % ', '.join(value)
  22. print(output)
  23. print('')
  24. def run():
  25. try:
  26. db = monco.Monco(dbName='eventman')
  27. events = db.query('events', {'title': sys.argv[1]})
  28. info(events[0], sys.argv[2], short='-s' in sys.argv[1:])
  29. except:
  30. print('duplicates.py "title of event" key')
  31. sys.exit(1)
  32. if __name__ == '__main__':
  33. run()