Commit | Line | Data |
---|---|---|
7a31b4aa MM |
1 | #### `Stream()` object |
2 | ||
3 | This object is used to represent user's stream on D\*. | |
4 | It is returned by `Client()`'s method `get_stream()` and | |
8b013ef4 | 5 | is basically a list of posts. |
7a31b4aa MM |
6 | |
7 | ---- | |
8 | ||
9 | ##### Getting stream | |
10 | ||
11 | To get basic stream you have to have working `Connection()` as | |
12 | this is required by `Stream()`'s constructor. | |
13 | ||
14 | c = diaspy.connection.Connection(pod='https://pod.example.com', | |
15 | username='foo', | |
16 | password='bar') | |
17 | c.login() | |
18 | stream = diaspy.models.Stream(c) | |
19 | ||
20 | Now you have a stream filled with posts (if any can be found on user's stream). | |
21 | ||
22 | ---- | |
23 | ||
cdbe5f4e MM |
24 | ##### `fill()` and `update()` |
25 | ||
26 | When you want to refresh stream call it's `fill()` method. It will overwrite old stream | |
27 | contents. | |
28 | ||
29 | On the contrary, `update()` will get a new stream but will not overwrite old stream saved | |
30 | in the object memory. It will append every new post to the old stream. | |
31 | ||
32 | ---- | |
33 | ||
34 | ##### Length of and iterating over a stream | |
7a31b4aa MM |
35 | |
36 | Stream's length can be checked by calling `len()` on it. | |
37 | ||
38 | len(stream) | |
39 | 10 | |
cdbe5f4e MM |
40 | |
41 | When you want to iterate over a stream (e.g. when you want to print first *n* posts on | |
42 | the stream) you can do it in two ways. | |
43 | ||
44 | First, using `len()` and `range()` functions. | |
45 | ||
46 | for i in range(len(stream)): | |
47 | # do stuff... | |
48 | ||
49 | Second, iterating directly over the stream contents: | |
50 | ||
51 | for post in stream: | |
52 | # do stuff... | |
53 | ||
54 | ||
8b013ef4 MM |
55 | ---- |
56 | ||
57 | ##### Posting data to stream | |
58 | ||
59 | This is described in [`posting`](./posting.mdown) document in this manual. | |
60 | ||
cdbe5f4e MM |
61 | ---- |
62 | ||
63 | ###### Manual for `diaspy`, written by Marek Marecki |