aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFoxMaSk <[email protected]>2017-09-05 22:59:32 +0200
committerFoxMaSk <[email protected]>2017-09-05 22:59:32 +0200
commite0e68ccd6a8007fa9fb50aa7e8432505dc93f7b8 (patch)
treeb8fdb2f7c5d7317fd4dd4e97853cfbcb963e66bb /mastodon/streaming.py
parentc8490be2a717467c61381245e0fa2793a48c57ae (diff)
downloadmastodon.py-e0e68ccd6a8007fa9fb50aa7e8432505dc93f7b8.tar.gz
not pep8 compliant #71
Diffstat (limited to 'mastodon/streaming.py')
-rw-r--r--mastodon/streaming.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/mastodon/streaming.py b/mastodon/streaming.py
index 3212848..290ed44 100644
--- a/mastodon/streaming.py
+++ b/mastodon/streaming.py
@@ -1,7 +1,7 @@
1''' 1"""
2Handlers for the Streaming API: 2Handlers for the Streaming API:
3https://github.com/tootsuite/mastodon/blob/master/docs/Using-the-API/Streaming-API.md 3https://github.com/tootsuite/mastodon/blob/master/docs/Using-the-API/Streaming-API.md
4''' 4"""
5 5
6import json 6import json
7import logging 7import logging
@@ -12,43 +12,43 @@ log = logging.getLogger(__name__)
12 12
13 13
14class MalformedEventError(Exception): 14class MalformedEventError(Exception):
15 '''Raised when the server-sent event stream is malformed.''' 15 """Raised when the server-sent event stream is malformed."""
16 pass 16 pass
17 17
18 18
19class StreamListener(object): 19class StreamListener(object):
20 '''Callbacks for the streaming API. Create a subclass, override the on_xxx 20 """Callbacks for the streaming API. Create a subclass, override the on_xxx
21 methods for the kinds of events you're interested in, then pass an instance 21 methods for the kinds of events you're interested in, then pass an instance
22 of your subclass to Mastodon.user_stream(), Mastodon.public_stream(), or 22 of your subclass to Mastodon.user_stream(), Mastodon.public_stream(), or
23 Mastodon.hashtag_stream().''' 23 Mastodon.hashtag_stream()."""
24 24
25 def on_update(self, status): 25 def on_update(self, status):
26 '''A new status has appeared! 'status' is the parsed JSON dictionary 26 """A new status has appeared! 'status' is the parsed JSON dictionary
27 describing the status.''' 27describing the status."""
28 pass 28 pass
29 29
30 def on_notification(self, notification): 30 def on_notification(self, notification):
31 '''A new notification. 'notification' is the parsed JSON dictionary 31 """A new notification. 'notification' is the parsed JSON dictionary
32 describing the notification.''' 32 describing the notification."""
33 pass 33 pass
34 34
35 def on_delete(self, status_id): 35 def on_delete(self, status_id):
36 '''A status has been deleted. status_id is the status' integer ID.''' 36 """A status has been deleted. status_id is the status' integer ID."""
37 pass 37 pass
38 38
39 def handle_heartbeat(self): 39 def handle_heartbeat(self):
40 '''The server has sent us a keep-alive message. This callback may be 40 """The server has sent us a keep-alive message. This callback may be
41 useful to carry out periodic housekeeping tasks, or just to confirm 41 useful to carry out periodic housekeeping tasks, or just to confirm
42 that the connection is still open.''' 42 that the connection is still open."""
43 43
44 def handle_stream(self, lines): 44 def handle_stream(self, lines):
45 ''' 45 """
46 Handles a stream of events from the Mastodon server. When each event 46 Handles a stream of events from the Mastodon server. When each event
47 is received, the corresponding .on_[name]() method is called. 47 is received, the corresponding .on_[name]() method is called.
48 48
49 lines: an iterable of lines of bytes sent by the Mastodon server, as 49 lines: an iterable of lines of bytes sent by the Mastodon server, as
50 returned by requests.Response.iter_lines(). 50 returned by requests.Response.iter_lines().
51 ''' 51 """
52 event = {} 52 event = {}
53 for raw_line in lines: 53 for raw_line in lines:
54 try: 54 try:
@@ -104,4 +104,3 @@ class StreamListener(object):
104 else: 104 else:
105 # TODO: allow handlers to return/raise to stop streaming cleanly 105 # TODO: allow handlers to return/raise to stop streaming cleanly
106 handler(payload) 106 handler(payload)
107
Powered by cgit v1.2.3 (git 2.41.0)