• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sitevar.Sitevar类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _render

    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,代码行数:28,代码来源:api_status_controller.py


示例2: post

    def post(self):
        self._require_admin()

        trusted_sitevar = Sitevar.get_or_insert('trustedapi')
        sitevar = Sitevar.get_or_insert('apistatus')
        old_value = sitevar.contents

        status = {}
        status['android'] = {}
        status['ios'] = {}
        status['max_season'] = int(self.request.get('max_year'))
        status['current_season'] = int(self.request.get('current_year'))
        status['android']['latest_app_version'] = int(self.request.get('android_latest_version'))
        status['android']['min_app_version'] = int(self.request.get('android_min_version'))
        status['ios']['latest_app_version'] = int(self.request.get('ios_latest_version'))
        status['ios']['min_app_version'] = int(self.request.get('ios_min_version'))
        sitevar.contents = status
        sitevar.put()

        trusted_status = {
            1: True if self.request.get('enable_match_video') else False,
            2: True if self.request.get('enable_event_teams') else False,
            3: True if self.request.get('enable_event_matches') else False,
            4: True if self.request.get('enable_event_rankings') else False,
            5: True if self.request.get('enable_event_alliances') else False,
            6: True if self.request.get('enable_event_awards') else False,
        }
        trusted_sitevar.contents = trusted_status
        trusted_sitevar.put()

        ApiStatusController.clear_cache_if_needed(old_value, status)

        self.redirect('/admin/apistatus')
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:33,代码来源:admin_apistatus_controller.py


示例3: test_parse_2017_events_with_cmp_hacks

    def test_parse_2017_events_with_cmp_hacks(self):
        hack_sitevar = Sitevar(id='cmp_registration_hacks')
        hack_sitevar.contents = {
            "event_name_override": [
                {"event": "2017cmpmo", "name": "FIRST Championship Event", "short_name": "Championship"},
                {"event": "2017cmptx", "name": "FIRST Championship Event", "short_name": "Championship"}],
            "set_start_to_last_day": ["2017cmptx", "2017cmpmo"],
            "divisions_to_skip": ["2017arc", "2017cars", "2017cur", "2017dal", "2017dar"],
        }
        hack_sitevar.put()

        with open('test_data/fms_api/2017_event_list.json', 'r') as f:
            events, districts = FMSAPIEventListParser(2017).parse(json.loads(f.read()))
            self.assertEqual(len(events), 159)
            self.assertEqual(len(districts), 10)

            non_einstein_types = EventType.CMP_EVENT_TYPES
            non_einstein_types.remove(EventType.CMP_FINALS)
            for key in hack_sitevar.contents['divisions_to_skip']:
                self.assertFalse(filter(lambda e: e.key_name == key, events))

            einstein_stl = next(e for e in events if e.key_name == '2017cmpmo')
            self.assertIsNotNone(einstein_stl)
            self.assertEqual(einstein_stl.name, "FIRST Championship Event (St. Louis)")
            self.assertEqual(einstein_stl.short_name, "Championship (St. Louis)")
            self.assertEquals(einstein_stl.start_date, datetime.datetime(year=2017, month=4, day=29, hour=0, minute=0, second=0))
            self.assertEquals(einstein_stl.end_date, datetime.datetime(year=2017, month=4, day=29, hour=23, minute=59, second=59))

            einstein_hou = next(e for e in events if e.key_name == '2017cmptx')
            self.assertIsNotNone(einstein_hou)
            self.assertEqual(einstein_hou.name, "FIRST Championship Event (Houston)")
            self.assertEqual(einstein_hou.short_name, "Championship (Houston)")
            self.assertEquals(einstein_hou.start_date, datetime.datetime(year=2017, month=4, day=22, hour=0, minute=0, second=0))
            self.assertEquals(einstein_hou.end_date, datetime.datetime(year=2017, month=4, day=22, hour=23, minute=59, second=59))
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:34,代码来源:test_fms_api_event_list_parser.py


示例4: post

    def post(self):
        self._require_admin()

        google_secrets = Sitevar.get_or_insert('google.secrets')
        firebase_secrets = Sitevar.get_or_insert('firebase.secrets')
        fmsapi_secrets = Sitevar.get_or_insert('fmsapi.secrets')
        mobile_clientIds = Sitevar.get_or_insert('mobile.clientIds')
        gcm_serverKey = Sitevar.get_or_insert('gcm.serverKey')

        google_key = self.request.get("google_secret")
        firebase_key = self.request.get("firebase_secret")
        fmsapi_user = self.request.get("fmsapi_user")
        fmsapi_secret = self.request.get("fmsapi_secret")
        web_client_id = self.request.get("web_client_id")
        android_client_id = self.request.get("android_client_id")
        ios_client_id = self.request.get("ios_client_id")
        gcm_key = self.request.get("gcm_key")

        google_secrets.contents = {'api_key': google_key}
        firebase_secrets.contents = {'FIREBASE_SECRET': firebase_key}
        fmsapi_secrets.contents = {'username': fmsapi_user, 'authkey': fmsapi_secret}
        mobile_clientIds.contents = {'web': web_client_id, 'android': android_client_id,
                                     'ios': ios_client_id}
        gcm_serverKey.contents = {'gcm_key': gcm_key}

        google_secrets.put()
        firebase_secrets.put()
        fmsapi_secrets.put()
        mobile_clientIds.put()
        gcm_serverKey.put()

        self.redirect('/admin/authkeys')
开发者ID:brycematsuda,项目名称:the-blue-alliance,代码行数:32,代码来源:admin_authkeys_controller.py


示例5: post

    def post(self, sitevar_key):
        #note, we don't use sitevar_key

        sitevar = Sitevar(
            id = self.request.get("key"),
            description = self.request.get("description"),
            values_json = self.request.get("values_json"),
        )
        sitevar.put()
        
        self.redirect("/admin/sitevar/edit/" + sitevar.key.id() + "?success=true")
开发者ID:dweitz,项目名称:the-blue-alliance,代码行数:11,代码来源:admin_sitevar_controller.py


示例6: __init__

    def __init__(self, version, sim_time=None, save_response=False):
        self._sim_time = sim_time
        self._save_response = save_response and sim_time is None
        fms_api_secrets = Sitevar.get_by_id('fmsapi.secrets')
        if fms_api_secrets is None:
            if self._sim_time is None:
                raise Exception("Missing sitevar: fmsapi.secrets. Can't access FMS API.")
        else:
            fms_api_username = fms_api_secrets.contents['username']
            fms_api_authkey = fms_api_secrets.contents['authkey']
            self._fms_api_authtoken = base64.b64encode('{}:{}'.format(fms_api_username, fms_api_authkey))

        self._is_down_sitevar = Sitevar.get_by_id('apistatus.fmsapi_down')
        if not self._is_down_sitevar:
            self._is_down_sitevar = Sitevar(id="apistatus.fmsapi_down", description="Is FMSAPI down?")

        self.FMS_API_DOMAIN = 'https://frc-api.firstinspires.org/'
        if version == 'v1.0':
            FMS_API_URL_BASE = self.FMS_API_DOMAIN + 'api/v1.0'
            self.FMS_API_AWARDS_URL_PATTERN = FMS_API_URL_BASE + '/awards/%s/%s'  # (year, event_short)
            self.FMS_API_HYBRID_SCHEDULE_QUAL_URL_PATTERN = FMS_API_URL_BASE + '/schedule/%s/%s/qual/hybrid'  # (year, event_short)
            self.FMS_API_HYBRID_SCHEDULE_PLAYOFF_URL_PATTERN = FMS_API_URL_BASE + '/schedule/%s/%s/playoff/hybrid'  # (year, event_short)
            self.FMS_API_EVENT_RANKINGS_URL_PATTERN = FMS_API_URL_BASE + '/rankings/%s/%s'  # (year, event_short)
            self.FMS_API_EVENT_ALLIANCES_URL_PATTERN = FMS_API_URL_BASE + '/alliances/%s/%s'  # (year, event_short)
            self.FMS_API_TEAM_DETAILS_URL_PATTERN = FMS_API_URL_BASE + '/teams/%s/?teamNumber=%s'  # (year, teamNumber)
            self.FMS_API_TEAM_AVATAR_URL_PATTERN = FMS_API_URL_BASE + '/%s/avatars/?teamNumber=%s'  # (year, teamNumber)
            self.FMS_API_EVENT_AVATAR_URL_PATTERN = FMS_API_URL_BASE + '/%s/avatars/?eventCode=%s&page=%s'  # (year, eventCode, page)
            self.FMS_API_EVENT_LIST_URL_PATTERN = FMS_API_URL_BASE + '/events/season=%s'
            self.FMS_API_EVENTTEAM_LIST_URL_PATTERN = FMS_API_URL_BASE + '/teams/?season=%s&eventCode=%s&page=%s'  # (year, eventCode, page)
        elif version == 'v2.0':
            FMS_API_URL_BASE = self.FMS_API_DOMAIN + 'v2.0'
            self.FMS_API_AWARDS_URL_PATTERN = FMS_API_URL_BASE + '/%s/awards/%s'  # (year, event_short)
            self.FMS_API_HYBRID_SCHEDULE_QUAL_URL_PATTERN = FMS_API_URL_BASE + '/%s/schedule/%s/qual/hybrid'  # (year, event_short)
            self.FMS_API_HYBRID_SCHEDULE_PLAYOFF_URL_PATTERN = FMS_API_URL_BASE + '/%s/schedule/%s/playoff/hybrid'  # (year, event_short)
            self.FMS_API_MATCH_DETAILS_QUAL_URL_PATTERN = FMS_API_URL_BASE + '/%s/scores/%s/qual'  # (year, event_short)
            self.FMS_API_MATCH_DETAILS_PLAYOFF_URL_PATTERN = FMS_API_URL_BASE + '/%s/scores/%s/playoff'  # (year, event_short)
            self.FMS_API_EVENT_RANKINGS_URL_PATTERN = FMS_API_URL_BASE + '/%s/rankings/%s'  # (year, event_short)
            self.FMS_API_EVENT_ALLIANCES_URL_PATTERN = FMS_API_URL_BASE + '/%s/alliances/%s'  # (year, event_short)
            self.FMS_API_TEAM_DETAILS_URL_PATTERN = FMS_API_URL_BASE + '/%s/teams/?teamNumber=%s'  # (year, teamNumber)
            self.FMS_API_TEAM_AVATAR_URL_PATTERN = FMS_API_URL_BASE + '/%s/avatars/?teamNumber=%s'  # (year, teamNumber)
            self.FMS_API_EVENT_AVATAR_URL_PATTERN = FMS_API_URL_BASE + '/%s/avatars/?eventCode=%s&page=%s'  # (year, eventCode, page)
            self.FMS_API_EVENT_LIST_URL_PATTERN = FMS_API_URL_BASE + '/%s/events'  # year
            self.FMS_API_EVENT_DETAILS_URL_PATTERN = FMS_API_URL_BASE + '/%s/events?eventCode=%s'  # (year, event_short)
            self.FMS_API_EVENTTEAM_LIST_URL_PATTERN = FMS_API_URL_BASE + '/%s/teams/?eventCode=%s&page=%s'  # (year, eventCode, page)
            self.FMS_API_DISTRICT_LIST_URL_PATTERN = FMS_API_URL_BASE + '/%s/districts'  # (year)
            self.FMS_API_DISTRICT_RANKINGS_PATTERN = FMS_API_URL_BASE + '/%s/rankings/district?districtCode=%s&page=%s'  # (year, district abbreviation, page)
        else:
            raise Exception("Unknown FMS API version: {}".format(version))
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:48,代码来源:datafeed_fms_api.py


示例7: oauth_req

    def oauth_req(self, url, http_method="GET", post_body=None,
                  http_headers=None):

        twitter_secrets = Sitevar.get_by_id("twitter.secrets")
        if not twitter_secrets:
            raise Exception("Missing sitevar: twitter.secrets. Cant scrape twitter.")

        TWITTER_CONSUMER_KEY = twitter_secrets.contents['TWITTER_CONSUMER_KEY']
        TWITTER_CONSUMER_SECRET = twitter_secrets.contents['TWITTER_CONSUMER_SECRET']
        TWITTER_ACCESS_TOKEN = twitter_secrets.contents['TWITTER_ACCESS_TOKEN']
        TWITTER_ACCESS_TOKEN_SECRET = twitter_secrets.contents['TWITTER_ACCESS_TOKEN_SECRET']

        consumer = oauth2.Consumer(key=TWITTER_CONSUMER_KEY, secret=TWITTER_CONSUMER_SECRET)
        token = oauth2.Token(key=TWITTER_ACCESS_TOKEN, secret=TWITTER_ACCESS_TOKEN_SECRET)
        client = oauth2.Client(consumer, token)
     
        resp, content = client.request(
            url,
            method=http_method,
            body=post_body,
            headers=http_headers,
            force_auth_header=True
        )
        return content
        
开发者ID:dweitz,项目名称:the-blue-alliance,代码行数:24,代码来源:datafeed_twitter.py


示例8: track_call

def track_call(api_action, api_details):
    analytics_id = Sitevar.get_by_id("google_analytics.id")
    if analytics_id is None:
        logging.warning("Missing sitevar: google_analytics.id. Can't track API usage.")
    else:
        GOOGLE_ANALYTICS_ID = analytics_id.contents['GOOGLE_ANALYTICS_ID']
        params = urllib.urlencode({
            'v': 1,
            'tid': GOOGLE_ANALYTICS_ID,
            'cid': '1',
            't': 'event',
            'ec': 'api',
            'ea': api_action,
            'el': api_details,
            'ev': 1,
            'ni': 1
        })

        # Sets up the call
        analytics_url = 'http://www.google-analytics.com/collect'
        urlfetch.fetch(
            url=analytics_url,
            payload=params,
            method=urlfetch.POST,
            headers={'Content-Type': 'application/x-www-form-urlencoded'}
        )
开发者ID:linuxuser0,项目名称:the-blue-alliance,代码行数:26,代码来源:api_controller.py


示例9: _render

    def _render(self):
        status_sitevar = Sitevar.get_by_id('apistatus')
        fmsapi_sitevar = Sitevar.get_by_id('apistatus.fmsapi_down')
        down_events_sitevar = Sitevar.get_by_id('apistatus.down_events')

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

        status_dict = status_sitevar.contents
        down_events_list = down_events_sitevar.contents if down_events_sitevar else None

        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 []
        return json.dumps(status_dict, ensure_ascii=True)
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:16,代码来源:api_status_controller.py


示例10: get

    def get(self, event_key):
        self._require_admin()

        event = Event.get_by_id(event_key)
        if not event:
            self.abort(404)
        event.prepAwardsMatchesTeams()

        reg_sitevar = Sitevar.get_by_id("cmp_registration_hacks")
        api_keys = ApiAuthAccess.query(ApiAuthAccess.event_list == ndb.Key(Event, event_key)).fetch()
        event_medias = Media.query(Media.references == event.key).fetch(500)

        self.template_values.update({
            "event": event,
            "medias": event_medias,
            "cache_key": event_controller.EventDetail('2016nyny').cache_key.format(event.key_name),
            "flushed": self.request.get("flushed"),
            "playoff_types": PlayoffType.type_names,
            "write_auths": api_keys,
            "event_sync_disable": reg_sitevar and event_key in reg_sitevar.contents.get('divisions_to_skip', []),
            "set_start_day_to_last": reg_sitevar and event_key in reg_sitevar.contents.get('set_start_to_last_day', []),
            "skip_eventteams": reg_sitevar and event_key in reg_sitevar.contents.get('skip_eventteams', []),
            "event_name_override": next(iter(filter(lambda e: e.get("event") == event_key, reg_sitevar.contents.get("event_name_override", []))), {}).get("name", "")
        })

        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/event_details.html')
        self.response.out.write(template.render(path, self.template_values))
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:27,代码来源:admin_event_controller.py


示例11: track_call

def track_call(api_action, api_label, x_tba_app_id):
    """
    For more information about GAnalytics Protocol Parameters, visit
    https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
    """
    analytics_id = Sitevar.get_by_id("google_analytics.id")
    if analytics_id is None:
        logging.warning("Missing sitevar: google_analytics.id. Can't track API usage.")
    else:
        GOOGLE_ANALYTICS_ID = analytics_id.contents["GOOGLE_ANALYTICS_ID"]
        params = urllib.urlencode(
            {
                "v": 1,
                "tid": GOOGLE_ANALYTICS_ID,
                "cid": uuid.uuid3(uuid.NAMESPACE_X500, str(x_tba_app_id)),
                "t": "event",
                "ec": "api-v02",
                "ea": api_action,
                "el": api_label,
                "cd1": x_tba_app_id,  # custom dimension 1
                "ni": 1,
                "sc": "end",  # forces tracking session to end
            }
        )

        analytics_url = "http://www.google-analytics.com/collect?%s" % params
        urlfetch.fetch(url=analytics_url, method=urlfetch.GET, deadline=10)
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:27,代码来源:api_base_controller.py


示例12: _render

    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,代码行数:28,代码来源:ajax_controller.py


示例13: update_champ_numbers

    def update_champ_numbers(cls, match):
        champ_numbers_sitevar = Sitevar.get_or_insert(
            'champ_numbers',
            values_json=json.dumps({
                'kpa_accumulated': 0,
                'rotors_engaged': 0,
                'ready_for_takeoff': 0,
            }))

        old_contents = champ_numbers_sitevar.contents
        for color in ['red', 'blue']:
            old_contents['kpa_accumulated'] += match.score_breakdown[color]['autoFuelPoints'] + match.score_breakdown[color]['teleopFuelPoints']
            if match.score_breakdown[color]['rotor4Engaged']:
                old_contents['rotors_engaged'] += 4
            elif match.score_breakdown[color]['rotor3Engaged']:
                old_contents['rotors_engaged'] += 3
            elif match.score_breakdown[color]['rotor2Engaged']:
                old_contents['rotors_engaged'] += 2
            elif match.score_breakdown[color]['rotor1Engaged']:
                old_contents['rotors_engaged'] += 1
            old_contents['ready_for_takeoff'] += match.score_breakdown[color]['teleopTakeoffPoints'] / 50

        champ_numbers_sitevar.contents = old_contents
        champ_numbers_sitevar.put()

        deferred.defer(
            cls._patch_data,
            'champ_numbers',
            json.dumps(old_contents),
            _queue="firebase")
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:30,代码来源:firebase_pusher.py


示例14: post

    def post(self):
        self._require_registration()

        event_key = self.request.get("event_key")

        status, suggestion = SuggestionCreator.createEventMediaSuggestion(
            author_account_key=self.user_bundle.account.key,
            media_url=self.request.get("media_url"),
            event_key=event_key)

        if status == 'success':
            # Send an update to the FUN slack
            slack_sitevar = Sitevar.get_or_insert('slack.hookurls')
            if slack_sitevar:
                slack_url = slack_sitevar.contents.get('fun', '')
                if slack_url:
                    message_body = u"{0} ({1}) has suggested a video for <https://www.thebluealliance.com/event/{2}|{2}>: https://youtu.be/{3}.\nSee all suggestions at https://www.thebluealliance.com/suggest/event/media/review".format(
                        self.user_bundle.account.display_name,
                        self.user_bundle.account.email,
                        event_key,
                        suggestion.contents['foreign_key']).encode('utf-8')

                    OutgoingNotificationHelper.send_slack_alert(slack_url, message_body, [])

        self.redirect('/suggest/event/media?event_key=%s&status=%s' % (event_key, status))
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:25,代码来源:suggest_event_media_controller.py


示例15: track_call

def track_call(api_action, api_label, auth_owner):
    """
    For more information about GAnalytics Protocol Parameters, visit
    https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
    """
    analytics_id = Sitevar.get_by_id("google_analytics.id")
    if analytics_id is None:
        logging.warning("Missing sitevar: google_analytics.id. Can't track API usage.")
    else:
        GOOGLE_ANALYTICS_ID = analytics_id.contents['GOOGLE_ANALYTICS_ID']
        payload = urllib.urlencode({
            'v': 1,
            'tid': GOOGLE_ANALYTICS_ID,
            'cid': uuid.uuid3(uuid.NAMESPACE_X500, str(auth_owner)),
            't': 'event',
            'ec': 'api-v03',
            'ea': api_action,
            'el': api_label,
            'cd1': auth_owner,  # custom dimension 1
            'ni': 1,
            'sc': 'end',  # forces tracking session to end
        })

        urlfetch.fetch(
            url='https://www.google-analytics.com/collect',
            validate_certificate=True,
            method=urlfetch.POST,
            deadline=30,
            payload=payload,
        )
开发者ID:fangeugene,项目名称:the-blue-alliance,代码行数:30,代码来源:api_base_controller.py


示例16: __init__

    def __init__(self, version):
        fms_api_secrets = Sitevar.get_by_id('fmsapi.secrets')
        if fms_api_secrets is None:
            raise Exception("Missing sitevar: fmsapi.secrets. Can't access FMS API.")

        fms_api_username = fms_api_secrets.contents['username']
        fms_api_authkey = fms_api_secrets.contents['authkey']
        self._fms_api_authtoken = base64.b64encode('{}:{}'.format(fms_api_username, fms_api_authkey))

        if version == 'v1.0':
            FMS_API_URL_BASE = 'https://frc-api.usfirst.org/api/v1.0'
            self.FMS_API_AWARDS_URL_PATTERN = FMS_API_URL_BASE + '/awards/%s/%s'  # (year, event_short)
            self.FMS_API_HYBRID_SCHEDULE_QUAL_URL_PATTERN = FMS_API_URL_BASE + '/schedule/%s/%s/qual/hybrid'  # (year, event_short)
            self.FMS_API_HYBRID_SCHEDULE_PLAYOFF_URL_PATTERN = FMS_API_URL_BASE + '/schedule/%s/%s/playoff/hybrid'  # (year, event_short)
            self.FMS_API_EVENT_RANKINGS_URL_PATTERN = FMS_API_URL_BASE + '/rankings/%s/%s'  # (year, event_short)
            self.FMS_API_EVENT_ALLIANCES_URL_PATTERN = FMS_API_URL_BASE + '/alliances/%s/%s'  # (year, event_short)
            self.FMS_API_TEAM_DETAILS_URL_PATTERN = FMS_API_URL_BASE + '/teams/%s/?teamNumber=%s'  # (year, teamNumber)
        elif version == 'v2.0':
            FMS_API_URL_BASE = 'https://frc-api.usfirst.org/v2.0'
            self.FMS_API_AWARDS_URL_PATTERN = FMS_API_URL_BASE + '/%s/awards/%s'  # (year, event_short)
            self.FMS_API_HYBRID_SCHEDULE_QUAL_URL_PATTERN = FMS_API_URL_BASE + '/%s/schedule/%s/qual/hybrid'  # (year, event_short)
            self.FMS_API_HYBRID_SCHEDULE_PLAYOFF_URL_PATTERN = FMS_API_URL_BASE + '/%s/schedule/%s/playoff/hybrid'  # (year, event_short)
            self.FMS_API_MATCH_DETAILS_QUAL_URL_PATTERN = FMS_API_URL_BASE + '/%s/scores/%s/qual'  # (year, event_short)
            self.FMS_API_MATCH_DETAILS_PLAYOFF_URL_PATTERN = FMS_API_URL_BASE + '/%s/scores/%s/playoff'  # (year, event_short)
            self.FMS_API_EVENT_RANKINGS_URL_PATTERN = FMS_API_URL_BASE + '/%s/rankings/%s'  # (year, event_short)
            self.FMS_API_EVENT_ALLIANCES_URL_PATTERN = FMS_API_URL_BASE + '/%s/alliances/%s'  # (year, event_short)
            self.FMS_API_TEAM_DETAILS_URL_PATTERN = FMS_API_URL_BASE + '/%s/teams/?teamNumber=%s'  # (year, teamNumber)
        else:
            raise Exception("Unknown FMS API version: {}".formation(version))
开发者ID:RCB35,项目名称:the-blue-alliance,代码行数:29,代码来源:datafeed_fms_api.py


示例17: _render

    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,代码行数:27,代码来源:gameday_controller.py


示例18: _render

    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,代码行数:26,代码来源:ajax_controller.py


示例19: _update_live_events_helper

    def _update_live_events_helper(cls):
        week_events = EventHelper.getWeekEvents()
        events_by_key = {}
        live_events = []
        for event in week_events:
            if event.now:
                event._webcast = event.current_webcasts  # Only show current webcasts
                for webcast in event.webcast:
                    WebcastOnlineHelper.add_online_status_async(webcast)
                events_by_key[event.key.id()] = event
            if event.within_a_day:
                live_events.append(event)

        # To get Champ events to show up before they are actually going on
        forced_live_events = Sitevar.get_or_insert(
            'forced_live_events',
            values_json=json.dumps([]))
        for event in ndb.get_multi([ndb.Key('Event', ekey) for ekey in forced_live_events.contents]):
            if event.webcast:
                for webcast in event.webcast:
                    WebcastOnlineHelper.add_online_status_async(webcast)
            events_by_key[event.key.id()] = event

        # # Add in the Fake TBA BlueZone event (watch for circular imports)
        # from helpers.bluezone_helper import BlueZoneHelper
        # bluezone_event = BlueZoneHelper.update_bluezone(live_events)
        # if bluezone_event:
        #     for webcast in bluezone_event.webcast:
        #         WebcastOnlineHelper.add_online_status_async(webcast)
        #     events_by_key[bluezone_event.key_name] = bluezone_event

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


示例20: track_call

def track_call(api_action, api_details, x_tba_app_id):
    analytics_id = Sitevar.get_by_id("google_analytics.id")
    if analytics_id is None:
        logging.warning("Missing sitevar: google_analytics.id. Can't track API usage.")
    else:
        GOOGLE_ANALYTICS_ID = analytics_id.contents['GOOGLE_ANALYTICS_ID']
        params = urllib.urlencode({
            'v': 1,
            'tid': GOOGLE_ANALYTICS_ID,
            'cid': uuid.uuid3(uuid.NAMESPACE_X500, str(x_tba_app_id)),
            't': 'event',
            'ec': 'api',
            'ea': api_action,
            'el': api_details,
            'cd1': x_tba_app_id,  # custom dimension 1
            'ni': 1,
            'sc': 'end',  # forces tracking session to end
        })

        # Sets up the call
        analytics_url = 'http://www.google-analytics.com/collect?%s' % params
        urlfetch.fetch(
            url=analytics_url,
            method=urlfetch.GET,
            deadline=10,
        )
开发者ID:lemiant,项目名称:the-blue-alliance,代码行数:26,代码来源:api_controller.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python storage.delete函数代码示例发布时间:2022-05-27
下一篇:
Python course_metadata.CourseMetadata类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap