1. Colin Copeland
  2. django-eventbrite

Source

django-eventbrite / eventbrite / utils.py

from eventbrite.models import Event, Ticket, Attendee, Contact, Venue
from eventbrite import API

api = API()

def update():
    events = api.call('user_list_events',)['events']
    for event in events:
        event = event['event']
        if 'venue' in event:
            del event['venue']['Lat-Long']
            v = Venue(
                **(event['venue'])
            )
            v.save()
        e = Event(
            **dict(
                (k, v) for k, v in event.iteritems() \
                if k in set(['id', 'modified', 'privacy', 'title', 
                'start_date', 'end_date', 'status', 'timezone', 'url', 'tags'])
            ) 
        )
        if 'venue' in event:
            e.venue = v
        e.save()
        attendee_flag = False
        if 'tickets' in event:
            for ticket in event['tickets']:
                ticket = ticket['ticket']
                if ticket['quantity_sold'] > 0:
                    attendee_flag = True
                t = Ticket(event=e, **ticket)
                t.save()
        if attendee_flag:
            attendees = api.call(
                'event_list_attendees', id=event['id']
            )['attendees']
            for attendee in attendees:
                attendee = attendee['attendee']
                attendee_ticket = Ticket.objects.get(id=attendee['ticket_id'])
                c = Contact(
                    email = attendee['email'],
                    first_name = attendee['first_name'],
                    last_name = attendee['last_name'],
                )
                c.save()
                if not attendee['event_date']:
                    del attendee['event_date']
                a = Attendee(ticket_id=attendee_ticket, contact=c,
                    **dict(
                        (k, v) for k, v in attendee.iteritems() \
                        if k in set([
                            'amount_paid', 'barcode', 'created', 'currency',
                            'discount', 'event_date', 'id', 'modified',
                            'order_id', 'order_type', 'quantity', 'affiliate',
                            'contact'
                        ])
                    )
                )
                a.save()