Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
f85201f4
Commit
f85201f4
authored
Nov 29, 2009
by
Joshua
Browse files
Add "on_data" method to stream listener to allow for access raw stream data.
parent
20dab8b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
CHANGELOG
View file @
f85201f4
...
...
@@ -12,6 +12,8 @@ during upgrade will be listed here.
s = Stream('test', 'password', MyListener())
s.sample(async=True) # threaded mode
s.filter(track=['pizza']) # synch./blocking mode
- Listener now has a "on_data" method which can be overridden to manually handle the
raw stream data.
1.2 -> 1.3 [Current release]
=====================
...
...
tweepy/streaming.py
View file @
f85201f4
...
...
@@ -29,6 +29,28 @@ STREAM_VERSION = 1
class
StreamListener
(
object
):
def
__init__
(
self
):
self
.
api
=
API
()
def
on_data
(
self
,
data
):
"""Called when raw data is received from connection.
Override this method if you wish to manually handle
the stream data. Return False to stop stream and close connection.
"""
if
'in_reply_to_status_id'
in
data
:
status
=
parse_status
(
json
.
loads
(
data
),
self
.
api
)
if
self
.
on_status
(
status
)
is
False
:
return
False
elif
'delete'
in
data
:
delete
=
json
.
loads
(
data
)[
'delete'
][
'status'
]
if
self
.
on_delete
(
delete
[
'id'
],
delete
[
'user_id'
])
is
False
:
return
False
elif
'limit'
in
data
:
if
self
.
on_limit
(
json
.
loads
(
data
)[
'limit'
][
'track'
])
is
False
:
return
False
def
on_status
(
self
,
status
):
"""Called when a new status arrives"""
return
...
...
@@ -128,21 +150,10 @@ class Stream(object):
else
:
continue
# read data
# read data
and pass into listener
data
=
resp
.
read
(
length
)
# turn json data into status object
if
'in_reply_to_status_id'
in
data
:
status
=
parse_status
(
json
.
loads
(
data
),
self
.
api
)
if
self
.
listener
.
on_status
(
status
)
==
False
:
self
.
running
=
False
elif
'delete'
in
data
:
delete
=
json
.
loads
(
data
)[
'delete'
][
'status'
]
if
self
.
listener
.
on_delete
(
delete
[
'id'
],
delete
[
'user_id'
])
==
False
:
self
.
running
=
False
elif
'limit'
in
data
:
if
self
.
listener
.
on_limit
(
json
.
loads
(
data
)[
'limit'
][
'track'
])
==
False
:
self
.
running
=
False
if
self
.
listener
.
on_data
(
data
)
is
False
:
self
.
running
=
False
def
_start
(
self
,
async
):
self
.
running
=
True
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment