twitter.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:v2ex-tornado-2 作者: coderyy 项目源码 文件源码
def ExpandBitly(self, text):
    if os.environ['HTTP_HOST'].find('localhost') == -1:
      p = re.compile('http:\/\/bit\.ly/[a-zA-Z0-9]+')
      m = p.findall(text)
      if len(m) > 0:
        api = bitly.Api(login='livid', apikey='R_40ab00809faf431d53cfdacc8d8b8d7f')
        last = None
        for s in m:
          if s != last:
            cache_tag = 'bitly_' + hashlib.md5(s).hexdigest()
            expanded = memcache.get(cache_tag)
            if expanded is None:
              expanded = api.expand(s)
              memcache.set(cache_tag, expanded, 2678400)
            last = s
            text = text.replace(s, expanded)
    return text
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号