twitter-text-py is a port of twitter-text-rb, where the last release is 2014-01-16.
Note: twitter-text only officially support Java, Ruby, JavaScript and Objective-C. I didn't find a more recent implementation of twitter-text
for Python.
Install.
pip install twitter-text-py
Code.
import loggingfrom twitter_text import Autolinkstr = u'I am #hello #My World #我爱你'html = Autolink(str).auto_link_hashtags({'hashtag_url_base': '/t/', 'hashtag_class': 'hashtag'})logging.info(html)
Output.
I am <a class="hashtag" href="/t/hello" title="#hello">#hello</a> <a class="hashtag" href="/t/My" title="#My">#My</a> World <a class="hashtag" href="/t/我爱你" title="#我爱你">#我爱你</a>