예제 #1
0
파일: main.py 프로젝트: pombreda/tweetux
    def get(self):
        profile = {}
        tweets = {}
        screen_name = self.request.path.split('/')[-1]

        key_name = self.get_cookie('oauth')
        logged_in = self.is_logged_in(key_name)

        if logged_in:
            cache_id = screen_name.encode('base64')
            profile = memcache.get(cache_id)

        if not profile:
            try:
                access_token = datamodel.OAuthAccessToken.get_by_key_name(key_name)
                oauth_token = oauth.OAuthToken(access_token.oauth_token, access_token.oauth_token_secret)
                client = oauth.OAuthClient(self, SETTINGS_OAUTH_TWITTER, oauth_token)
                params = {'screen_name': screen_name}
                profile = client.get('/users/show', **params)
                memcache.set(cache_id, profile, 86400)
            except:
                # FIXME logging
                pass

        params = { 'q': 'linux', 'from': screen_name }
        tweets = twitter.search_tweets(**params)

        self.set_template_value('is_user_logged_in', logged_in)
        self.set_template_value('tweets', tweets)
        self.set_template_value('profile', profile)
        self.set_template_value('screen_name', screen_name)

        self.generate('text/html', 'profile.html')
예제 #2
0
    def get_data(self, request, topic=''):
        page = request.get('page')
        if page is '':
            page = 1
        elif not page.isnumeric():
            return False

        if topic is '':
            topic = request.get('q')
            if topic is '':
                topic = SETTINGS_TOPICS[0]
        else:
            # replace chars that can occur in screen names and searches
            check = re.sub(r'[_#:\s\+\-]', '', topic)
            if not check.isalnum():
                return False

        request_params = {'page': page, 'q': topic}
        result = twitter.search_tweets(**request_params)
        return result
예제 #3
0
파일: main.py 프로젝트: pombreda/tweetux
    def get_data(self, request, topic=''):
        page = request.get('page')
        if page is '':
            page = 1
        elif not page.isnumeric():
            return False

        if topic is '':
            topic = request.get('q')
            if topic is '':
                topic = SETTINGS_TOPICS[0]
        else:
            # replace chars that can occur in screen names and searches
            check = re.sub(r'[_#:\s\+\-]', '', topic)
            if not check.isalnum():
                return False

        request_params = {'page': page, 'q': topic}
        result = twitter.search_tweets(**request_params)
        return result
def main():
    since_id_str = read_last_id()
    # Initialize since_id
    since_id = 1
    if since_id_str.isdigit():
        since_id = int(since_id_str)
    # Initialize largest_id which will be new since_id
    largest_id = since_id
    for q in query_strings:
        tweets = search_tweets(q, since_id)
        if len(tweets) > 0:
            # Post a header
            header_template = Template(result_header_template)
            header_text = header_template.render(query=q,
                                                 num_tweets=len(tweets))
            post_message(header_text, slack_channel_id)
            max_id = post_tweets_to_slack(tweets)
            # Update largest_id when one of tweets has larger ID than the
            # current.
            if max_id > largest_id:
                largest_id = max_id

    post_message(largest_id, slack_direct_message_id)
예제 #5
0
    def get(self):
        profile = {}
        tweets = {}
        screen_name = self.request.path.split('/')[-1]

        key_name = self.get_cookie('oauth')
        logged_in = self.is_logged_in(key_name)

        if logged_in:
            cache_id = screen_name.encode('base64')
            profile = memcache.get(cache_id)

        if not profile:
            try:
                access_token = datamodel.OAuthAccessToken.get_by_key_name(
                    key_name)
                oauth_token = oauth.OAuthToken(access_token.oauth_token,
                                               access_token.oauth_token_secret)
                client = oauth.OAuthClient(self, SETTINGS_OAUTH_TWITTER,
                                           oauth_token)
                params = {'screen_name': screen_name}
                profile = client.get('/users/show', **params)
                memcache.set(cache_id, profile, 86400)
            except:
                # FIXME logging
                pass

        params = {'q': 'linux', 'from': screen_name}
        tweets = twitter.search_tweets(**params)

        self.set_template_value('is_user_logged_in', logged_in)
        self.set_template_value('tweets', tweets)
        self.set_template_value('profile', profile)
        self.set_template_value('screen_name', screen_name)

        self.generate('text/html', 'profile.html')