c21a6b4347460fa4333badde2ef02f3677bba938
7 """This is the client class to connect to diaspora.
11 Before calling any other function
12 you have to call :func:`diaspy.Client.login`.
16 def __init__(self
, pod
):
17 self
._token
_regex
= re
.compile(r
'content="(.*?)"\s+name="csrf-token')
19 self
.session
= requests
.Session()
22 r
= self
.session
.get(self
.pod
+ "/stream")
23 token
= self
._token
_regex
.search(r
.text
).group(1)
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 data
= {'aspect_ids': aspect_id
,
58 'status_message[text]': text
,
59 'authenticity_token': self
.get_token()}
60 r
= self
.session
.post(self
.pod
+ "/status_messages", data
=data
)
62 def get_user_info(self
):
63 """This function returns the current user's attributes.
65 :returns: dict -- json formatted user info.
68 r
= self
.session
.get(self
.pod
+ "/stream")
69 regex
= re
.compile(r
'window.current_user_attributes = ({.*})')
70 userdata
= json
.loads(regex
.search(r
.text
).group(1))