eventman/tools/duplicates.py

40 lines
968 B
Python
Raw Permalink Normal View History

2017-04-23 16:56:51 +02:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import monco
2017-10-15 11:18:24 +02:00
def info(event, key, short=False):
2017-04-23 16:56:51 +02:00
tickets = event['tickets']
data = {}
for ticket in tickets:
if ticket.get('cancelled'):
continue
value = ticket.get(key)
email = ticket.get('email')
if not (value and email):
continue
data.setdefault(value, []).append(email)
for key, value in data.items():
if len(value) < 2:
continue
2017-10-15 11:18:24 +02:00
output = '%s (%d persons)' % (key, len(value))
if not short:
output += ': %s' % ', '.join(value)
print(output)
2017-04-23 16:56:51 +02:00
print('')
def run():
try:
db = monco.Monco(dbName='eventman')
events = db.query('events', {'title': sys.argv[1]})
2017-10-15 11:18:24 +02:00
info(events[0], sys.argv[2], short='-s' in sys.argv[1:])
2017-04-23 16:56:51 +02:00
except:
2017-09-16 20:50:30 +02:00
print('duplicates.py "title of event" key')
2017-04-23 16:56:51 +02:00
sys.exit(1)
if __name__ == '__main__':
run()