File: streams.markdown

package info (click to toggle)
python-diaspy 0.6.0-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 352 kB
  • sloc: python: 1,600; makefile: 149
file content (87 lines) | stat: -rw-r--r-- 1,967 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#### `Stream()` object

This object is used to represent user's stream on D\*. 
It is basically a list of posts. 

----

##### Getting stream

To get basic stream you have to have working `Connection()` as 
this is required by `Stream()`'s constructor.

    c = diaspy.connection.Connection(pod='https://pod.example.com',
                                     username='foo',
                                     password='bar')
    c.login()
    stream = diaspy.streams.Stream(c)

Now you have a stream filled with posts (if any can be found on user's
stream).

Other streams you can use are `Activity()`, `Aspects()`, `Commented()`,
`Liked()`, `Mentions()`, `FollowedTags()` and `Tag()`.

Example: `stream = diaspy.streams.Activity(c)`

----

##### `fill()`, `update()` and `more()`

When you want to refresh stream call it's `fill()` method. It will 
overwrite old stream contents.

On the contrary, `update()` will get a new stream but will not overwrite
 old stream saved in the object memory. It will append every new post to
 the old stream.

`more()` complements `update()` it will fetch you older posts instead of
 newer ones.

----

##### Length of and iterating over a stream

Stream's length can be checked by calling `len()` on it.

    len(stream)
    10

When you want to iterate over a stream (e.g. when you want to print 
first *n* posts on the stream) you can do it in two ways.

First, using `len()` and `range()` functions.

    for i in range(len(stream)):
        # do stuff...

Second, iterating directly over the stream contents:

    for post in stream:
        # do stuff...


----

##### Posting data to stream

This is described in [`posting`](./posting.markdown) document in this 
manual.


----

##### Clearing stream

##### `clear()`

This will remove all posts from visible stream.

##### `purge()`

This will scan stream for nonexistent posts (eg. deleted) and remove 
them.

----

###### Manual for `diaspy`, written by Marek Marecki