当前位置: 首页>>代码示例>>Python>>正文


Python Sitevar.get_by_id_async方法代码示例

本文整理汇总了Python中models.sitevar.Sitevar.get_by_id_async方法的典型用法代码示例。如果您正苦于以下问题:Python Sitevar.get_by_id_async方法的具体用法?Python Sitevar.get_by_id_async怎么用?Python Sitevar.get_by_id_async使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.sitevar.Sitevar的用法示例。


在下文中一共展示了Sitevar.get_by_id_async方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _render(self):
        status_sitevar_future = Sitevar.get_by_id_async('apistatus')
        fmsapi_sitevar_future = Sitevar.get_by_id_async('apistatus.fmsapi_down')
        down_events_sitevar_future = Sitevar.get_by_id_async('apistatus.down_events')

        # Error out of no sitevar found
        status_sitevar = status_sitevar_future.get_result()
        if not status_sitevar:
            self._errors = {"404": "API Status Not Found"}
            self.abort(404)

        status_dict = status_sitevar.contents
        down_events_sitevar = down_events_sitevar_future.get_result()
        down_events_list = down_events_sitevar.contents if down_events_sitevar else None

        fmsapi_sitevar = fmsapi_sitevar_future.get_result()
        status_dict['is_datafeed_down'] = True if fmsapi_sitevar and fmsapi_sitevar.contents == True else False
        status_dict['down_events'] = down_events_list if down_events_list is not None else []

        last_modified_times = [status_sitevar.updated]
        if down_events_sitevar:
            last_modified_times.append(down_events_sitevar.updated)
        if fmsapi_sitevar:
            last_modified_times.append(fmsapi_sitevar.updated)

        self._last_modified = max(last_modified_times)

        return json.dumps(status_dict, ensure_ascii=True, indent=2, sort_keys=True)
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:30,代码来源:api_status_controller.py

示例2: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _render(self, event_key, webcast_number):
        self.response.headers.add_header('content-type', 'application/json', charset='utf-8')

        output = {}
        if not webcast_number.isdigit():
            return json.dumps(output)
        webcast_number = int(webcast_number) - 1

        event = Event.get_by_id(event_key)
        if event and event.webcast:
            webcast = event.webcast[webcast_number]
            if 'type' in webcast and 'channel' in webcast:
                output['player'] = self._renderPlayer(webcast)
        else:
            special_webcasts_future = Sitevar.get_by_id_async('gameday.special_webcasts')
            special_webcasts = special_webcasts_future.get_result()
            if special_webcasts:
                special_webcasts = special_webcasts.contents
            else:
                special_webcasts = {}
            if event_key in special_webcasts:
                webcast = special_webcasts[event_key]
                if 'type' in webcast and 'channel' in webcast:
                    output['player'] = self._renderPlayer(webcast)

        return json.dumps(output)
开发者ID:hamster1147,项目名称:the-blue-alliance,代码行数:28,代码来源:ajax_controller.py

示例3: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _render(self, *args, **kw):
        special_webcasts_future = Sitevar.get_by_id_async('gameday.special_webcasts')
        special_webcasts_temp = special_webcasts_future.get_result()
        if special_webcasts_temp:
            default_chat = special_webcasts_temp.contents.get("default_chat", "")
            special_webcasts_temp = special_webcasts_temp.contents.get("webcasts", [])
        else:
            default_chat = ""
            special_webcasts_temp = []
        special_webcasts = []
        for webcast in special_webcasts_temp:
            toAppend = {}
            for key, value in webcast.items():
                toAppend[str(key)] = str(value)
            special_webcasts.append(toAppend)

        webcasts_json = {
            'special_webcasts': special_webcasts,
        }

        self.template_values.update({
            'webcasts_json': json.dumps(webcasts_json),
            'default_chat': default_chat,
        })

        path = os.path.join(os.path.dirname(__file__), '../templates/gameday2.html')
        return template.render(path, self.template_values)
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:29,代码来源:gameday_controller.py

示例4: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _render(self, event_key, webcast_number):
        self.response.headers["Cache-Control"] = "public, max-age=%d" % (5 * 60)
        self.response.headers["Pragma"] = "Public"
        self.response.headers.add_header("content-type", "application/json", charset="utf-8")

        output = {}
        if not webcast_number.isdigit():
            return json.dumps(output)
        webcast_number = int(webcast_number) - 1

        event = Event.get_by_id(event_key)
        if event and event.webcast:
            webcast = event.webcast[webcast_number]
            if "type" in webcast and "channel" in webcast:
                output["player"] = self._renderPlayer(webcast)
        else:
            special_webcasts_future = Sitevar.get_by_id_async("gameday.special_webcasts")
            special_webcasts = special_webcasts_future.get_result()
            if special_webcasts:
                special_webcasts = special_webcasts.contents
            else:
                special_webcasts = {}
            if event_key in special_webcasts:
                webcast = special_webcasts[event_key]
                if "type" in webcast and "channel" in webcast:
                    output["player"] = self._renderPlayer(webcast)

        return json.dumps(output)
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:30,代码来源:ajax_controller.py

示例5: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _render(self, event_key, webcast_number):
        self.response.headers.add_header("content-type", "application/json", charset="utf-8")

        output = {}
        if not webcast_number.isdigit():
            return json.dumps(output)
        webcast_number = int(webcast_number) - 1

        event = Event.get_by_id(event_key)
        if event and event.webcast:
            webcast = event.webcast[webcast_number]
            if "type" in webcast and "channel" in webcast:
                output["player"] = self._renderPlayer(webcast)
        else:
            special_webcasts_future = Sitevar.get_by_id_async("gameday.special_webcasts")
            special_webcasts = special_webcasts_future.get_result()
            if special_webcasts:
                special_webcasts = special_webcasts.contents
            else:
                special_webcasts = []

            special_webcasts_dict = {}
            for webcast in special_webcasts:
                special_webcasts_dict[webcast["key_name"]] = webcast

            if event_key in special_webcasts_dict:
                webcast = special_webcasts_dict[event_key]
                if "type" in webcast and "channel" in webcast:
                    output["player"] = self._renderPlayer(webcast)

        return json.dumps(output)
开发者ID:fangeugene,项目名称:the-blue-alliance,代码行数:33,代码来源:ajax_controller.py

示例6: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _render(self, *args, **kw):
        special_webcasts_future = Sitevar.get_by_id_async("gameday.special_webcasts")
        special_webcasts_temp = special_webcasts_future.get_result()
        if special_webcasts_temp:
            special_webcasts_temp = special_webcasts_temp.contents
        else:
            special_webcasts_temp = {}
        special_webcasts = []
        for webcast in special_webcasts_temp.values():
            toAppend = {}
            for key, value in webcast.items():
                toAppend[str(key)] = str(value)
            special_webcasts.append(toAppend)

        ongoing_events = []
        ongoing_events_w_webcasts = []
        week_events = EventHelper.getWeekEvents()
        for event in week_events:
            if event.within_a_day:
                ongoing_events.append(event)
                if event.webcast:
                    valid = []
                    for webcast in event.webcast:
                        if "type" in webcast and "channel" in webcast:
                            event_webcast = {"event": event}
                            valid.append(event_webcast)
                    # Add webcast numbers if more than one for an event
                    if len(valid) > 1:
                        count = 1
                        for event in valid:
                            event["count"] = count
                            count += 1
                    ongoing_events_w_webcasts += valid

        self.template_values.update(
            {
                "special_webcasts": special_webcasts,
                "ongoing_events": ongoing_events,
                "ongoing_events_w_webcasts": ongoing_events_w_webcasts,
            }
        )

        path = os.path.join(os.path.dirname(__file__), "../templates/gameday.html")
        return template.render(path, self.template_values)
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:46,代码来源:main_controller.py

示例7: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _render(self, *args, **kw):
        next_events = Event.query(Event.start_date >= (datetime.datetime.today() - datetime.timedelta(days=4)))
        next_events.order(Event.start_date).fetch(20)
        
        special_webcasts_future = Sitevar.get_by_id_async('gameday.special_webcasts')
        special_webcasts_temp = special_webcasts_future.get_result()
        if special_webcasts_temp:
            special_webcasts_temp = special_webcasts_temp.contents
        else:
            special_webcasts_temp = {}
        special_webcasts =  []
        for webcast in special_webcasts_temp.values():
            toAppend = {}
            for key, value in webcast.items():
                toAppend[str(key)] = str(value)
            special_webcasts.append(toAppend)

        ongoing_events = []
        ongoing_events_w_webcasts = []
        for event in next_events:
            if event.start_date.date() < datetime.date.today() + datetime.timedelta(days=4):
                ongoing_events.append(event)
                if event.webcast:
                    valid = []
                    for webcast in event.webcast:
                        if 'type' in webcast and 'channel' in webcast:
                            event_webcast = {'event': event}
                            valid.append(event_webcast)
                    # Add webcast numbers if more than one for an event
                    if len(valid) > 1:
                        count = 1
                        for event in valid:
                            event['count'] = count
                            count += 1
                    ongoing_events_w_webcasts += valid
        
        template_values = {'special_webcasts': special_webcasts,
                           'ongoing_events': ongoing_events,
                           'ongoing_events_w_webcasts': ongoing_events_w_webcasts}
        
        path = os.path.join(os.path.dirname(__file__), '../templates/gameday.html')
        return template.render(path, template_values)
开发者ID:dweitz,项目名称:the-blue-alliance,代码行数:44,代码来源:main_controller.py

示例8: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _render(self, *args, **kw):
        template_values = {}

        special_webcasts_future = Sitevar.get_by_id_async('gameday.special_webcasts')
        special_webcasts_temp = special_webcasts_future.get_result()
        if special_webcasts_temp:
            special_webcasts_temp = special_webcasts_temp.contents
        else:
            special_webcasts_temp = {}
        special_webcasts = []
        for webcast in special_webcasts_temp.values():
            toAppend = {}
            for key, value in webcast.items():
                toAppend[str(key)] = str(value)
            special_webcasts.append(toAppend)

        template_values = {'special_webcasts': special_webcasts}

        path = os.path.join(os.path.dirname(__file__), '../templates/gameday2.html')
        return template.render(path, template_values)
开发者ID:linuxuser0,项目名称:the-blue-alliance,代码行数:22,代码来源:gameday2_controller.py

示例9: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
 def _render(self, event_key, webcast_number):
     event = Event.get_by_id(event_key)
     output = {}
     if event and event.webcast:
         webcast = event.webcast[webcast_number]
         if 'type' in webcast and 'channel' in webcast:
             output['player'] = self._renderPlayer(webcast)
     else:
         special_webcasts_future = Sitevar.get_by_id_async('gameday.special_webcasts')
         special_webcasts = special_webcasts_future.get_result()
         if special_webcasts:
             special_webcasts = special_webcasts.contents
         else:
             special_webcasts = {}
         if event_key in special_webcasts:
             webcast = special_webcasts[event_key]
             if 'type' in webcast and 'channel' in webcast:
                 output['player'] = self._renderPlayer(webcast)                   
             
     return json.dumps(output)
开发者ID:lyncas,项目名称:the-blue-alliance,代码行数:22,代码来源:ajax_controller.py

示例10: _validate_auth

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _validate_auth(self, auth, event_key):
        status_sitevar_future = Sitevar.get_by_id_async('trustedapi')
        allowed_event_keys = [ekey.id() for ekey in auth.event_list]
        if event_key not in allowed_event_keys:
            return "Only allowed to edit events: {}".format(', '.join(allowed_event_keys))

        missing_auths = self.REQUIRED_AUTH_TYPES.difference(set(auth.auth_types_enum))
        if missing_auths != set():
            return "You do not have permission to edit: {}. If this is incorrect, please contact TBA admin.".format(",".join([AuthType.write_type_names[ma] for ma in missing_auths]))

        if auth.expiration and auth.expiration < datetime.datetime.now():
            return "These keys expired on {}. Contact TBA admin to make changes".format(auth.expiration)

        status_sitevar = status_sitevar_future.get_result()
        if status_sitevar:
            for auth_type in self.REQUIRED_AUTH_TYPES:
                if not status_sitevar.contents.get(str(auth_type), True):  # Fail open
                    return "The trusted API has been temporarily disabled by the TBA admins. Please contact them for more details."

        return None
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:22,代码来源:api_base_controller.py

示例11: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _render(self, *args, **kw):
        special_webcasts_future = Sitevar.get_by_id_async('gameday.special_webcasts')
        special_webcasts_temp = special_webcasts_future.get_result()
        if special_webcasts_temp:
            special_webcasts_temp = special_webcasts_temp.contents
        else:
            special_webcasts_temp = {}
        special_webcasts =  []
        for webcast in special_webcasts_temp.values():
            toAppend = {}
            for key, value in webcast.items():
                toAppend[str(key)] = str(value)
            special_webcasts.append(toAppend)

        ongoing_events = []
        ongoing_events_w_webcasts = []
        upcoming_events = EventHelper.getUpcomingEvents()
        for event in upcoming_events:
            if event.within_a_day:
                ongoing_events.append(event)
                if event.webcast:
                    valid = []
                    for webcast in event.webcast:
                        if 'type' in webcast and 'channel' in webcast:
                            event_webcast = {'event': event}
                            valid.append(event_webcast)
                    # Add webcast numbers if more than one for an event
                    if len(valid) > 1:
                        count = 1
                        for event in valid:
                            event['count'] = count
                            count += 1
                    ongoing_events_w_webcasts += valid
        
        template_values = {'special_webcasts': special_webcasts,
                           'ongoing_events': ongoing_events,
                           'ongoing_events_w_webcasts': ongoing_events_w_webcasts}
        
        path = os.path.join(os.path.dirname(__file__), '../templates/gameday.html')
        return template.render(path, template_values)
开发者ID:germy,项目名称:the-blue-alliance,代码行数:42,代码来源:main_controller.py

示例12: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _render(self, event_key, webcast_number):
        self.response.headers['Cache-Control'] = "public, max-age=%d" % (5 * 60)
        self.response.headers['Pragma'] = 'Public'
        self.response.headers.add_header('content-type', 'application/json', charset='utf-8')

        event = Event.get_by_id(event_key)
        output = {}
        if event and event.webcast:
            webcast = event.webcast[webcast_number]
            if 'type' in webcast and 'channel' in webcast:
                output['player'] = self._renderPlayer(webcast)
        else:
            special_webcasts_future = Sitevar.get_by_id_async('gameday.special_webcasts')
            special_webcasts = special_webcasts_future.get_result()
            if special_webcasts:
                special_webcasts = special_webcasts.contents
            else:
                special_webcasts = {}
            if event_key in special_webcasts:
                webcast = special_webcasts[event_key]
                if 'type' in webcast and 'channel' in webcast:
                    output['player'] = self._renderPlayer(webcast)

        return json.dumps(output)
开发者ID:linuxuser0,项目名称:the-blue-alliance,代码行数:26,代码来源:ajax_controller.py

示例13: _render

# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id_async [as 别名]
    def _render(self, event_key):
        event = EventQuery(event_key).fetch()

        if not event:
            self.abort(404)

        event.prepAwardsMatchesTeams()
        event.prep_details()
        medias_future = media_query.EventTeamsPreferredMediasQuery(event_key).fetch_async()
        district_future = DistrictQuery(event.district_key.id()).fetch_async() if event.district_key else None
        event_medias_future = media_query.EventMediasQuery(event_key).fetch_async()
        status_sitevar_future = Sitevar.get_by_id_async('apistatus.down_events')

        event_divisions_future = None
        event_codivisions_future = None
        parent_event_future = None
        if event.divisions:
            event_divisions_future = ndb.get_multi_async(event.divisions)
        elif event.parent_event:
            parent_event_future = event.parent_event.get_async()
            event_codivisions_future = EventDivisionsQuery(event.parent_event.id()).fetch_async()

        awards = AwardHelper.organizeAwards(event.awards)
        cleaned_matches = MatchHelper.deleteInvalidMatches(event.matches, event)
        matches = MatchHelper.organizeMatches(cleaned_matches)
        teams = TeamHelper.sortTeams(event.teams)

        # Organize medias by team
        image_medias = MediaHelper.get_images([media for media in medias_future.get_result()])
        team_medias = defaultdict(list)
        for image_media in image_medias:
            for reference in image_media.references:
                team_medias[reference].append(image_media)
        team_and_medias = []
        for team in teams:
            team_and_medias.append((team, team_medias.get(team.key, [])))

        num_teams = len(team_and_medias)
        middle_value = num_teams / 2
        if num_teams % 2 != 0:
            middle_value += 1
        teams_a, teams_b = team_and_medias[:middle_value], team_and_medias[middle_value:]

        oprs = [i for i in event.matchstats['oprs'].items()] if (event.matchstats is not None and 'oprs' in event.matchstats) else []
        oprs = sorted(oprs, key=lambda t: t[1], reverse=True)  # sort by OPR
        oprs = oprs[:15]  # get the top 15 OPRs

        if event.now:
            matches_recent = MatchHelper.recentMatches(cleaned_matches)
            matches_upcoming = MatchHelper.upcomingMatches(cleaned_matches)
        else:
            matches_recent = None
            matches_upcoming = None

        bracket_table = MatchHelper.generateBracket(matches, event, event.alliance_selections)

        playoff_advancement = None
        playoff_template = None
        double_elim_matches = None
        if EventHelper.is_2015_playoff(event_key):
            playoff_advancement = MatchHelper.generatePlayoffAdvancement2015(matches, event.alliance_selections)
            playoff_template = 'playoff_table'
            for comp_level in ['qf', 'sf']:
                if comp_level in bracket_table:
                    del bracket_table[comp_level]
        elif event.playoff_type == PlayoffType.ROUND_ROBIN_6_TEAM:
            playoff_advancement = MatchHelper.generatePlayoffAdvancementRoundRobin(matches, event.year, event.alliance_selections)
            playoff_template = 'playoff_round_robin_6_team'
            comp_levels = bracket_table.keys()
            for comp_level in comp_levels:
                if comp_level != 'f':
                    del bracket_table[comp_level]
        elif event.playoff_type == PlayoffType.BO3_FINALS or event.playoff_type == PlayoffType.BO5_FINALS:
            comp_levels = bracket_table.keys()
            for comp_level in comp_levels:
                if comp_level != 'f':
                    del bracket_table[comp_level]
        elif event.playoff_type == PlayoffType.DOUBLE_ELIM_8_TEAM:
            double_elim_matches = MatchHelper.organizeDoubleElimMatches(matches)

        district_points_sorted = None
        if event.district_key and event.district_points:
            district_points_sorted = sorted(event.district_points['points'].items(), key=lambda (team, points): -points['total'])

        event_insights = event.details.insights if event.details else None
        event_insights_template = None
        if event_insights:
            event_insights_template = 'event_partials/event_insights_{}.html'.format(event.year)

        district = district_future.get_result() if district_future else None
        event_divisions = None
        if event_divisions_future:
            event_divisions = [e.get_result() for e in event_divisions_future]
        elif event_codivisions_future:
            event_divisions = event_codivisions_future.get_result()

        medias_by_slugname = MediaHelper.group_by_slugname([media for media in event_medias_future.get_result()])
        has_time_predictions = matches_upcoming and any(match.predicted_time for match in matches_upcoming)

        status_sitevar = status_sitevar_future.get_result()
#.........这里部分代码省略.........
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:103,代码来源:event_controller.py


注:本文中的models.sitevar.Sitevar.get_by_id_async方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。