本文整理汇总了Python中datafeeds.datafeed_usfirst.DatafeedUsfirst.getEventTeams方法的典型用法代码示例。如果您正苦于以下问题:Python DatafeedUsfirst.getEventTeams方法的具体用法?Python DatafeedUsfirst.getEventTeams怎么用?Python DatafeedUsfirst.getEventTeams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datafeeds.datafeed_usfirst.DatafeedUsfirst
的用法示例。
在下文中一共展示了DatafeedUsfirst.getEventTeams方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from datafeeds.datafeed_usfirst import DatafeedUsfirst [as 别名]
# 或者: from datafeeds.datafeed_usfirst.DatafeedUsfirst import getEventTeams [as 别名]
def get(self, year, first_eid):
datafeed = DatafeedUsfirst()
event = datafeed.getEventDetails(int(year), first_eid)
event = EventManipulator.createOrUpdate(event)
teams = datafeed.getEventTeams(int(year), first_eid)
teams = TeamManipulator.createOrUpdate(teams)
if teams:
event_teams = [EventTeam(
id = event.key.id() + "_" + team.key.id(),
event = event.key,
team = team.key,
year = event.year)
for team in teams]
event_teams = EventTeamManipulator.createOrUpdate(event_teams)
else:
event_teams = []
template_values = {
'event': event,
'event_teams': event_teams,
}
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_event_details_get.html')
self.response.out.write(template.render(path, template_values))
示例2: get
# 需要导入模块: from datafeeds.datafeed_usfirst import DatafeedUsfirst [as 别名]
# 或者: from datafeeds.datafeed_usfirst.DatafeedUsfirst import getEventTeams [as 别名]
def get(self, year, first_eid):
df = DatafeedUsfirst()
df_legacy = DatafeedUsfirstLegacy()
event = df.getEventDetails(first_eid)
if not event:
logging.warning("getEventDetails with DatafeedUsfirst for event id {} failed. Retrying with DatafeedUsfirstLegacy.".format(first_eid))
event = df_legacy.getEventDetails(int(year), first_eid)
if self.request.get('event_district_enum'):
event.event_district_enum = int(self.request.get('event_district_enum'))
event = EventManipulator.createOrUpdate(event)
teams = df.getEventTeams(int(year), first_eid)
if not teams:
logging.warning("getEventTeams with DatafeedUsfirst for event id {} failed. Retrying with DatafeedUsfirstLegacy.".format(first_eid))
teams = df_legacy.getEventTeams(int(year), first_eid)
if not teams:
logging.warning("getEventTeams with DatafeedUsfirstLegacy for event id {} failed.".format(first_eid))
teams = []
teams = TeamManipulator.createOrUpdate(teams)
if teams:
if type(teams) is not list:
teams = [teams]
event_teams = [EventTeam(
id=event.key.id() + "_" + team.key.id(),
event=event.key,
team=team.key,
year=event.year)
for team in teams]
# Delete eventteams of teams that unregister from an event
if event.future:
existing_event_team_keys = set(EventTeam.query(EventTeam.event == event.key).fetch(1000, keys_only=True))
event_team_keys = set([et.key for et in event_teams])
et_keys_to_delete = existing_event_team_keys.difference(event_team_keys)
EventTeamManipulator.delete_keys(et_keys_to_delete)
event_teams = EventTeamManipulator.createOrUpdate(event_teams)
if type(event_teams) is not list:
event_teams = [event_teams]
else:
event_teams = []
template_values = {
'event': event,
'event_teams': event_teams,
}
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_event_details_get.html')
self.response.out.write(template.render(path, template_values))
示例3: TestDatafeedUsfirstEvents
# 需要导入模块: from datafeeds.datafeed_usfirst import DatafeedUsfirst [as 别名]
# 或者: from datafeeds.datafeed_usfirst.DatafeedUsfirst import getEventTeams [as 别名]
class TestDatafeedUsfirstEvents(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
self.datafeed = DatafeedUsfirst()
def tearDown(self):
self.testbed.deactivate()
def test_getEvent(self):
# test with 2011ct
event = self.datafeed.getEventDetails("5561")
self.assertEqual(event.key.id(), "2011ct")
self.assertEqual(event.name, "Northeast Utilities FIRST Connecticut Regional")
self.assertEqual(event.event_type_enum, EventType.REGIONAL)
self.assertEqual(event.start_date, datetime.datetime(2011, 3, 31, 0, 0))
self.assertEqual(event.end_date, datetime.datetime(2011, 4, 2, 0, 0))
self.assertEqual(event.year, 2011)
self.assertEqual(event.venue_address, "Connecticut Convention Center\r\n100 Columbus Blvd\r\nHartford, CT 06103\r\nUSA")
self.assertEqual(event.website, "http://www.ctfirst.org/ctr")
self.assertEqual(event.event_short, "ct")
def test_getEventTeams(self):
# test with 2011ct
teams = self.datafeed.getEventTeams(2011, "5561")
sort_key = lambda t: t[1]
self.assertEqual(
sorted([(team.team_number, team.first_tpid) for team in teams], key=sort_key),
sorted([(383, 41829), (1124, 42285), (155, 41609), (3634, 51637), (999, 42215), (1699, 42751), (173, 41625), (175, 41629), (716, 42049), (178, 41635), (2170, 43331), (3146, 44577), (2168, 43335), (2067, 43175), (181, 41641), (1991, 43133), (3125, 44539), (2785, 44073), (1740, 42765), (1784, 42895), (3654, 51609), (3718, 49891), (558, 41939), (3719, 52081), (230, 41681), (3464, 49827), (177, 41633), (2064, 43159), (195, 41651), (3104, 44463), (3555, 49069), (3141, 44487), (3461, 47483), (3525, 48801), (237, 41691), (3182, 44547), (571, 41947), (176, 41631), (1071, 42251), (2836, 43965), (126, 41585), (157, 41611), (69, 41519), (1027, 42235), (663, 42007), (3585, 50743), (1073, 42255), (501, 41899), (869, 42131), (714, 42047), (1923, 42947), (743, 42051), (20, 41475), (3204, 44731), (1601, 42659), (2791, 43935), (533, 41919), (694, 42027)], key=sort_key)
)
def test_getEventList(self):
events = self.datafeed.getEventList(2011)
self.assertEqual(len(events), 58) # 58 events expected
self.assertEqual(events[0].first_eid, "5519")
self.assertEqual(events[0].event_type_enum, EventType.REGIONAL)
self.assertEqual(events[0].name, "BAE Systems/Granite State Regional")
self.assertEqual(events[1].first_eid, "5523")
self.assertEqual(events[1].event_type_enum, EventType.REGIONAL)
self.assertEqual(events[1].name, "New Jersey Regional")
示例4: get
# 需要导入模块: from datafeeds.datafeed_usfirst import DatafeedUsfirst [as 别名]
# 或者: from datafeeds.datafeed_usfirst.DatafeedUsfirst import getEventTeams [as 别名]
def get(self, year, first_eid):
df = DatafeedUsfirst()
df_legacy = DatafeedUsfirstLegacy()
event = df.getEventDetails(first_eid)
if not event:
logging.warning("getEventDetails with DatafeedUsfirst for event id {} failed. Retrying with DatafeedUsfirstLegacy.".format(first_eid))
event = df_legacy.getEventDetails(int(year), first_eid)
event = EventManipulator.createOrUpdate(event)
teams = df.getEventTeams(int(year), first_eid)
if not teams:
logging.warning("getEventTeams with DatafeedUsfirst for event id {} failed. Retrying with DatafeedUsfirstLegacy.".format(first_eid))
teams = df_legacy.getEventTeams(int(year), first_eid)
if not teams:
logging.warning("getEventTeams with DatafeedUsfirstLegacy for event id {} failed.".format(first_eid))
teams = []
teams = TeamManipulator.createOrUpdate(teams)
if teams:
if type(teams) is not list:
teams = [teams]
event_teams = [EventTeam(
id=event.key.id() + "_" + team.key.id(),
event=event.key,
team=team.key,
year=event.year)
for team in teams]
event_teams = EventTeamManipulator.createOrUpdate(event_teams)
if type(event_teams) is not list:
event_teams = [event_teams]
else:
event_teams = []
template_values = {
'event': event,
'event_teams': event_teams,
}
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_event_details_get.html')
self.response.out.write(template.render(path, template_values))