本文整理汇总了Python中models.sitevar.Sitevar.values_json方法的典型用法代码示例。如果您正苦于以下问题:Python Sitevar.values_json方法的具体用法?Python Sitevar.values_json怎么用?Python Sitevar.values_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.sitevar.Sitevar
的用法示例。
在下文中一共展示了Sitevar.values_json方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_upcoming_matches
# 需要导入模块: from models.sitevar import Sitevar [as 别名]
# 或者: from models.sitevar.Sitevar import values_json [as 别名]
def send_upcoming_matches(cls, live_events):
from helpers.match_helper import MatchHelper # PJL: Hacky :P
# Causes circular import, otherwise
# https://github.com/the-blue-alliance/the-blue-alliance/pull/1098#discussion_r25128966
down_events = []
now = datetime.datetime.utcnow()
for event in live_events:
matches = event.matches
if not matches:
continue
last_matches = MatchHelper.recentMatches(matches, num=1)
next_matches = MatchHelper.upcomingMatches(matches, num=2)
# First, compare the difference between scheduled times of next/last match
# Send an upcoming notification if it's <10 minutes, to account for events ahead of schedule
if last_matches != []:
last_match = last_matches[0]
for i, next_match in enumerate(next_matches):
if not next_match.push_sent and last_match.time and next_match.time:
diff = next_match.time - last_match.time
if diff < datetime.timedelta(minutes=10 * (i + 1)):
cls.send_upcoming_match_notification(next_match, event)
for match in next_matches:
if match and not match.push_sent:
# Only continue sending for the next match if a push hasn't already been sent for it
if match.time is None or match.time + datetime.timedelta(minutes=-7) <= now:
# Only send notifications for matches no more than 7 minutes (average-ish match cycle time) before it's scheduled to start
# Unless, the match has no time info. Then #yolo and send it
cls.send_upcoming_match_notification(match, event)
# Determine if event is down
if cls.is_event_down(last_matches[0] if last_matches else None, next_matches[0] if next_matches else None):
down_events.append(event.key_name)
# Update the status sitevar
status_sitevar = Sitevar.get_by_id('apistatus.down_events')
if status_sitevar is None:
status_sitevar = Sitevar(id="apistatus.down_events", description="A list of down event keys")
status_sitevar.values_json = json.dumps(down_events)
status_sitevar.put()