def run(*args): # Stops execution after runtime seconds if specified if args: signal.signal(signal.SIGALRM, lambda signum, frame: sys.exit(0)) signal.alarm(args[0]) games = schedule.games_today() team_abbrs_today = games.home_abbr.tolist() + games.away_abbr.tolist() team_terms_today = {team_abbr: ' '.join([schedule.teams_dict[team_abbr]] + twitter.hashtags_dict[team_abbr]) for team_abbr in team_abbrs_today} for tweet in queue.consume(): # Determine which team(s) and game(s) the tweet should be associated with similarities = tweet_to_team(tweet['text'], team_terms_today) relevant_teams = [team for team, similarity in similarities.iteritems() if similarity != 0.] relevant_game_ids = {} for team in relevant_teams: # Get the game the team is playing in game_id = games[(games.home_abbr == team) | (games.away_abbr == team)].index.tolist()[0] if game_id in relevant_game_ids: relevant_game_ids[game_id].append(team) else: relevant_game_ids[game_id] = [team] if relevant_game_ids: for relevant_game_id, teams in relevant_game_ids.iteritems(): if schedule.game_on(games.loc[relevant_game_id]): # update_tweets(relevant_game_id, teams, tweet) update_sentiment(relevant_game_id, teams, tweet)
def update_all_plays(sc): [update_plays(season_id, game_id) for game_id in games.index if schedule.game_on(games.ix[game_id])] sc.enter(60, 1, update_all_plays, (sc,))