当前位置: 首页>>代码示例>>Python>>正文


Python API.trends_available方法代码示例

本文整理汇总了Python中tweepy.API.trends_available方法的典型用法代码示例。如果您正苦于以下问题:Python API.trends_available方法的具体用法?Python API.trends_available怎么用?Python API.trends_available使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tweepy.API的用法示例。


在下文中一共展示了API.trends_available方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TwitterTrends

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import trends_available [as 别名]
class TwitterTrends(object):
    def __init__(self):
        auth = OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
        self.api = API(auth)

    def get_trends(self):
        return self.api.trends_available()
开发者ID:wallarelvo,项目名称:streamy,代码行数:10,代码来源:streaming.py

示例2: Twitter

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import trends_available [as 别名]
class Twitter(object):
    """A class that does all interactions with twitter."""
    def __init__(self, storage_dir=False, db=False):
        """Initialise the API."""
        if not db and not storage_dir:
            raise TypeError(
                "Twitter() needs either a storage_dir or a db argument."
            )

        if not db:
            db = DB(storage_dir)
        self.db = db
        ck = self.db.get_config('consumer_key')
        cs = self.db.get_config('consumer_secret')
        at = self.db.get_config('access_token')
        ats = self.db.get_config('access_token_secret')
        mf = wtModelFactory()
        pr = ModelParser(model_factory=mf)
        self.auth = OAuthHandler(ck, cs)
        self.auth.set_access_token(at, ats)
        self.api = API(self.auth, parser=pr)
        try:
            self.api.me().name
        except TweepError as error:
            raise TwitterError("Could not connect to Twitter: %s" % error)
        except TypeError as error:
            raise TwitterError("Your keys haven't been set correctly!")

    def update_status(self, message, reply_id=False):
        """Posts text to twitter."""
        if self.__is_sane(message):
            try:
                self.api.update_status(status=message, in_reply_to_status_id=reply_id)
            except TweepError as error:
                raise TwitterError("Failed to post status: %s" % error)
            return "Status updated."
        else:
            raise TwitterError("Status too long!")

    def get_tweet(self, identification):
        """Return a tweet from either an integer or cached screen name."""
        tid = False
        try:
            int(identification)
            tid = identification
        except ValueError:
            identification = identification.lstrip("@")
            tid = self.db.get_last_tid(identification)
            if not tid:
                raise TwitterError("ID %s not cached." % identification)
        try:
            return self.api.get_status(tid, include_entities=True)
        except TweepError as error:
            raise TwitterError("Failed to get tweet: %s" % error)

    def get_user(self, user):
        """Returns the requested user."""
        try:
            user = self.api.get_user(user, include_entities=True)
        except TweepError as error:
            raise TwitterError("Failed to get user: %s" % error)
        return user

    def get_followed(self):
        """Returns an array of screen_names that you follow."""
        try:
            followed = []
            for user in Cursor(self.api.friends).items(200):
                followed.append(user.screen_name)
        except TweepError as error:
            raise TwitterError("Faled to get followed: %s" % error)
        return followed

    def get_trend_places(self):
        """
        Returns a dict of dicts, first by country then by place.
        Every country has a special 'woeid' key that holds the woeid of the
        country itself and all the places of the country pointing to their
        respective woeids.
        A special exception is the 'Worldwide' "country" which only has a
        woeid entry.
        """
        try:
            trend_places = self.api.trends_available()
        except TweepError as error:
            raise TwitterError("Falied to get available places: %s." % error)

        places = defaultdict(dict)
        for place in trend_places:
            if not place['country']:
                places['Worldwide'] = {'woeid': place['woeid']}
            else:
                if place['country'] == place['name']:
                    places[place['country']]['woeid'] = place['woeid']
                else:
                    places[place['country']][place['name']] = place['woeid']
        return places

    def get_trends(self, woeid):
        """
#.........这里部分代码省略.........
开发者ID:ainmosni,项目名称:weetwit,代码行数:103,代码来源:twitter.py


注:本文中的tweepy.API.trends_available方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。