From 0142c8ff41effc29576c5f83153975e4ab50acd5 Mon Sep 17 00:00:00 2001 From: botcs Date: Tue, 7 Mar 2017 14:32:45 +0100 Subject: [PATCH 1/9] getThreadInfo fix. Stripping fbid: from string --- fbchat/client.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index c82561a..616a80e 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -789,13 +789,24 @@ class Client(object): except requests.exceptions.Timeout: pass - def getUserInfo(self,*user_ids): + def getUserInfo(self, *user_ids): """Get user info from id. Unordered. :param user_ids: one or more user id(s) to query """ - data = {"ids[{}]".format(i):user_id for i,user_id in enumerate(user_ids)} + def fbidStrip(_fbid): + # Stripping of `fbid:` from author_id + if type(_fbid) == int: + return _fbid + + if type(_fbid) == str and 'fbid:' in _fbid: + return int(_fbid[5:]) + + user_ids = [fbidStrip(uid) for uid in user_ids] + + + data = {"ids[{}]".format(i):uid for i,uid in enumerate(user_ids)} r = self._post(UserInfoURL, data) info = get_json(r.text) full_data= [details for profile,details in info['payload']['profiles'].items()] From d2d77501e407c2d1e33701a5e58a1da55c748715 Mon Sep 17 00:00:00 2001 From: botcs Date: Tue, 7 Mar 2017 14:37:00 +0100 Subject: [PATCH 2/9] getThreadInfo fix: refactored `end` parameter, using instead length, because of behaviour --- fbchat/client.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 616a80e..0e75cad 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -512,17 +512,16 @@ class Client(object): # Strip the start and parse out the returned image_id return json.loads(r._content[9:])['payload']['metadata'][0]['image_id'] - def getThreadInfo(self, userID, start, end=None, thread_type='user'): + def getThreadInfo(self, userID, start, length=20, thread_type='user'): """Get the info of one Thread :param userID: ID of the user you want the messages from :param start: the start index of a thread - :param end: (optional) the last index of a thread + :param length: (optional) number of retrieved messages from start :param thread_type: (optional) change from 'user' for group threads """ - - if not end: end = start + 20 - if end <= start: end = start + end + + assert(length > 0, 'length must be positive integer, got %d'%length) data = {} if thread_type == 'user': @@ -531,7 +530,7 @@ class Client(object): key = 'thread_fbids' data['messages[{}][{}][offset]'.format(key, userID)] = start - data['messages[{}][{}][limit]'.format(key, userID)] = end + data['messages[{}][{}][limit]'.format(key, userID)] = length data['messages[{}][{}][timestamp]'.format(key, userID)] = now() r = self._post(MessagesURL, query=data) From f4cac4b8dbd6d1bb310d0240edb7fa585fbede2e Mon Sep 17 00:00:00 2001 From: botcs Date: Tue, 7 Mar 2017 14:39:10 +0100 Subject: [PATCH 3/9] getThreadInfo fix: removed parens from assertion --- fbchat/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 0e75cad..b8f8c80 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -521,7 +521,7 @@ class Client(object): :param thread_type: (optional) change from 'user' for group threads """ - assert(length > 0, 'length must be positive integer, got %d'%length) + assert length > 0, 'length must be positive integer, got %d'%length data = {} if thread_type == 'user': From 2580cf557744d7320bef3bf09352cdfc37178b63 Mon Sep 17 00:00:00 2001 From: botcs Date: Tue, 7 Mar 2017 14:54:04 +0100 Subject: [PATCH 4/9] getThreadInfo fix: start is deprecated, method always returns with 0 offset --- fbchat/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index b8f8c80..a7b62d7 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -521,7 +521,7 @@ class Client(object): :param thread_type: (optional) change from 'user' for group threads """ - assert length > 0, 'length must be positive integer, got %d'%length + assert length > 0, 'length must be positive integer, got %d' % length data = {} if thread_type == 'user': From 3ea27ea49a4652c19e99cca551f594779892bbfc Mon Sep 17 00:00:00 2001 From: botcs Date: Tue, 7 Mar 2017 15:55:03 +0100 Subject: [PATCH 5/9] getThreadList fix: `end` is ignored by the querry --- fbchat/client.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index a7b62d7..40f444e 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -512,25 +512,27 @@ class Client(object): # Strip the start and parse out the returned image_id return json.loads(r._content[9:])['payload']['metadata'][0]['image_id'] - def getThreadInfo(self, userID, start, length=20, thread_type='user'): + def getThreadInfo(self, userID, last_n=20, start=None, thread_type='user'): """Get the info of one Thread :param userID: ID of the user you want the messages from - :param start: the start index of a thread - :param length: (optional) number of retrieved messages from start + :param last_n: (optional) number of retrieved messages from start + :param start: (optional) the start index of a thread (Deprecated) :param thread_type: (optional) change from 'user' for group threads """ - assert length > 0, 'length must be positive integer, got %d' % length - + assert last_n > 0, 'length must be positive integer, got %d' % last_n + assert start is None, '`start` is deprecated, always 0 offset querry is returned' data = {} if thread_type == 'user': key = 'user_ids' else: key = 'thread_fbids' - - data['messages[{}][{}][offset]'.format(key, userID)] = start - data['messages[{}][{}][limit]'.format(key, userID)] = length + assert + # deprecated + # `start` doesn't matter, always returns from the last + # data['messages[{}][{}][offset]'.format(key, userID)] = start + data['messages[{}][{}][limit]'.format(key, userID)] = last_n data['messages[{}][{}][timestamp]'.format(key, userID)] = now() r = self._post(MessagesURL, query=data) @@ -553,10 +555,14 @@ class Client(object): :param start: the start index of a thread :param end: (optional) the last index of a thread """ - - if not end: end = start + 20 - if end <= start: end = start + end - + + # deprecated + # end does not limit the length of the returned threads + # if not end: end = start + 20 + # if end <= start: end = start + end + + assert end is None, 'end is deprecated' + timestamp = now() date = datetime.now() data = { From 3f3929fcdec89c6c34577b63af086c4e28879f54 Mon Sep 17 00:00:00 2001 From: botcs Date: Tue, 7 Mar 2017 15:58:47 +0100 Subject: [PATCH 6/9] getThreadList fix: `end` is ignored by the querry --- fbchat/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 40f444e..351894b 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -528,7 +528,7 @@ class Client(object): key = 'user_ids' else: key = 'thread_fbids' - assert + # deprecated # `start` doesn't matter, always returns from the last # data['messages[{}][{}][offset]'.format(key, userID)] = start From 43fbe4c6555de0e71138dccd1108b8a68fafcb5f Mon Sep 17 00:00:00 2001 From: botcs Date: Tue, 7 Mar 2017 16:09:00 +0100 Subject: [PATCH 7/9] assertion added for getThreadList end --- fbchat/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 351894b..63ae8f0 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -561,7 +561,7 @@ class Client(object): # if not end: end = start + 20 # if end <= start: end = start + end - assert end is None, 'end is deprecated' + assert end is None, '`end` is deprecated, always return last 20 threads' timestamp = now() date = datetime.now() From 78928fda7733aaf7d5fc763434e2f6ed61546327 Mon Sep 17 00:00:00 2001 From: botcs Date: Wed, 8 Mar 2017 10:28:13 +0100 Subject: [PATCH 8/9] fix None issue --- fbchat/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 63ae8f0..c21190c 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -532,6 +532,7 @@ class Client(object): # deprecated # `start` doesn't matter, always returns from the last # data['messages[{}][{}][offset]'.format(key, userID)] = start + data['messages[{}][{}][offset]'.format(key, userID)] = 0 data['messages[{}][{}][limit]'.format(key, userID)] = last_n data['messages[{}][{}][timestamp]'.format(key, userID)] = now() @@ -568,7 +569,7 @@ class Client(object): data = { 'client' : self.client, 'inbox[offset]' : start, - 'inbox[limit]' : end, + 'inbox[limit]' : 19, } r = self._post(ThreadsURL, data) From eb1ff3ffaad15539581e0ba862260637771d7278 Mon Sep 17 00:00:00 2001 From: botcs Date: Wed, 8 Mar 2017 10:48:57 +0100 Subject: [PATCH 9/9] !!! getThreadList length MAX 20 --- fbchat/client.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index c21190c..195d7dd 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -550,26 +550,21 @@ class Client(object): return list(reversed(messages)) - def getThreadList(self, start, end=None): + def getThreadList(self, start, length=20): """Get thread list of your facebook account. :param start: the start index of a thread :param end: (optional) the last index of a thread """ - # deprecated - # end does not limit the length of the returned threads - # if not end: end = start + 20 - # if end <= start: end = start + end - - assert end is None, '`end` is deprecated, always return last 20 threads' + assert length < 21, '`length` is deprecated, max. last 20 threads are returned' timestamp = now() date = datetime.now() data = { 'client' : self.client, 'inbox[offset]' : start, - 'inbox[limit]' : 19, + 'inbox[limit]' : length, } r = self._post(ThreadsURL, data)