示例#1
0
def store_event(data):
    event = Event(id=data['key'])
    event.name = data['name']
    event.short_name = data['short_name']
    event.event_short = data['event_code']
    event.event_type_enum = data['event_type']
    event.year = data['year']
    event.timezone_id = data['timezone']
    event.website = data['website']
    event.start_date = datetime.datetime.strptime(
        data['start_date'],
        EVENT_DATE_FORMAT_STR) if data['start_date'] else None
    event.end_date = datetime.datetime.strptime(
        data['end_date'], EVENT_DATE_FORMAT_STR) if data['end_date'] else None
    event.webcast_json = json.dumps(data['webcasts'])
    event.venue = data['location_name']
    event.city = data['city']
    event.state_prov = data['state_prov']
    event.country = data['country']
    event.playoff_type = data['playoff_type']
    event.parent_event = ndb.Key(
        Event, data['parent_event_key']) if data['parent_event_key'] else None
    event.divisions = [
        ndb.Key(Event, div_key) for div_key in data['division_keys']
    ] if data['division_keys'] else []

    district = store_district(data['district']) if data['district'] else None
    event.district_key = district.key if district else None

    return EventManipulator.createOrUpdate(event)
 def test_is_maybe_match_wrong_city(self):
     event_one = Event(start_date=datetime.datetime(year=2020,
                                                    month=7,
                                                    day=14,
                                                    hour=0,
                                                    minute=0,
                                                    second=0),
                       end_date=datetime.datetime(year=2020,
                                                  month=7,
                                                  day=15,
                                                  hour=23,
                                                  minute=59,
                                                  second=59),
                       city="London",
                       state_prov="OH")
     event_two = Event(start_date=datetime.datetime(year=2020,
                                                    month=7,
                                                    day=14,
                                                    hour=0,
                                                    minute=0,
                                                    second=0),
                       end_date=datetime.datetime(year=2020,
                                                  month=7,
                                                  day=15,
                                                  hour=23,
                                                  minute=59,
                                                  second=59),
                       city="Sandusky",
                       state_prov="OH")
     self.assertFalse(
         OffseasonEventHelper.is_maybe_match(event_one, event_two))
     event_two.city = event_one.city
     self.assertTrue(
         OffseasonEventHelper.is_maybe_match(event_one, event_two))
示例#3
0
    def test_championship_location(self):
        # No home_cmp, no updated
        team = Team(id="frc7332", team_number=7332)
        self.assertIsNone(team.home_cmp)
        self.assertIsNone(team.updated)
        self.assertIsNone(team.championship_location)

        # home_cmp, no updated
        team.home_cmp = 'cmp'
        self.assertIsNotNone(team.home_cmp)
        self.assertIsNone(team.updated)
        self.assertIsNone(team.championship_location)

        # no home_cmp, updated
        team.home_cmp = None
        team.updated = datetime.now()
        self.assertIsNone(team.home_cmp)
        self.assertIsNotNone(team.updated)
        self.assertIsNone(team.championship_location)

        # home_cmp, updated, no event
        team.home_cmp = 'cmp'
        self.assertIsNotNone(team.home_cmp)
        self.assertIsNotNone(team.updated)
        self.assertIsNone(team.championship_location)

        event = Event(id="{}{}".format(team.updated.year, team.home_cmp),
                      event_type_enum=EventType.CMP_FINALS,
                      event_short="cmp",
                      year=team.updated.year)
        event.put()

        # home_cmp, updated, event, no city
        self.assertIsNotNone(team.home_cmp)
        self.assertIsNotNone(team.updated)
        self.assertIsNone(team.championship_location)

        # home_cmp, updated, event, city
        event.city = 'Atlanta'
        self.assertIsNotNone(team.home_cmp)
        self.assertIsNotNone(team.updated)
        self.assertEqual(team.championship_location,
                         {team.updated.year: 'Atlanta'})
def store_event(data):
    event = Event(id=data['key'])
    event.name = data['name']
    event.short_name = data['short_name']
    event.event_short = data['event_code']
    event.event_type_enum = data['event_type']
    event.year = data['year']
    event.timezone_id = data['timezone']
    event.website = data['website']
    event.start_date = datetime.datetime.strptime(data['start_date'], EVENT_DATE_FORMAT_STR) if data['start_date'] else None
    event.end_date = datetime.datetime.strptime(data['end_date'], EVENT_DATE_FORMAT_STR) if data['end_date'] else None
    event.webcast_json = json.dumps(data['webcasts'])
    event.venue = data['location_name']
    event.city = data['city']
    event.state_prov = data['state_prov']
    event.country = data['country']

    district = store_district(data['district']) if data['district'] else None
    event.district_key = district.key if district else None

    return EventManipulator.createOrUpdate(event)
示例#5
0
 def set_event_details(e_id, name, date, city,  add, descr, host, url, attendees, price, category, source):
     event1 = Event()
     qry = event1.check_event_exist(e_id) or event1.check_event_exist_by_name(name)
     if qry is False:
         event1.id = e_id
         event1.name = name
         event1.date = date
         event1.city = city
         event1.address = add
         event1.description = descr
         event1.host = host
         event1.event_url = url
         event1.source = source
         if (attendees != "Unknown"):
             event1.attendees = attendees
         event1.price = price
         if category is not None:
             event1.category = category
         key = event1.put()
         return key
     else:  # Update existing meetings! It could be changed or canceled!
         qry.name = name
         qry.date = date
         qry.city = city
         qry.address = add
         qry.description = descr
         qry.host = host
         qry.event_url = url
         qry.source = source
         qry.price = price
         if category is not None:
             qry.category = category
         results = Attendings.query(Attendings.event_id == qry.get_by_id(e_id))
         if results is not None:
             qry.attendees = attendees + results.count()
         else:
             qry.attendees = attendees
         qry.put()
示例#6
0
 def set_event_details(e_id, name, date, city,  add, descr, host, url, attendees, price, category, source):
     event1 = Event()
     qry = event1.check_event_exist(e_id) or event1.check_event_exist_by_name(name)
     if qry is False:
         event1.id = e_id
         event1.name = name
         event1.date = date
         event1.city = city
         event1.address = add
         event1.description = descr
         event1.host = host
         event1.event_url = url
         event1.source = source
         if (attendees != "Unknown"):
             event1.attendees = attendees
         event1.price = price
         if category is not None:
             event1.category = category
         key = event1.put()
         return key
     else:  # Update existing meetings! It could be changed or canceled!
         qry.name = name
         qry.date = date
         qry.city = city
         qry.address = add
         qry.description = descr
         qry.host = host
         qry.event_url = url
         qry.source = source
         qry.price = price
         if category is not None:
             qry.category = category
         results = Attendings.query(Attendings.event_id == qry.get_by_id(e_id))
         if results is not None:
             qry.attendees = attendees + results.count()
         else:
             qry.attendees = attendees
         qry.put()
示例#7
0
    def extract(self):
        connector = self.get_connector()

        i = 0
        for key, res in self.data.items():
            res_key = self.create_key(res['name'], res['city'])

            connector_res = get_from(connector.data, [res_key], {})
            res.update(connector_res)

            place_id = get_from(res, ['place_id'])
            if place_id:
                print("Found {} | {} => {}".format(i, place_id, res_key))
                if res_key not in connector.data or res != connector.data[
                        res_key]:
                    "\tUpdate"
                    connector.data[res_key] = res
                    db_session.merge(connector)
                    db_session.commit()
                pass
            else:
                place_q = ", ".join([
                    res['name'] or "",
                    get_from(res, ['address'], ""), res['city'] or ""
                ])

                print("!!!GEOCODE!!! {} | {} => {}".format(
                    i, res_key, place_q))

                try:
                    results = self.client.find_place(
                        input=place_q,
                        input_type='textquery',
                        fields=["place_id", "name", "formatted_address"])
                    res_data = get_from(results, ['candidates', 0], {})

                    res_addr = get_from(res_data, ['formatted_address'])
                    if 'formatted_address' in res_data:
                        del res_data["formatted_address"]
                    if res_addr: res_data["address"] = res_addr

                    res.update(res_data)

                    connector.data[res_key] = res
                    db_session.merge(connector)
                    db_session.commit()
                except Exception as e:
                    print("\t!!!ERROR!!! => {}".format(e))

                print("\t{}".format(res))
            i += 1

        i = 0
        for key, res in self.data.items():
            place_id = get_from(res, ['place_id'])
            if not place_id: continue

            ev = Event.query.filter(
                or_(Event.name == res['name'],
                    Event.alias == place_id)).first()

            if ev:
                print("Found Event({}) => {}".format(place_id, res['name']))
            else:
                print("Create Event({}) => {}".format(place_id, res['name']))
                print("\t{}".format(res))

                ev = Event(name=res['name'], alias=res['place_id'])

            # print(i, json.dumps(res, indent=2))
            i += 1

            ev.primary_type = Tag.FOOD_DRINK
            ev.address = get_from(res, ['address'])
            ev.city = res['city']
            ev.state = get_from(res, ['state'])
            if not ev.meta: ev.meta = {}
            ev.meta[self.TYPE] = res
            db_session.merge(ev)
            db_session.commit()