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
7189112b
Commit
7189112b
authored
Aug 19, 2013
by
Joshua Roesslein
Browse files
Merge pull request #347 from tewalds/disconnect
Handle disconnect notices, log unknown messages
parents
77472a0e
38a2fbc3
Changes
1
Hide whitespace changes
Inline
Side-by-side
tweepy/streaming.py
View file @
7189112b
...
...
@@ -2,6 +2,7 @@
# Copyright 2009-2010 Joshua Roesslein
# See LICENSE for details.
import
logging
import
httplib
from
socket
import
timeout
from
threading
import
Thread
...
...
@@ -31,24 +32,30 @@ class StreamListener(object):
"""
pass
def
on_data
(
self
,
data
):
def
on_data
(
self
,
raw_
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.
"""
data
=
json
.
loads
(
raw_data
)
if
'in_reply_to_status_id'
in
data
:
status
=
Status
.
parse
(
self
.
api
,
json
.
loads
(
data
)
)
status
=
Status
.
parse
(
self
.
api
,
data
)
if
self
.
on_status
(
status
)
is
False
:
return
False
elif
'delete'
in
data
:
delete
=
json
.
loads
(
data
)
[
'delete'
][
'status'
]
delete
=
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
:
if
self
.
on_limit
(
data
[
'limit'
][
'track'
])
is
False
:
return
False
elif
'disconnect'
in
data
:
if
self
.
on_disconnect
(
data
[
'disconnect'
])
is
False
:
return
False
else
:
logging
.
error
(
"Unknown message type: "
+
str
(
raw_data
))
def
on_status
(
self
,
status
):
"""Called when a new status arrives"""
...
...
@@ -70,6 +77,14 @@ class StreamListener(object):
"""Called when stream connection times out"""
return
def
on_disconnect
(
self
,
notice
):
"""Called when twitter sends a disconnect notice
Disconnect codes are listed here:
https://dev.twitter.com/docs/streaming-apis/messages#Disconnect_messages_disconnect
"""
return
class
Stream
(
object
):
...
...
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