Esempio n. 1
0
class Category:
    def __init__(self):
        self.eventbrite = Eventbrite(settings.EVENTBRITE_API_KEY)

    def all(self):
        """
        This returns all categories from the eventbrite API

        :return:
        :return: List of categories
        """
        eventbrite_categories = self.eventbrite.get_categories()
        if eventbrite_categories.status_code == 200:
            return eventbrite_categories["categories"]
        else:
            return None

    def get(self, category_id):
        """
        Given the id of a category, returns that eventbrite category object

        :param category_id:
        :return:
        """
        data = self.eventbrite.get_category(category_id)
        if data.status_code == 200:
            return data
        else:
            return None

    def get_multiple(self, category_ids):
        """
        Returns category objects for category ids given

        :param category_ids:
        :return:
        """
        categories = []
        for category_id in category_ids:
            categories.append(self.get(category_id))

        return categories
Esempio n. 2
0
def get_recommendation(desired_time):
    # GET EVENT RECOMMENDATION FROM EVENTBRITE

    # GET EVENTBRITE API KEY
    eventbrite_api_key = get_key('EVENTBRITE_TOKEN')
    eventbrite = Eventbrite(eventbrite_api_key)

    # GET ADDRESS FROM HOTEL NAME (GOOGLEMAPS)
    google_api_key = get_key('GOOGLE')
    gmaps = googlemaps.Client(key=google_api_key)
    places_result = gmaps.places(query=session.attributes['hotel'])
    hotel_address = [e['formatted_address'] for e in places_result['results']]

    # GET CATEGORY ID FROM CATEGORY NAME
    address = hotel_address
    category_input = 'Music'
    subcategory_input = session.attributes['music_cat_id']
    location_radius = '10mi'
    event_timing = desired_time
    categoryquery = eventbrite.get_categories()

    category_name = [c['name'] for c in categoryquery['categories']]
    category_ids = [c['id'] for c in categoryquery['categories']]
    categories = zip(category_name, category_ids)

    category_id = None
    for x in categories:
        if x[0] == category_input:
            category_id = x[1]

    # GET SUBCATEGORY ID FROM CATEGORY ID
    #subcategoryquery = eventbrite.get_subcategories()

    #subcategory_name = [c['name'] for c in subcategoryquery['subcategories']]
    #subcategory_ids = [c['id'] for c in subcategoryquery['subcategories']]
    #subcategories = zip(subcategory_name, subcategory_ids)

    subcategory_id = subcategory_input
    #for x in subcategories:
        #if x[0] == subcategory_input:
            #subcategory_id = x[1]

    # GET LIST OF EVENTS
    eventquery = eventbrite.event_search(**{'location.address': address,
                                            'categories': category_id,
                                            'subcategories': subcategory_id,
                                            'location.within': location_radius,
                                            'start_date.keyword': event_timing})

    eventnames = [e['name']['text'] for e in eventquery['events']]
    if not eventnames:
        return False
    event1 = eventnames[0]

    eventdescr = [e['description']['text'] for e in eventquery['events']]
    descr1 = eventdescr[0]

    # COLLECT ADDITIONAL INFO FOR FILES
    #eventdescr2 = []
    #for i in eventdescr:
        #if i is None:
            #eventdescr2.append("")
        #eventdescr2.append(((i.replace("\n", " ")).replace("\r", " "))[0:30])

    eventlogo = []
    for e in eventquery['events']:
        eventlogo.append(e['logo']['original']['url'] if e['logo'] else '')
    logo1 = eventlogo[0]

    eventkeys = []
    for i in eventnames:
        eventkeys.append(('event-' + i).replace(" ", "-"))

    eventlist = zip(eventkeys, eventnames, eventnames, eventlogo)

    eventstart = [l['local']
                  for l in (e['start'] for e in eventquery['events'])]
    start1 = eventstart[0]

    eventend = [l['local'] for l in (e['end'] for e in eventquery['events'])]
    end1 = eventend[0]

    eventvenue = [v['venue_id'] for v in eventquery['events']]
    venue1 = eventvenue[0]
    venuequery = eventbrite.get('/venues/{0}'.format(venue1))
    venue_list = venuequery['address']['localized_multi_line_address_display']
    venue_string = " ".join(str(x) for x in venue_list)

    eventurl = [u['url'] for u in eventquery['events']]
    url1 = eventurl[0]

    # CREATE EVENT TERMS

    eventterms = []
    for i in eventnames:
        eventterms.append((((category_input + '__' + session.attributes['music_cat']).replace(" ", "_")).replace("/", "and")).lower())

    termfile = zip(eventkeys, eventterms)
    with get_connection() as conn:
        with conn.cursor() as cursor:
            cursor.executemany("""
                INSERT INTO products (id, name, description, image_link)
                VALUES (%s, %s, %s, %s)
                """, eventlist)
            cursor.executemany("""
                INSERT INTO terms (event_key, event_term) VALUES (%s, %s)
                """, termfile)
    conn.close()

    # TEXT EVENT DETAILS

    account_sid = get_key('TWILIO_SID')
    auth_token = get_key('TWILIO_TOKEN')

    client = twilio.rest.Client(account_sid, auth_token)

    phone_number = session.attributes['phone_number']
    client.messages.create(
        to=phone_number,
        from_=get_key('TWILIO_PHONE'),
        body="Your IHG Concierge has sent you an event you may enjoy: " +
             '\n' + event1 + '\n' + descr1[:800] + '\n' + "Start Time: " +
             start1 + '\n' + "End Time: " + end1 + '\n' + "Venue: " +
             venue_string + '\n' + url1,
        media_url=logo1 if phone_number.startswith('+1') else None)

    return eventnames[0]
Esempio n. 3
0
def categories():
    eventbrite = Eventbrite(token)
    category_list = eventbrite.get_categories()
    names = [category['name'] for category in category_list['categories']]
    return "test"