|
| 1 | +twitter-text-python |
| 2 | +=================== |
| 3 | + |
| 4 | +**twitter-text-python** is a Tweet parser and formatter for Python. Extract |
| 5 | +users, hashtags, URLs and format as HTML for display. |
| 6 | + |
| 7 | +PyPI release: [https://pypi.python.org/pypi/twitter-text-python/](http://pypi.python.org/pypi/twitter-text-python/) |
| 8 | + |
| 9 | + |
| 10 | +installation |
| 11 | +------------ |
| 12 | + |
| 13 | + $ pip install twitter-text-python |
| 14 | + |
| 15 | + |
| 16 | +usage |
| 17 | +----- |
| 18 | + |
| 19 | + >>> from ttp import ttp |
| 20 | + >>> p = ttp.Parser() |
| 21 | + >>> result = p.parse("@burnettedmond, you now support #IvoWertzel's tweet parser! https://github.com/edburnett/") |
| 22 | + >>> result.reply |
| 23 | + 'burnettedmond' |
| 24 | + >>> result.users |
| 25 | + ['burnettedmond'] |
| 26 | + >>> result.tags |
| 27 | + ['IvoWertzel'] |
| 28 | + >>> result.urls |
| 29 | + ['https://github.com/burnettedmond/'] |
| 30 | + >>> result.html |
| 31 | + u'<a href="http://twitter.com/burnettedmond">@burnettedmond</a>, you now support <a href="https://twitter.com/search?q=%23IvoWertzel">#IvoWertzel</a>\'s tweet parser! <a href="https://github.com/edburnett/">https://github.com/edburnett/</a>' |
| 32 | + |
| 33 | +If you need different HTML output just subclass and override the `format_*` methods. |
| 34 | + |
| 35 | +You can also ask for the span tags to be returned for each entity: |
| 36 | + |
| 37 | + >>> p = ttp.Parser(include_spans=True) |
| 38 | + >>> result = p.parse("@burnettedmond, you now support #IvoWertzel's tweet parser! https://github.com/edburnett/") |
| 39 | + >>> result.urls |
| 40 | + [('https://github.com/burnettedmond/', (57, 87))] |
| 41 | + |
| 42 | + |
| 43 | +To use the shortlink follower |
| 44 | + |
| 45 | + >>> from ttp import utils |
| 46 | + >>> # assume that result.urls == ['http://t.co/8o0z9BbEMu', u'http://bbc.in/16dClPF'] |
| 47 | + >>> print utils.follow_shortlinks(result.urls) # pass in list of shortlink URLs |
| 48 | + {'http://t.co/8o0z9BbEMu': [u'http://t.co/8o0z9BbEMu', u'http://bbc.in/16dClPF', u'http://www.bbc.co.uk/sport/0/21711199#TWEET650562'], u'http://bbc.in/16dClPF': [u'http://bbc.in/16dClPF', u'http://www.bbc.co.uk/sport/0/21711199#TWEET650562']} |
| 49 | + >>> # note that bad shortlink URLs have a key to an empty list (lost/forgotten shortlink URLs don't generate any error) |
| 50 | + |
| 51 | + |
| 52 | +changelog |
| 53 | +--------- |
| 54 | + |
| 55 | +* 2014/7/30 1.0.3 Update parsed URLs for Twitter API 1.1 compatibility |
| 56 | +* 2013/6/1 1.0.1 new working version, adding comma parse fix (thanks https://github.com/muckrack), used autopep8 to clean the src, added a shortlink expander |
| 57 | +* 2013/2/11 1.0.0.2 released to PyPI |
| 58 | + |
| 59 | + |
| 60 | +tests |
| 61 | +----- |
| 62 | + |
| 63 | +Checkout the code via github https://github.com/edburnett/twitter-text-python and run tests locally:: |
| 64 | + |
| 65 | + $ python ttp/tests.py |
| 66 | + .................................................................................................... |
| 67 | + ---------------------------------------------------------------------- |
| 68 | + Ran 100 tests in 0.009s |
| 69 | + OK |
| 70 | + |
| 71 | + |
| 72 | +contributing |
| 73 | +------------ |
| 74 | + |
| 75 | +The source is available on |
| 76 | +[https://github.com/edburnett/twitter-text-python](GitHub), to contribute to |
| 77 | +the project, fork it on GitHub and send a pull request. Everyone is welcome to |
| 78 | +make improvements to **twitter-text-python**! |
| 79 | + |
| 80 | +https://github.com/edburnett/twitter-text-python |
| 81 | + |
| 82 | + |
| 83 | +history |
| 84 | +------- |
| 85 | + |
| 86 | +The current version was forked by Edmond Burnett in July 2014: |
| 87 | +https://github.com/edburnett/twitter-text-python |
| 88 | + |
| 89 | +The library was forked by Ian Ozsvald in January 2013 and released to PyPI, some bugs were fixed, a few minor changes to functionality added (no longer supported): |
| 90 | +https://github.com/ianozsvald/twitter-text-python |
| 91 | + |
| 92 | +The original ttp comes from Ivo Wetzel (no longer supported): |
| 93 | +https://github.com/BonsaiDen/twitter-text-python |
| 94 | + |
| 95 | +Originally based on [http://github.com/mzsanford/twitter-text-java](twitter-text-java). |
| 96 | + |
| 97 | + |
| 98 | +license |
| 99 | +------- |
| 100 | + |
| 101 | +*MIT* |
| 102 | + |
| 103 | +Copyright (c) 2012 Ivo Wetzel. |
| 104 | + |
| 105 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 106 | +of this software and associated documentation files (the "Software"), to deal |
| 107 | +in the Software without restriction, including without limitation the rights |
| 108 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 109 | +copies of the Software, and to permit persons to whom the Software is |
| 110 | +furnished to do so, subject to the following conditions: |
| 111 | + |
| 112 | +The above copyright notice and this permission notice shall be included in |
| 113 | +all copies or substantial portions of the Software. |
| 114 | + |
| 115 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 116 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 117 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 118 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 119 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 120 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 121 | +THE SOFTWARE. |
| 122 | + |
| 123 | +Copyright (c) 2010-2013 Ivo Wetzel |
| 124 | + |
0 commit comments