Add function to retrieve userinfo
authorMoritz Kiefer <moritz.kiefer@gmail.com>
Wed, 16 Jan 2013 14:17:35 +0000 (15:17 +0100)
committerMoritz Kiefer <moritz.kiefer@gmail.com>
Wed, 16 Jan 2013 14:17:35 +0000 (15:17 +0100)
.gitignore
diaspy.py

index 666aa6abc88d467125629a29a96539e8e42a0c9e..1ebd6c0eaf28fc40c2a19230c441a84c77042464 100644 (file)
@@ -2,4 +2,5 @@
 *.swp
 docs/build/*
 __pycache__/*
+.env
 
index 66d9d3841a42eb3e5cc655944e437f0f8a514132..9bbb3eecd626e1b96b27f26bf46856b9041e536d 100644 (file)
--- a/diaspy.py
+++ b/diaspy.py
@@ -9,6 +9,7 @@
 """
 import requests
 import re
+import json
 
 class Client:
     """This is the client class to connect to diaspora.
@@ -60,3 +61,13 @@ class Client:
                 'status_message[text]': text,
                 'authenticity_token': token}
         r = self._session.post(self._pod + "/status_messages", data=data)
+
+    def getUserInfo(self):
+        """ This function return the current user's attributes
+        :returns dict -- json formatted user info
+
+        """
+        r = self._session.get(self._pod + "/stream")
+        regex = re.compile(r'window.current_user_attributes = ({.*})')
+        userdata = json.loads(regex.search(r.text).group(1))
+        return userdata