本文整理汇总了Python中models.sitevar.Sitevar.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Sitevar.get_by_id方法的具体用法?Python Sitevar.get_by_id怎么用?Python Sitevar.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.sitevar.Sitevar
的用法示例。
在下文中一共展示了Sitevar.get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
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))
示例2: track_call
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
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,
)
示例3: track_call
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
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,
)
示例4: get
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
def get(self):
self._require_admin()
all_clients = MobileClient.query()
android = all_clients.filter(MobileClient.client_type == ClientType.OS_ANDROID).count()
ios = all_clients.filter(MobileClient.client_type == ClientType.OS_IOS).count()
webhook = all_clients.filter(MobileClient.client_type == ClientType.WEBHOOK).count()
var = Sitevar.get_by_id('notifications.enable')
if var is None or not var.values_json == "true":
push_enabled = False
else:
push_enabled = True
self.template_values.update({
'mobile_users': all_clients.count(),
'android_users': android,
'ios_users': ios,
'webhooks': webhook,
'broadcast_success': self.request.get('broadcast_success'),
'push_enabled': push_enabled,
})
path = os.path.join(os.path.dirname(__file__), '../../templates/admin/mobile_dashboard.html')
self.response.out.write(template.render(path, self.template_values))
示例5: get
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
def get(self):
access_token = self.get_oauth_token('https://www.googleapis.com/auth/datastore')
app_id = app_identity.get_application_id()
timestamp = datetime.datetime.now().strftime('%Y-%m-%d')
backup_entities = self.get_backup_entities()
backup_bucket = self.get_backup_bucket()
output_url_prefix = "gs://{}/{}".format(backup_bucket, timestamp)
entity_filter = {
'kinds': backup_entities,
}
request = {
'project_id': app_id,
'output_url_prefix': output_url_prefix,
'entity_filter': entity_filter
}
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + access_token
}
url = 'https://datastore.googleapis.com/v1beta1/projects/%s:export' % app_id
status, _ = self.fetch_url(
url=url,
payload=json.dumps(request),
method=urlfetch.POST,
headers=headers)
status_sitevar = Sitevar.get_by_id('apistatus')
if status == 200 and status_sitevar and 'backup' in status_sitevar.contents:
status_sitevar.contents['backup']['db_export'] = timestamp
status_sitevar.put()
示例6: _render
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
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)
示例7: get
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
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))
示例8: track_call
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
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'}
)
示例9: track_call
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
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,
)
示例10: get_timezone_id
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
def get_timezone_id(cls, location, event_key):
if location is None:
logging.warning('Could not get timezone for event {} with no location!'.format(event_key))
return None
google_secrets = Sitevar.get_by_id("google.secrets")
google_api_key = None
if google_secrets is None:
logging.warning("Missing sitevar: google.api_key. API calls rate limited by IP and may be over rate limit.")
else:
google_api_key = google_secrets.contents['api_key']
# geocode request
geocode_params = {
'address': location,
'sensor': 'false',
}
if google_api_key is not None:
geocode_params['key'] = google_api_key
geocode_url = 'https://maps.googleapis.com/maps/api/geocode/json?%s' % urllib.urlencode(geocode_params)
try:
geocode_result = urlfetch.fetch(geocode_url)
except Exception, e:
logging.warning('urlfetch for geocode request failed: {}'.format(geocode_url))
logging.info(e)
return None
示例11: oauth_req
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
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
示例12: __init__
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
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))
示例13: track_call
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
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)
示例14: track_notification
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
def track_notification(self, notification_type_enum, num_keys):
"""
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('tba-notification-tracking')),
't': 'event',
'ec': 'notification',
'ea': NotificationType.type_names[notification_type_enum],
'ev': num_keys,
'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,
)
示例15: _get_max_year
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import get_by_id [as 别名]
def _get_max_year():
DEFAULT_YEAR = 2018
try:
status_sitevar = Sitevar.get_by_id('apistatus')
return status_sitevar.contents.get(
'max_season', DEFAULT_YEAR) if status_sitevar else DEFAULT_YEAR
except Exception:
return DEFAULT_YEAR