e2a26748fb239a13ae4e858fb73c19f042a7461d
[diaspy.git] / manual / streams.markdown
1 #### `Stream()` object
2
3 This object is used to represent user's stream on D\*.
4 It is basically a list of posts.
5
6 ----
7
8 ##### Getting stream
9
10 To get basic stream you have to have working `Connection()` as
11 this is required by `Stream()`'s constructor.
12
13 c = diaspy.connection.Connection(pod='https://pod.example.com',
14 username='foo',
15 password='bar')
16 c.login()
17 stream = diaspy.streams.Stream(c)
18
19 Now you have a stream filled with posts (if any can be found on user's
20 stream).
21
22 Other streams you can use are `Activity()`, `Aspects()`, `Commented()`,
23 `Liked()`, `Mentions()`, `FollowedTags()` and `Tag()`.
24
25 Example: `stream = diaspy.streams.Activity(c)`
26
27 ----
28
29 ##### `fill()`, `update()` and `more()`
30
31 When you want to refresh stream call it's `fill()` method. It will
32 overwrite old stream contents.
33
34 On the contrary, `update()` will get a new stream but will not overwrite
35 old stream saved in the object memory. It will append every new post to
36 the old stream.
37
38 `more()` complements `update()` it will fetch you older posts instead of
39 newer ones.
40
41 ----
42
43 ##### Length of and iterating over a stream
44
45 Stream's length can be checked by calling `len()` on it.
46
47 len(stream)
48 10
49
50 When you want to iterate over a stream (e.g. when you want to print
51 first *n* posts on the stream) you can do it in two ways.
52
53 First, using `len()` and `range()` functions.
54
55 for i in range(len(stream)):
56 # do stuff...
57
58 Second, iterating directly over the stream contents:
59
60 for post in stream:
61 # do stuff...
62
63
64 ----
65
66 ##### Posting data to stream
67
68 This is described in [`posting`](./posting.markdown) document in this
69 manual.
70
71
72 ----
73
74 ##### Clearing stream
75
76 ##### `clear()`
77
78 This will remove all posts from visible stream.
79
80 ##### `purge()`
81
82 This will scan stream for nonexistent posts (eg. deleted) and remove
83 them.
84
85 ----
86
87 ###### Manual for `diaspy`, written by Marek Marecki