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))
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))
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))
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))
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')
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')
class MatchManipulator(ManipulatorBase): """ Handle Match database writes. """ @classmethod def getCacheKeysAndControllers(cls, affected_refs): return CacheClearer.get_match_cache_keys_and_controllers(affected_refs) @classmethod 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: NotificationHelper.send_match_score_update(match) except Exception, 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')