本文整理汇总了Python中helpers.firebase.firebase_pusher.FirebasePusher类的典型用法代码示例。如果您正苦于以下问题:Python FirebasePusher类的具体用法?Python FirebasePusher怎么用?Python FirebasePusher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FirebasePusher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
self._require_admin()
event_key = self.request.get('event_key')
matches_csv = self.request.get('matches_csv')
matches = OffseasonMatchesParser.parse(matches_csv)
event = Event.get_by_id(event_key)
matches = [Match(
id=Match.renderKeyName(
event.key.id(),
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event=event.key,
game=Match.FRC_GAMES_BY_YEAR.get(event.year, "frc_unknown"),
set_number=match.get("set_number", 0),
match_number=match.get("match_number", 0),
comp_level=match.get("comp_level", None),
team_key_names=match.get("team_key_names", None),
alliances_json=match.get("alliances_json", None)
)
for match in matches]
try:
FirebasePusher.updated_event(event.key_name)
except:
logging.warning("Enqueuing Firebase push failed!")
self.redirect('/admin/event/{}'.format(event_key))
示例2: get
def get(self, event_key):
df = DatafeedUsfirst()
event = Event.get_by_id(event_key)
new_matches = MatchManipulator.createOrUpdate(df.getMatches(event))
if new_matches:
for match in new_matches:
if hasattr(match, 'dirty') and match.dirty:
# Enqueue push notification
try:
FirebasePusher.updated_event(event.key_name)
except:
logging.warning("Enqueuing Firebase push failed!")
# Enqueue task to calculate matchstats
taskqueue.add(
url='/tasks/math/do/event_matchstats/' + event.key_name,
method='GET')
break
template_values = {
'matches': new_matches,
}
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_matches_get.html')
self.response.out.write(template.render(path, template_values))
示例3: post
def post(self):
self._require_admin()
event_key = self.request.get('event_key')
matches_csv = self.request.get('matches_csv')
matches = OffseasonMatchesParser.parse(matches_csv)
event = Event.get_by_id(event_key)
matches = [Match(
id=Match.renderKeyName(
event.key.id(),
match.get("comp_level", None),
match.get("set_number", 0),
match.get("match_number", 0)),
event=event.key,
game=Match.FRC_GAMES_BY_YEAR.get(event.year, "frc_unknown"),
set_number=match.get("set_number", 0),
match_number=match.get("match_number", 0),
comp_level=match.get("comp_level", None),
team_key_names=match.get("team_key_names", None),
alliances_json=match.get("alliances_json", None)
)
for match in matches]
new_matches = MatchManipulator.createOrUpdate(matches)
try:
last_matches = MatchHelper.recentMatches(new_matches, 1)
upcoming_matches = MatchHelper.upcomingMatches(new_matches, 8)
except:
logging.warning("Computing last/upcoming matches for Firebase failed!")
try:
FirebasePusher.updateEvent(event, last_matches, upcoming_matches)
except:
logging.warning("Enqueuing Firebase push failed!")
self.redirect('/admin/event/{}'.format(event_key))
示例4: postUpdateHook
def postUpdateHook(cls, matches):
'''
To run after the match has been updated.
Send push notifications to subscribed users
Only if the match is part of an active event
'''
for match in matches:
if match.event.get().now:
logging.info("Sending push notifications for "+match.key_name)
try:
GCMMessageHelper.send_match_score_update(match)
except exception:
logging.error("Error sending match updates: "+str(exception))
'''
Enqueue firebase push
'''
if matches:
event_key = matches[0].event.id()
try:
FirebasePusher.updated_event(event_key)
except Exception:
logging.warning("Enqueuing Firebase push failed!")
# Enqueue task to calculate matchstats
taskqueue.add(
url='/tasks/math/do/event_matchstats/' + event_key,
method='GET')
示例5: postDeleteHook
def postDeleteHook(cls, matches):
'''
To run after the match has been deleted.
'''
for match in matches:
try:
FirebasePusher.delete_match(match)
except Exception:
logging.warning("Enqueuing Firebase delete failed!")
示例6: send
def send(self, keys, push_firebase=True, track_call=True):
self.keys = keys # dict like {ClientType : [ key ] } ... The list for webhooks is a tuple of (key, secret)
deferred.defer(self.render, self._supported_clients, _queue="push-notifications")
if self._push_firebase and push_firebase:
FirebasePusher.push_notification(self)
if self._track_call and track_call:
num_keys = 0
for v in keys.values():
# Count the number of clients receiving the notification
num_keys += len(v)
deferred.defer(self.track_notification, self._type, num_keys, _queue="api-track-call")
示例7: get
def get(self, event_key):
event = Event.get_by_id(event_key)
event_teams = EventTeam.query(EventTeam.event==event.key).fetch()
for event_team in event_teams:
status = EventTeamStatusHelper.generate_team_at_event_status(event_team.team.id(), event)
event_team.status = status
FirebasePusher.update_event_team_status(event_key, event_team.team.id(), status)
EventTeamManipulator.createOrUpdate(event_teams)
if 'X-Appengine-Taskname' not in self.request.headers: # Only write out if not in taskqueue
self.response.out.write("Finished calculating event team statuses for: {}".format(event_key))
示例8: updateMerge
def updateMerge(self, new_match, old_match):
"""
Given an "old" and a "new" Match object, replace the fields in the
"old" team that are present in the "new" team, but keep fields from
the "old" team that are null in the "new" team.
"""
immutable_attrs = [
"comp_level",
"event",
"set_number",
"match_number",
] # These build key_name, and cannot be changed without deleting the model.
attrs = [
"alliances_json",
"game",
"no_auto_update",
"time",
"time_string",
]
list_attrs = [
"team_key_names",
"tba_videos",
"youtube_videos"
]
push_match = not old_match.has_been_played and new_match.has_been_played
for attr in attrs:
if getattr(new_match, attr) is not None:
if getattr(new_match, attr) != getattr(old_match, attr):
setattr(old_match, attr, getattr(new_match, attr))
if attr == 'alliances_json':
# Necessary since 'alliances' doesn't get changed
# when mutating 'alliances_json'
old_match.clearAlliances()
old_match.dirty = True
for attr in list_attrs:
if len(getattr(new_match, attr)) > 0:
if getattr(new_match, attr) != getattr(old_match, attr):
setattr(new_match, attr, getattr(new_match, attr))
old_match.dirty = True
if push_match:
try:
FirebasePusher.pushMatch(old_match)
except:
logging.warning("Enqueuing Firebase push failed!")
return old_match
示例9: flush
def flush(self):
flushed = []
flushed.append(MainChampsHandler().memcacheFlush())
flushed.append(MainCompetitionseasonHandler().memcacheFlush())
flushed.append(MainOffseasonHandler().memcacheFlush())
flushed.append(MainInsightsHandler().memcacheFlush())
flushed.append(GamedayHandler().memcacheFlush())
flushed.append(Gameday2Controller().memcacheFlush())
flushed.append(WebcastsHandler().memcacheFlush())
flushed.append(EventList().memcacheFlush())
FirebasePusher.update_live_events()
return flushed
示例10: postUpdateHook
def postUpdateHook(cls, matches):
"""
To run after models have been updated
"""
if matches:
event_key = matches[0].event.id()
try:
FirebasePusher.updated_event(event_key)
except Exception:
logging.warning("Enqueuing Firebase push failed!")
# Enqueue task to calculate matchstats
taskqueue.add(
url='/tasks/math/do/event_matchstats/' + event_key,
method='GET')
示例11: _render
def _render(self, *args, **kw):
week_events = EventHelper.getWeekEvents()
popular_teams_events = TeamHelper.getPopularTeamsEvents(week_events)
# Only show special webcasts that aren't also hosting an event
special_webcasts = []
for special_webcast in FirebasePusher.get_special_webcasts():
add = True
for event in week_events:
if event.now and event.webcast:
for event_webcast in event.webcast:
if (special_webcast.get('type', '') == event_webcast.get('type', '') and
special_webcast.get('channel', '') == event_webcast.get('channel', '') and
special_webcast.get('file', '') == event_webcast.get('file', '')):
add = False
break
if not add:
break
if add:
special_webcasts.append(special_webcast)
self.template_values.update({
"events": week_events,
"any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts),
"special_webcasts": special_webcasts,
"popular_teams_events": popular_teams_events,
})
path = os.path.join(os.path.dirname(__file__), '../templates/index_competitionseason.html')
return template.render(path, self.template_values)
示例12: _render
def _render(self, *args, **kw):
week_events = EventHelper.getWeekEvents()
special_webcasts = FirebasePusher.get_special_webcasts()
self.template_values.update({
"events": week_events,
"any_webcast_online": any(w.get('status') == 'online' for w in special_webcasts),
"special_webcasts": special_webcasts,
})
path = os.path.join(os.path.dirname(__file__), '../templates/index_competitionseason.html')
return template.render(path, self.template_values)
示例13: get
def get(self, event_key):
df = DatafeedUsfirst()
event = Event.get_by_id(event_key)
new_matches = MatchManipulator.createOrUpdate(df.getMatches(event))
try:
last_matches = MatchHelper.recentMatches(new_matches, 1)
upcoming_matches = MatchHelper.upcomingMatches(new_matches, 8)
except:
logging.warning("Computing last/upcoming matches for Firebase failed!")
try:
FirebasePusher.updateEvent(event, last_matches, upcoming_matches)
except:
logging.warning("Enqueuing Firebase push failed!")
template_values = {
'matches': new_matches,
}
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_matches_get.html')
self.response.out.write(template.render(path, template_values))
示例14: postUpdateHook
def postUpdateHook(cls, event_details_list, updated_attr_list, is_new_list):
"""
To run after models have been updated
"""
for (event_details, updated_attrs) in zip(event_details_list, updated_attr_list):
event = Event.get_by_id(event_details.key.id())
try:
if event.within_a_day and "alliance_selections" in updated_attrs:
# Send updated alliances notification
logging.info("Sending alliance notifications for {}".format(event.key_name))
NotificationHelper.send_alliance_update(event)
except Exception:
logging.error("Error sending alliance update notification for {}".format(event.key_name))
logging.error(traceback.format_exc())
# Enqueue task to calculate district points
try:
taskqueue.add(
url='/tasks/math/do/district_points_calc/{}'.format(event.key.id()),
method='GET')
except Exception:
logging.error("Error enqueuing district_points_calc for {}".format(event.key.id()))
logging.error(traceback.format_exc())
# Enqueue task to calculate event team status
try:
taskqueue.add(
url='/tasks/math/do/event_team_status/{}'.format(event.key.id()),
method='GET')
except Exception:
logging.error("Error enqueuing event_team_status for {}".format(event.key.id()))
logging.error(traceback.format_exc())
try:
FirebasePusher.update_event_details(event_details)
except Exception:
logging.warning("Firebase update_event_details failed!")
示例15: update_bluezone
#.........这里部分代码省略.........
if current_match and not current_match.has_been_played and now < cutoff_time \
and current_match_key not in blacklisted_match_keys \
and current_match.event_key_name not in blacklisted_event_keys:
logging.info("[BLUEZONE] Keeping current match {}".format(current_match.key.id()))
to_log += "[BLUEZONE] Keeping current match {}\n".format(current_match.key.id())
bluezone_matches.append(current_match)
for match in potential_matches:
if len(bluezone_matches) >= 2: # one current, one future
break
logging.info("[BLUEZONE] Trying potential match: {}".format(match.key.id()))
to_log += "[BLUEZONE] Trying potential match: {}\n".format(match.key.id())
if filter(lambda m: m.key.id() == match.key.id(), bluezone_matches):
logging.info("[BLUEZONE] Match {} already chosen".format(match.key.id()))
to_log += "[BLUEZONE] Match {} already chosen\n".format(match.key.id())
continue
if match.event_key_name in blacklisted_event_keys:
logging.info("[BLUEZONE] Event {} is blacklisted, skipping...".format(match.event_key_name))
to_log += "[BLUEZONE] Event {} is blacklisted, skipping...\n".format(match.event_key_name)
continue
if match.key.id() not in blacklisted_match_keys:
if match.key.id() == current_match_key:
if current_match_predicted_time and cutoff_time < now and len(potential_matches) > 1:
# We've been on this match too long
new_blacklisted_match_keys.add(match.key.id())
logging.info("[BLUEZONE] Adding match to blacklist: {}".format(match.key.id()))
to_log += "[BLUEZONE] Adding match to blacklist: {}\n".format(match.key.id())
logging.info("[BLUEZONE] scheduled time: {}, now: {}".format(current_match_predicted_time, now))
to_log += "[BLUEZONE] scheduled time: {}, now: {}\n".format(current_match_predicted_time, now)
OutgoingNotificationHelper.send_slack_alert(slack_url, "Blacklisting match {}. Predicted time: {}, now: {}".format(match.key.id(), current_match_predicted_time, now))
else:
# We can continue to use this match
bluezone_matches.append(match)
logging.info("[BLUEZONE] Continuing to use match: {}".format(match.key.id()))
to_log += "[BLUEZONE] Continuing to use match: {}\n".format(match.key.id())
else:
# Found a new good match
bluezone_matches.append(match)
logging.info("[BLUEZONE] Found a good new match: {}".format(match.key.id()))
to_log += "[BLUEZONE] Found a good new match: {}\n".format(match.key.id())
else:
logging.info("[BLUEZONE] Match already blacklisted: {}".format(match.key.id()))
to_log += "[BLUEZONE] Match already blacklisted: {}\n".format(match.key.id())
new_blacklisted_match_keys.add(match.key.id())
if not bluezone_matches:
logging.info("[BLUEZONE] No match selected")
to_log += "[BLUEZONE] No match selected\n"
logging.info("[BLUEZONE] All selected matches: {}".format([m.key.id() for m in bluezone_matches]))
to_log += "[BLUEZONE] All selected matches: {}\n".format([m.key.id() for m in bluezone_matches])
# (3) Switch to hottest match
fake_event = cls.build_fake_event()
if bluezone_matches:
bluezone_match = bluezone_matches[0]
real_event = filter(lambda x: x.key_name == bluezone_match.event_key_name, live_events)[0]
# Create Fake event for return
fake_event.webcast_json = json.dumps([real_event.current_webcasts[0]])
if bluezone_match.key_name != current_match_key:
current_match_switch_time = now
logging.info("[BLUEZONE] Switching to: {}".format(bluezone_match.key.id()))
to_log += "[BLUEZONE] Switching to: {}\n".format(bluezone_match.key.id())
OutgoingNotificationHelper.send_slack_alert(slack_url, "It is now {}. Switching BlueZone to {}, scheduled for {} and predicted to be at {}.".format(now, bluezone_match.key.id(), bluezone_match.time, bluezone_match.predicted_time))
if not current_match or current_match.has_been_played:
last_match = current_match
# Only need to update if things changed
if bluezone_match.key_name != current_match_key or new_blacklisted_match_keys != blacklisted_match_keys:
FirebasePusher.update_event(fake_event)
bluezone_config.contents = {
'current_match': bluezone_match.key.id(),
'last_match': last_match.key.id() if last_match else '',
'current_match_predicted': bluezone_match.predicted_time.strftime(cls.TIME_PATTERN),
'blacklisted_matches': list(new_blacklisted_match_keys),
'blacklisted_events': list(blacklisted_event_keys),
'current_match_switch_time': current_match_switch_time.strftime(cls.TIME_PATTERN),
}
bluezone_config.put()
# Log to cloudstorage
log_dir = '/tbatv-prod-hrd.appspot.com/tba-logging/'
log_file = 'bluezone_{}.txt'.format(now.date())
full_path = log_dir + log_file
existing_contents = ''
if full_path in set([f.filename for f in cloudstorage.listbucket(log_dir)]):
with cloudstorage.open(full_path, 'r') as existing_file:
existing_contents = existing_file.read()
with cloudstorage.open(full_path, 'w') as new_file:
new_file.write(existing_contents + to_log)
bluezone_matches.insert(0, last_match)
bluezone_matches = filter(lambda m: m is not None, bluezone_matches)
FirebasePusher.replace_event_matches('bluezone', bluezone_matches)
return fake_event