Example #1
0
def get_current_series_games(team_nickname, team_key):
    game_dates = get_game_dates(team_nickname)
    series_opponent = None
    series_games = []

    for game_date in game_dates[::-1][0:10]:
        scoreboard = get_scoreboard(game_date)
        games = scoreboard.get(settings.data['games_tree'])
        home_team_key = 'home.team_key'
        visitor_team_key = 'visitor.team_key'
        team_key = team_key
        for game_dict in games:
            game = dotdictify(game_dict)
            if team_key in [game[home_team_key], game[visitor_team_key]]:
                if team_key == game.get(home_team_key):
                    this_opponent = game[visitor_team_key]
                else:
                    this_opponent = game[home_team_key]

                if series_opponent is None:
                    series_opponent = this_opponent

                if this_opponent == series_opponent and 'playoffs' in game:
                    series_games.append(game)

                break
    return series_games[::-1]
    def process(self, data):
        """Processes every status/event coming in through streaming API
        """
        # Convert tweet to pythonic form
        status = utils.dotdictify(data)

        for ext_name in self.extensions:
            extension = self.extensions[ext_name]
            if 'text' in status:
                if '@'+self.settings.username in status.text:
                    if (hasattr(extension, 'process_mention') and
                        callable(getattr(extension, 'process_mention'))):
                        result = extension.process_mention(status,
                                                      settings=self.settings)
                        if result:
                            self.process_response(result, status)

                elif (hasattr(extension, 'process_status') and
                    callable(getattr(extension, 'process_status'))):
                    result = extension.process_status(status,
                                                  settings=self.settings)
                    if result:
                        self.process_response(result, status)


            if 'direct_message' in status:
                if (hasattr(extension, 'process_dm') and
                    callable(getattr(extension, 'process_dm'))):
                    result = extension.process_dm(status,
                                                  settings=self.settings)
                    if result:
                        self.process_response(result, status)

            if ('event' in status and 'follow' in status.event and
                self.settings.username == status.target.screen_name):
                if (hasattr(extension, 'process_follow') and
                    callable(getattr(extension, 'process_follow'))):
                    result = extension.process_follow(status,
                                                  settings=self.settings)
                    if result:
                        self.process_response(result, status)
    def process_response(self, result, status):
        """Processes response from extensions."""
        result = utils.dotdictify(result)
        # Wrap twitter's various methods to return screen_name
        if 'direct_message' in status:
            screen_name = status.direct_message.sender_screen_name
        elif 'text' in status:
            screen_name = status.user.screen_name
        elif 'event' in status:
            screen_name = status.source.screen_name
        else:
            screen_name = ''

        if 'response' in result:
            self.post(result.response,
                      status.id,
                      screen_name)

        if 'post' in result:
            self.post(result.post)

        if 'dm' in result:
            self.post(u'd %s %s' %(screen_name,
                                  result.dm))

        if 'follow' in result:
            # follow user
            self.follow(screen_name, follow=True)

        if 'unfollow' in result:
            # unfollow user
            self.follow(screen_name, follow=False)

        if 'delete_dm' in result:
            self.delete_dm(status.direct_message.id)

        if 'force_unfollow' in result:
            self.force_unfollow(screen_name)
Example #4
0
def get_scoreboard(date):
    url = settings.data['scoreboard_url'].format(date=date)
    return dotdictify(json.loads(urllib2.urlopen(url, timeout=2).read()))