1
1
twitter-text-python
2
2
===================
3
3
4
- **twitter-text-python ** is a Tweet parser and formatter for Python.
4
+ **twitter-text-python ** is a Tweet parser and formatter for Python. Extract users, hashtags, URLs and format as HTML for display.
5
5
6
6
It is based on twitter-text-java _ and passes all the unittests of
7
7
twitter-text-conformance _ plus some additional ones.
8
8
9
9
.. _twitter-text-java : http://github.com/mzsanford/twitter-text-java
10
10
.. _twitter-text-conformance : http://github.com/mzsanford/twitter-text-conformance
11
11
12
- UPDATE - forked by Ian Ozsvald, some bugs fixed, few minor changes to functionality added:
12
+ This version was forked by Ian Ozsvald in January 2013 and released to PyPI , some bugs were fixed, a few minor changes to functionality added:
13
13
https://github.com/ianozsvald/twitter-text-python
14
14
15
- The original ttp comes from:
15
+ PyPI release:
16
+ http://pypi.python.org/pypi/twitter-text-python/
17
+
18
+ The original ttp comes from Ivo Wetzel (Ivo's version no longer supported):
16
19
https://github.com/BonsaiDen/twitter-text-python
17
20
18
21
Usage::
19
22
20
23
>>> import ttp
21
24
>>> p = ttp.Parser()
22
- >>> result = p.parse("@BonsaiDen Hey that 's a great Tweet parser! #twp ")
25
+ >>> result = p.parse("@ianozsvald, you now support #IvoWertzel 's tweet parser! https://github.com/ianozsvald/ ")
23
26
>>> result.reply
24
- 'BonsaiDen '
27
+ 'ianozsvald '
25
28
>>> result.users
26
- ['BonsaiDen ']
29
+ ['ianozsvald ']
27
30
>>> result.tags
28
- ['twp ']
31
+ ['IvoWertzel ']
29
32
>>> result.urls
30
- []
33
+ ['https://github.com/ianozsvald/' ]
31
34
>>> result.html
32
- u'<a href="http://twitter.com/BonsaiDen">@BonsaiDen</a> Hey that\'s a great Tweet Parser!
33
- <a href="http://search.twitter.com/search?q=%23twp">#twp</a>'
34
-
35
+ u'<a href="http://twitter.com/ianozsvald">@ianozsvald</a>, you now support <a href="http://search.twitter.com/search?q=%23IvoWertzel">#IvoWertzel</a>\'s tweet parser! <a href="https://github.com/ianozsvald/">https://github.com/ianozsvald/</a>'
35
36
36
37
If you need different HTML output just subclass and override the ``format_* `` methods.
37
38
39
+ You can also ask for the span tags to be returned for each entity::
40
+
41
+ >>> p = ttp.Parser(include_spans=True)
42
+ >>> result = p.parse("@ianozsvald, you now support #IvoWertzel's tweet parser! https://github.com/ianozsvald/")
43
+ >>> result.urls
44
+ [('https://github.com/ianozsvald/', (57, 87))]
45
+
46
+
47
+
48
+ Installation
49
+ ------------
50
+
51
+ $ pip install twitter-text-python # via: http://pypi.python.org/pypi/twitter-text-python
52
+ $ python
53
+ >>> import ttp
54
+ >>> ttp.__version__
55
+ '1.0.0'
56
+
57
+
58
+ Changelog
59
+ ---------
60
+
61
+ * 2013/2/11 1.0.0 released to PyPI
62
+
63
+
64
+ Tests
65
+ -----
66
+
67
+ $ python tests.py
68
+ .................................................................................................
69
+ ----------------------------------------------------------------------
70
+ Ran 97 tests in 0.009s
71
+ OK
72
+
38
73
39
74
Contributing
40
75
------------
@@ -43,23 +78,32 @@ The source is available on GitHub_, to
43
78
contribute to the project, fork it on GitHub and send a pull request.
44
79
Everyone is welcome to make improvements to **twp **!
45
80
46
- .. _GitHub : http://github.com/BonsaiDen/twitter-text-python
81
+ .. _GitHub : https://github.com/ianozsvald/twitter-text-python
82
+
47
83
48
84
License
49
- =======
85
+ -------
86
+
87
+ *MIT *
50
88
51
- Copyright (c) 2010 Ivo Wetzel
89
+ Copyright (c) 2012 Ivo Wetzel.
52
90
53
- **twitter-text-python ** is free software: you can redistribute it and/or
54
- modify it under the terms of the GNU General Public License as published by
55
- the Free Software Foundation, either version 3 of the License, or
56
- (at your option) any later version.
91
+ Permission is hereby granted, free of charge, to any person obtaining a copy
92
+ of this software and associated documentation files (the "Software"), to deal
93
+ in the Software without restriction, including without limitation the rights
94
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
95
+ copies of the Software, and to permit persons to whom the Software is
96
+ furnished to do so, subject to the following conditions:
57
97
58
- **twitter-text-python ** is distributed in the hope that it will be useful,
59
- but WITHOUT ANY WARRANTY; without even the implied warranty of
60
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
61
- GNU General Public License for more details.
98
+ The above copyright notice and this permission notice shall be included in
99
+ all copies or substantial portions of the Software.
62
100
63
- You should have received a copy of the GNU General Public License along with
64
- **twitter-text-python **. If not, see <http://www.gnu.org/licenses/>.
101
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
102
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
103
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
104
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
105
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
106
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
107
+ THE SOFTWARE.
65
108
109
+ Copyright (c) 2010-2013 Ivo Wetzel
0 commit comments