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


Python Twitter.truncate方法代码示例

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


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

示例1: main

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import truncate [as 别名]
def main():
    '''
    app entry point
    '''
    # gets a twitter object
    tw = Twitter(TWITTER['CONSUMER_KEY'], TWITTER['CONSUMER_SECRET'], \
        TWITTER['ACCESS_TOKEN'], TWITTER['ACCESS_TOKEN_SECRET'])
    # gets a bitly object
    bl = Bitly(BITLY['USER'], BITLY['APIKEY'])

    # tries to load the history from the file. If an exception is raised,
    # istantiates an empty dictionary object
    try:
        with open(HISTORY_FILE, 'rb') as history_file:
            history = pickle.load(history_file)
    except:
        history = dict()

    # cycles through the RSSs defined in settings
    for rsskey, rssvalue in RSS.iteritems():
        # gets a feed object
        fd = Feeds(rssvalue['RSS'])
        # tries to load last timestamp. If an exception is raised,
        # initializes it with the init value defined in settings
        try:
            last_timestamp = history[rsskey]
        except:
            last_timestamp = (rssvalue['HISTORY'])['INIT_VALUE']
            history[rsskey] = last_timestamp
        # gets the updated feeds
        entries = fd.get_updated_feeds(rssvalue['HISTORY'], last_timestamp)
        # cycles through the feeds, tweetin them
        for feed in entries:
            link = bl.shorten_url(getattr(feed, rssvalue['LINK']))
            tweet = getattr(feed, rssvalue['TEXT'])
            length = TWITTER['TWEET_LENGTH'] - len(rssvalue['HASHTAG']) \
                     - len(link) - 10
            tweet = rssvalue['HASHTAG'] + ' ' + tw.truncate(tweet, length) \
                    + ' ' + link
            tw.update_status(tweet, DEBUG)
        # updates the last timestamp
        history[rsskey] = fd.get_last_timestamp()
    # saves the history
    with open(HISTORY_FILE, 'wb') as history_file:
        pickle.dump(history, history_file)
    sys.exit(0)
开发者ID:hohenstaufen,项目名称:tweetyourRSS,代码行数:48,代码来源:tweetyourRSS.py


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