コード例 #1
0
ファイル: twitter.py プロジェクト: raqqun/tweetcommander
    def post_tweets(self, tweet):
        url = 'https://api.twitter.com/1.1/statuses/update.json'

        tweet = {
            'status': tweet
        }

        credentials = oauth.connection()

        requests.post(url, auth=credentials, params=tweet)
コード例 #2
0
ファイル: twitter.py プロジェクト: raqqun/tweetcommander
    def retweet(self, retweet):

        index = len(self.timeline[int(retweet[0])-1])

        url = ('https://api.twitter.com/1.1/statuses/retweet/' +
               self.timeline[int(retweet[0])-1][index-int(retweet[2:])]['id_str'] + '.json'
        )

        credentials = oauth.connection()
        retweet = requests.post(url, auth=credentials)
コード例 #3
0
ファイル: twitter.py プロジェクト: raqqun/tweetcommander
    def favorite(self, *args):
        url = 'https://api.twitter.com/1.1/favorites/create.json'

        index = len(self.timeline[int(args[0][0])-1])

        fav = {
            'id': self.timeline[int(args[0][0])-1][index-int(args[0][1])]['id_str']
        }

        credentials = oauth.connection()

        favorite = requests.post(url, auth=credentials, params=fav)
コード例 #4
0
ファイル: twitter.py プロジェクト: raqqun/tweetcommander
    def get_timeline(self, url, url_params):
        ents = HTMLParser.HTMLParser()
        tweet_id = 0

        credentials = oauth.connection()
        twitter_request = requests.get(url, auth=credentials, params=url_params)

        if twitter_request.json() and twitter_request.status_code == 200:
            ref = self.page
            self.page += 1
            self.timeline.append(twitter_request.json())
            self.since_id = self.timeline[ref][0]['id_str']

            for i in range(len(self.timeline[ref])-1, -1, -1):

                tweet_id += 1

                try:
                    text = ents.unescape(self.timeline[ref][i]['retweeted_status']['text'])
                    print '%d %d %s from %s' % (
                        self.page, tweet_id,
                        colored.green('@' + self.timeline[ref][i]['user']['screen_name']),
                        colored.red('@' + self.timeline[ref][i]['retweeted_status']['user']['screen_name'])
                    )
                    print colored.yellow(text)
                    print ''
                except KeyError:
                    text = ents.unescape(self.timeline[ref][i]['text'])
                    print '%d %d %s' % (
                        self.page, tweet_id,
                        colored.green('@' + self.timeline[ref][i]['user']['screen_name'])
                    )
                    print colored.yellow(text)
                    print ''
        else:
            print colored.red('Theres no new tweets at the moment !!!')