Exemplo n.º 1
0
def main():

    session = get_session()

    events = session.query(Event).\
        filter(Event.start_time > '2016-02-27 17:00:00').\
        filter(Event.start_time < '2016-02-27 23:00:00').\
        filter(Event.eventful_popularity > 40).\
        order_by(-Event.eventful_popularity)

    while True:

        print("Fetching Uber prices at " + str(datetime.now()))

        client = UberRidesClient(Session(server_token=UBER_SERVER_TOKEN))

        for event in events:
            response = client.get_price_estimates(event.venue.lat,
                                                  event.venue.long, 37.700,
                                                  -122.4)

            for price in response.json['prices']:
                if price['display_name'] != 'uberX':
                    continue
                else:
                    price = UberPrice(event=event,
                                      surge=price['surge_multiplier'],
                                      time=datetime.now())
                    session.add(price)
                    session.commit()
                    break

        sleep(180)
Exemplo n.º 2
0
def main():
    session = get_session()

    events = session.query(Event).filter(Event.end_time == None).limit(50)

    for event in events:
        if event.categories:
            print(event.categories)
Exemplo n.º 3
0
def main():

    session = get_session()

    events = session.query(Event).\
        filter(Event.start_time > '2016-02-27 17:00:00').\
        filter(Event.start_time < '2016-02-27 23:00:00').\
        filter(Event.eventful_popularity > 40).\
        order_by(-Event.eventful_popularity)

    while True:

        print("Fetching Lyft prices at " + str(datetime.now()))

        lyft_response = requests.post(
            url="https://api.lyft.com/oauth/token",
            headers={
                "Content-Type": "application/json",
            },
            auth=(LYFT_CLIENT_ID, LYFT_CLIENT_SECRET),
            data=json.dumps({
                "scope": "public",
                "grant_type": "client_credentials"
            })
        )

        token = lyft_response.json()['access_token']

        for event in events:
            response = requests.get(
                url="https://api.lyft.com/v1/cost",
                headers={
                    "Authorization": "Bearer {}".format(token)
                },
                params={
                    'start_lat': event.venue.lat,
                    'start_lng': event.venue.long
                }
            )

            for price in response.json()['cost_estimates']:
                if price['ride_type'] != 'lyft':
                    continue
                else:
                    price = LyftPrice(
                        event=event,
                        primetime=(100+int(price['primetime_percentage'][:-1]))/100,
                        time=datetime.now()
                    )
                    session.add(price)
                    session.commit()
                    break

        sleep(180)
Exemplo n.º 4
0
def main():

    session = get_session()

    events = session.query(Event).\
        filter(Event.start_time > '2016-02-28 09:00:00').\
        filter(Event.start_time < '2016-02-28 16:00:00').\
        filter(Event.eventful_popularity > 40).\
        order_by(-Event.eventful_popularity)

    while True:

        print("Fetching Lyft prices at " + str(datetime.now()))

        lyft_response = requests.post(url="https://api.lyft.com/oauth/token",
                                      headers={
                                          "Content-Type": "application/json",
                                      },
                                      auth=(LYFT_CLIENT_ID,
                                            LYFT_CLIENT_SECRET),
                                      data=json.dumps({
                                          "scope":
                                          "public",
                                          "grant_type":
                                          "client_credentials"
                                      }))

        token = lyft_response.json()['access_token']

        for event in events:
            response = requests.get(
                url="https://api.lyft.com/v1/cost",
                headers={"Authorization": "Bearer {}".format(token)},
                params={
                    'start_lat': event.venue.lat,
                    'start_lng': event.venue.long
                })

            for price in response.json()['cost_estimates']:
                if price['ride_type'] != 'lyft':
                    continue
                else:
                    price = LyftPrice(
                        event=event,
                        primetime=(100 +
                                   int(price['primetime_percentage'][:-1])) /
                        100,
                        time=datetime.now())
                    session.add(price)
                    session.commit()
                    break

        sleep(180)
Exemplo n.º 5
0
def main():
    session = get_session()

    start_cutoff = arrow.utcnow().\
        replace(hours=-3).\
        to('US/Pacific').\
        format('YYYY-MM-DD HH:mm:ss')

    stop_cutoff = arrow.utcnow().\
        replace(hours=6).\
        to('US/Pacific').\
        format('YYYY-MM-DD HH:mm:ss')

    eventful_events = session.query(Event).\
        filter(Event.eventful_popularity > 40).\
        filter(Event.start_time > start_cutoff).\
        filter(Event.start_time > stop_cutoff).\
        order_by(Event.start_time).\
        limit(150)

    data = {}
    counter = 0
    for event in eventful_events:
        start_time = arrow.get(event.start_time).format('YYYY-MM-DD HH:mm')
        data['valleys/' + str(counter)] = {
            'name': event.name,
            'time': start_time,
            'rating': event.eventful_popularity / 170,
            'lat': str(event.venue.lat),
            'long': str(event.venue.long)
        }
        end_time = arrow.get(event.end_time).format(
            'YYYY-MM-DD HH:mm') if event.end_time else arrow.get(
                event.start_time).replace(hours=3).format('YYYY-MM-DD HH:mm')
        data['peaks/' + str(counter)] = {
            'name': event.name,
            'time': end_time,
            'rating': event.eventful_popularity / 170,
            'lat': str(event.venue.lat),
            'long': str(event.venue.long)
        }
        counter += 1

    ref.update(data)
Exemplo n.º 6
0
def main():
    session = get_session()

    start_cutoff = arrow.utcnow().\
        replace(hours=-3).\
        to('US/Pacific').\
        format('YYYY-MM-DD HH:mm:ss')

    stop_cutoff = arrow.utcnow().\
        replace(hours=6).\
        to('US/Pacific').\
        format('YYYY-MM-DD HH:mm:ss')

    eventful_events = session.query(Event).\
        filter(Event.eventful_popularity > 40).\
        filter(Event.start_time > start_cutoff).\
        filter(Event.start_time > stop_cutoff).\
        order_by(Event.start_time).\
        limit(150)

    data = {}
    counter = 0
    for event in eventful_events:
        start_time = arrow.get(event.start_time).format('YYYY-MM-DD HH:mm')
        data['valleys/'+str(counter)] = {
            'name': event.name,
            'time': start_time,
            'rating': event.eventful_popularity/170,
            'lat': str(event.venue.lat),
            'long': str(event.venue.long)
        }
        end_time = arrow.get(event.end_time).format('YYYY-MM-DD HH:mm') if event.end_time else arrow.get(event.start_time).replace(hours=3).format('YYYY-MM-DD HH:mm')
        data['peaks/'+str(counter)] = {
            'name': event.name,
            'time': end_time,
            'rating': event.eventful_popularity/170,
            'lat': str(event.venue.lat),
            'long': str(event.venue.long)
        }
        counter += 1

    ref.update(data)
Exemplo n.º 7
0
def main():

    session = get_session()

    events = session.query(Event).\
        filter(Event.start_time > '2016-02-28 09:00:00').\
        filter(Event.start_time < '2016-02-28 16:00:00').\
        filter(Event.eventful_popularity > 40).\
        order_by(-Event.eventful_popularity)

    while True:

        print("Fetching Uber prices at " + str(datetime.now()))

        client = UberRidesClient(Session(server_token=UBER_SERVER_TOKEN))

        for event in events:
            response = client.get_price_estimates(
                event.venue.lat,
                event.venue.long,
                37.700,
                -122.4
            )

            for price in response.json['prices']:
                if price['display_name'] != 'uberX':
                    continue
                else:
                    price = UberPrice(
                        event=event,
                        surge=price['surge_multiplier'],
                        time=datetime.now()
                    )
                    session.add(price)
                    session.commit()
                    break

        sleep(180)
Exemplo n.º 8
0
def main():
    session = get_session()

    start_cutoff = arrow.utcnow().\
        replace(hours=-4).\
        to('US/Pacific').\
        format('YYYY-MM-DD HH:mm:ss')

    stop_cutoff = arrow.utcnow().\
        replace(days=3).\
        to('US/Pacific').\
        format('YYYY-MM-DD HH:mm:ss')

    eventful_events = list(session.query(Event).\
        filter(Event.eventful_popularity > 40).\
        filter(Event.start_time > start_cutoff).\
        filter(Event.start_time > stop_cutoff))

    songkick_events = list(session.query(Event).\
        filter(Event.songkick_popularity > 0).\
        filter(Event.start_time > start_cutoff).\
        filter(Event.start_time > stop_cutoff))

    eventbrite_events = list(session.query(Event).\
        filter(Event.eventbrite_id != None).\
        filter(Event.start_time > start_cutoff).\
        filter(Event.start_time > stop_cutoff))

    events = set(eventful_events + songkick_events + eventbrite_events)

    ranked_events = []
    for event in events:
        score = 0.0
        if event.eventful_popularity:
            score += event.eventful_popularity/170 * 3
        else:
            score += 1
        if event.songkick_popularity:
            score += float(min(event.songkick_popularity*10, 1) * 3)
        else:
            score += 1
        if event.venue.capacity:
            score += float(min(5000, event.venue.capacity)/5000 * 3)
        else:
            score += 1

        ranked_events.append((score, event))

    data = {}
    counter = 0
    for score, event in ranked[:500]:
        start_time = arrow.get(event.start_time).format('YYYY-MM-DD HH:mm')
        data['valleys/'+str(counter)] = {
            'id': counter,
            'name': event.name,
            'time': start_time,
            'rating': score/5,
            'lat': str(event.venue.lat),
            'long': str(event.venue.long)
        }
        end_time = arrow.get(event.end_time).format('YYYY-MM-DD HH:mm') if event.end_time else arrow.get(event.start_time).replace(hours=3).format('YYYY-MM-DD HH:mm')
        data['peaks/'+str(counter)] = {
            'id': counter,
            'name': event.name,
            'time': end_time,
            'rating': score/3,
            'lat': str(event.venue.lat),
            'long': str(event.venue.long)
        }
        counter += 1

    ref.update(data)
Exemplo n.º 9
0
def search_events_by_location(address, location_within, popular, sort_by, start_date_range_start, start_date_range_end):
    top_url = "".join([EVENTBRITE_API_URL,EVENT_SEARCH_ENDPOINT])
    param_url = "&".join([TOKEN_PARAM, LOC_ADDRESS_PARAM+address, LOCATION_WITHIN_PARAM+location_within, POPULAR_PARAM+popular, SORT_BY_PARAM+sort_by, START_DATE_PARAM+start_date_range_start, END_DATE_PARAM+start_date_range_end])
    query_url = "".join([top_url, param_url])

    session = get_session()
    ttl_events = {}
    #TODO: fix startpage
    for evt in request_and_return_res(query_url, "events"):
        for e in evt:
            try:
                v = get_venue_info(e["venue_id"])
                venue = session.query(Venue).filter(Venue.eventbrite_id==e['venue_id']).first()
                v_name = v['name'].encode("latin-1", "ignore") if v.get('name') else None

                if "address" not in v:
                    continue
                if not venue:
                    venue = Venue(name=v_name,
                                  address='{}, {}, {} {}'.format(v["address"]["address_1"], v["address"]["city"], v["address"]["region"], v["address"]["postal_code"]),
                                  lat=v["address"]["latitude"],
                                  long=v["address"]["longitude"],
                                  capacity=int(e["capacity"]),
                                  eventbrite_id=e['venue_id'])
                    session.add(venue)
                    session.commit()
                    print ("Added Venue:", v_name)
                else:
                    session.query(Venue).filter(Venue.eventbrite_id==e['venue_id']).update({'capacity':int(e["capacity"])})
                    session.commit()
                    print("Updated CAPACITY", v_name, int(e["capacity"]))
            #
                image_url = None
                if "logo" in e:
                    if e["logo"] != None and "url" in e["logo"]:
                        image_url = e["logo"]["url"]
                event = session.query(Event).filter(Event.eventbrite_id==e['id']).first()
                e_name = e["name"]["text"].encode("latin-1", "ignore") if e.get("name").get("text") else None

                if not event:
                    event = Event(name=e_name,
                                  start_time=e["start"]["local"].replace("T", " "),
                                  end_time=e["end"]["local"].replace("T", " "),
                                  eventbrite_id=e['id'],
                                  image_url=image_url,
                                  venue=venue)
                    session.add(event)
                    session.commit()
                    print ("Added Event:", e_name)
                else:
                    print ("Skipped:", e_name)

                if e["category_id"]:
                    c = get_category_name(e["category_id"])
                    if not c.get("name"):
                        continue
                    else:
                        cat_name = c["name"].encode("latin-1", "ignore")

                    category = session.query(Category).filter(Category.type==cat_name).first()
                    if not category:
                        category = Category(type=cat_name, name=cat_name)
                        session.add(category)
                        event.categories.append(category)
                        session.commit()
                        print ("Added Category:", cat_name)
                    else:
                        print ("Skipped:", cat_name)
                print('----------------------')

            except UnicodeEncodeError:
                session.rollback()
                print("FAILED")
                # print("FAILED: {} @ {}".format(e["name"]["text"], v['name']))
                continue
            except IntegrityError:
                session.rollback()
                print("DUPLICATE")
                # print("DUPLICATE: {} @ {}".formate(e["name"]["text"], v['name']))
                continue
Exemplo n.º 10
0
def main():

    params = {
        "app_key": EVENTFUL_KEY,
        "location": "San Francisco",
        "include": "categories,popularity,tickets,subcategories",
        "page_size": "100",
        "sort_order": "popularity",
        "date": "This Week",
    }

    page = 22
    data = {}

    session = get_session()
    time_cutoff = arrow.utcnow().replace(days=-1)

    while True:
        params['page_number'] = page

        r = requests.get('https://api.eventful.com/json/events/search', params=params)

        if r.status_code != 200 or not r.json().get('events'):
            return

        for e in r.json()['events']['event']:

            if not e.get('start_time') or arrow.get(e['start_time']+'-08:00') < time_cutoff:
                print("Skipping {} @ {}".format(e['title'], e['start_time']))
                continue

            if session.query(Event).filter(Event.eventful_id==e['id']).first():
                continue

            print("Trying {} @ {}".format(e['title'], e['venue_name']))

            try:
                venue = session.query(Venue).filter(Venue.eventful_id==e['venue_id']).first()
                if not venue:
                    venue = Venue(name=e['venue_name'],
                                  address='{}, {}, {} {}'.format(e['venue_address'], e['city_name'], e['region_abbr'], e['postal_code']),
                                  lat=e['latitude'],
                                  long=e['longitude'],
                                  eventful_id=e['venue_id'])
                    session.add(venue)
                    session.commit()

                event = Event(name=e['title'],
                              start_time=e['start_time'],
                              end_time=e['stop_time'],
                              eventful_popularity=int(e['popularity']),
                              eventful_id=e['id'],
                              image_url=e['image']['medium']['url'] if e.get('image') else None,
                              venue=venue)
                session.add(event)
                session.commit()

                for c in e['categories']['category']:
                    category = session.query(Category).filter(Category.type==c['id']).first()
                    if not category:
                        category = Category(type=c['id'], name=c['name'])
                        session.add(category)
                    event.categories.append(category)
                    session.commit()
            except UnicodeEncodeError:
                session.rollback()
                print("FAILED: {} @ {}".format(e['title'], e['venue_name']))
                continue

            except IntegrityError:
                session.rollback()
                print("DUPLICATE: {} @ {}".format(e['title'], e['venue_name']))
                continue

        page += 1
        print('----------On to page {}------------'.format(page))
    session.commit()
Exemplo n.º 11
0
def search_metro_area_upcoming_event(search_query="San+Francisco", metro_area_id=SF_BAY_METRO_ID, api_key=SONGKICK_API_KEY):
    # metro_url = "".join([SONGKICK_API_URL, "/metro_areas/"])
    session = get_session()
    calendar_url = "/calendar.json?"
    query_url = "".join([SONGKICK_API_URL, "/metro_areas/", SF_BAY_METRO_ID, calendar_url, "apikey=", api_key])
    print (query_url)
    cnt = 0
    for res in request_and_return_res(query_url, "event", page_num=3):
        # if cnt < 1:
        for idx, evt in enumerate(res):
            try:
                address = ref.child("venues").child('sc-ven-'+str(evt["venue"]["id"])).child('address').get().val()

                if evt.get("start"):
                    if not evt.get("start").get("time"):
                        continue
                    start_time = evt["start"]["date"] + " " + evt["start"]["time"]
                else:
                    start_time = None

                if evt.get("end"):
                    if not evt.get("end").get("time"):
                        continue
                    end_time = evt["end"]["date"] + " " + evt["end"]["time"]
                else:
                    end_time = None
                capacity = ref.child("venues").child('sc-ven-'+str(evt["venue"]["id"])).child('capacity').get().val()

                venue = session.query(Venue).filter(Venue.songkick_id==evt["venue"]["id"]).first()
                if not venue:
                    venue = Venue(name=evt["venue"]["displayName"],
                                  address=address,
                                  lat=evt["location"]["lat"],
                                  long=evt["location"]["lng"],
                                  songkick_id=evt["venue"]["id"])
                    session.add(venue)
                    session.commit()
                    print("Added VENUE:", evt["venue"]["displayName"])
                else:
                     session.query(Venue).filter(Venue.songkick_id==evt["venue"]["id"]).update({'capacity':capacity})
                     print("Added CAPACITY", evt["venue"]["displayName"], capacity)

                event = session.query(Event).filter(Event.songkick_id==evt["id"]).first()
                if not event:
                    event = Event(name=evt["displayName"],
                                  start_time=start_time,
                                  end_time=end_time,
                                  songkick_popularity=evt["popularity"],
                                  songkick_id=evt["id"],
                                  venue=venue)
                    session.add(event)
                    session.commit()
                    print("Added VENUE:", evt["displayName"])

                category = session.query(Category).filter(Category.type==evt["type"]).first()
                if not category:
                    category = Category(type=evt["type"], name=evt["type"])
                    session.add(category)
                    print("Added CATEGORY:", evt["type"])
                event.categories.append(category)
                session.commit()

            except UnicodeEncodeError:
                session.rollback()
                print("FAILED")
                # print("FAILED: {} @ {}".format(e['title'], e['venue_name']))
                continue

            except IntegrityError:
                session.rollback()
                session.query(Event).filter(Event.songkick_id==evt["id"]).update({'name':evt["displayName"]})
                session.commit()
                print("DUPLICATE")
                # print("DUPLICATE: {} @ {}".format(e['title'], e['venue_name']))
                continue