2 .. module:: diaspora_api.diaspy
3 :platform: Unix, Windows
4 :synopsis: Simple python api for diaspora
6 .. moduleauthor:: Moritz Kiefer <moritz.kiefer@gmail.com>
14 """This is the client class to connect to diaspora.
18 Before calling any other function you have to call :func:`diaspy.diaspy.Client.login`.
22 def __init__(self
, pod
):
23 self
._token
_regex
= re
.compile(r
'content="(.*?)"\s+name="csrf-token')
25 self
._session
= requests
.Session()
27 def login(self
, username
, password
):
28 """This function is used to connect to the pod and log in.
30 :param username: The username used to log in.
32 :param password: The password used to log in.
36 self
._username
= username
37 self
._password
= password
38 r
= self
._session
.get(self
._pod
+ "/users/sign_in")
39 token
= self
._token
_regex
.search(r
.text
).group(1)
41 data
= {'user[username]': self
._username
,
42 'user[password]': self
._password
,
43 'authenticity_token': token
,
46 r
= self
._session
.post(self
._pod
+ "/users/sign_in", data
=data
)
48 def post(self
, text
, aspect_id
='public'):
49 """This function sends a post to an aspect
51 :param text: Text to post.
53 :param aspect_id: Aspect id to send post to.
57 r
= self
._session
.get(self
._pod
+ "/stream")
58 token
= self
._token
_regex
.search(r
.text
).group(1)
59 data
= {'aspect_ids': aspect_id
,
60 'status_message[text]': text
,
61 'authenticity_token': token
}
62 r
= self
._session
.post(self
._pod
+ "/status_messages", data
=data
)