From a264fac2b412f5ef139123a7487cb9097f43b558 Mon Sep 17 00:00:00 2001 From: ThatAlexanderA <38069912+ThatAlexanderA@users.noreply.github.com> Date: Mon, 4 Jun 2018 13:29:23 +0200 Subject: [PATCH 1/8] Update utils.py --- fbchat/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fbchat/utils.py b/fbchat/utils.py index c3fe933..b8a6454 100644 --- a/fbchat/utils.py +++ b/fbchat/utils.py @@ -122,7 +122,9 @@ class ReqUrl(object): ATTACHMENT_PHOTO = "https://www.facebook.com/mercury/attachments/photo/" EVENT_REMINDER = "https://www.facebook.com/ajax/eventreminder/create" MODERN_SETTINGS_MENU = "https://www.facebook.com/bluebar/modern_settings_menu/" - + REMOVE_FRIENDFIRST = "https://m.facebook.com/removefriend.php?friend_id=" + REMOVE_FRIENDSECOND = "https://m.facebook.com/a/removefriend.php" + pull_channel = 0 def change_pull_channel(self, channel=None): From c842be3a52d900f5c6866719e0ab0c80d38b52e7 Mon Sep 17 00:00:00 2001 From: ThatAlexanderA <38069912+ThatAlexanderA@users.noreply.github.com> Date: Mon, 4 Jun 2018 13:32:15 +0200 Subject: [PATCH 2/8] Update client.py --- fbchat/client.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 2b20d69..5e79bd9 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -467,8 +467,32 @@ class Client(object): """ END DEFAULT THREAD METHODS - """ - + """ + def removefriend(self, friend_id=None): + r = self._get(self.req_url.REMOVE_FRIENDFIRST + friend_id) + soup = bs(r.text, "lxml") + fb_dtsg_value = soup.find('input', {'name': 'fb_dtsg'}).get('value') + print self._session.cookies.get_dict().get('c_user') + print self._session.cookies.get_dict().get('xs') + payload = [ + { + "name": "fb_dtsg", + "value": fb_dtsg_value + }, + { + "name": "friend_id", + "value": friend_id + }, + { + "name": "unref", + "value": "none" + }, + { + "name": "confirm", + "value": "Confirm" + }] + r = self._post(self.req_url.REMOVE_FRIENDSECOND,payload) + return r.ok """ FETCH METHODS """ From 36742bf30b2f8456a0a4a618e49ee2e2df24ff2f Mon Sep 17 00:00:00 2001 From: ThatAlexanderA <38069912+ThatAlexanderA@users.noreply.github.com> Date: Mon, 4 Jun 2018 16:16:53 +0200 Subject: [PATCH 3/8] Added remove friend def --- fbchat/client.py | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 5e79bd9..2cd5ec0 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -468,30 +468,14 @@ class Client(object): """ END DEFAULT THREAD METHODS """ - def removefriend(self, friend_id=None): - r = self._get(self.req_url.REMOVE_FRIENDFIRST + friend_id) - soup = bs(r.text, "lxml") - fb_dtsg_value = soup.find('input', {'name': 'fb_dtsg'}).get('value') - print self._session.cookies.get_dict().get('c_user') - print self._session.cookies.get_dict().get('xs') - payload = [ - { - "name": "fb_dtsg", - "value": fb_dtsg_value - }, - { - "name": "friend_id", - "value": friend_id - }, - { - "name": "unref", - "value": "none" - }, - { - "name": "confirm", - "value": "Confirm" - }] - r = self._post(self.req_url.REMOVE_FRIENDSECOND,payload) + def removeFriend(self, friend_id=None): + :param friend_id: The id of the friend that you want to remove + payload = { + "friend_id": friend_id, + "unref": "none", + "confirm": "Confirm", + } + r = self._post(self.req_url.REMOVE_FRIEND,payload) return r.ok """ FETCH METHODS From e3602e83ce96651b0b29306dd58331c2755442a3 Mon Sep 17 00:00:00 2001 From: ThatAlexanderA <38069912+ThatAlexanderA@users.noreply.github.com> Date: Mon, 4 Jun 2018 16:18:32 +0200 Subject: [PATCH 4/8] Added Remove Friend URl --- fbchat/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fbchat/utils.py b/fbchat/utils.py index b8a6454..7801b82 100644 --- a/fbchat/utils.py +++ b/fbchat/utils.py @@ -122,8 +122,7 @@ class ReqUrl(object): ATTACHMENT_PHOTO = "https://www.facebook.com/mercury/attachments/photo/" EVENT_REMINDER = "https://www.facebook.com/ajax/eventreminder/create" MODERN_SETTINGS_MENU = "https://www.facebook.com/bluebar/modern_settings_menu/" - REMOVE_FRIENDFIRST = "https://m.facebook.com/removefriend.php?friend_id=" - REMOVE_FRIENDSECOND = "https://m.facebook.com/a/removefriend.php" + REMOVE_FRIEND = "https://m.facebook.com/a/removefriend.php" pull_channel = 0 From 91778f43b7d8e90cf5f9a04389941f8790a22a83 Mon Sep 17 00:00:00 2001 From: ThatAlexanderA <38069912+ThatAlexanderA@users.noreply.github.com> Date: Mon, 4 Jun 2018 16:19:40 +0200 Subject: [PATCH 5/8] Update client.py --- fbchat/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 2cd5ec0..96c8bdc 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -469,7 +469,7 @@ class Client(object): END DEFAULT THREAD METHODS """ def removeFriend(self, friend_id=None): - :param friend_id: The id of the friend that you want to remove + """param friend_id: The id of the friend that you want to remove""" payload = { "friend_id": friend_id, "unref": "none", From b599033c54d96f62240d7bd35e6fbda14dfb0a7f Mon Sep 17 00:00:00 2001 From: ThatAlexanderA <38069912+ThatAlexanderA@users.noreply.github.com> Date: Tue, 5 Jun 2018 18:41:09 +0200 Subject: [PATCH 6/8] Updated removeFirend --- fbchat/client.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 96c8bdc..448f92c 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -11,7 +11,12 @@ from .utils import * from .models import * from .graphql import * import time - +try: + from urllib.parse import urlparse + from urllib.parse import parse_qs +except ImportError: + from urlparse import urlparse + from urlparse import parse_qs class Client(object): @@ -469,14 +474,25 @@ class Client(object): END DEFAULT THREAD METHODS """ def removeFriend(self, friend_id=None): - """param friend_id: The id of the friend that you want to remove""" + """ + Removes a specifed friend from your friend list + :param friend_id: The id of the friend that you want to remove + :returns error when the removing was unsuccessful + :returns True when the removing was successful + """ payload = { "friend_id": friend_id, "unref": "none", "confirm": "Confirm", } r = self._post(self.req_url.REMOVE_FRIEND,payload) - return r.ok + dict = parse_qs(urlparse(r.url).query) + if "err" not in dict: + print ("Remove was successful!") + return True + else: + print ("Error while removing friend") + return False """ FETCH METHODS """ From c7cbbdd1c89e92cffdd0641ecd7f7f7f22e586c5 Mon Sep 17 00:00:00 2001 From: ThatAlexanderA <38069912+ThatAlexanderA@users.noreply.github.com> Date: Tue, 5 Jun 2018 21:56:31 +0200 Subject: [PATCH 7/8] Changed dict to query, replaced print with log --- fbchat/client.py | 50 +++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 448f92c..099799f 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -12,11 +12,9 @@ from .models import * from .graphql import * import time try: - from urllib.parse import urlparse - from urllib.parse import parse_qs + from urllib.parse import urlparse,parse_qs except ImportError: - from urlparse import urlparse - from urlparse import parse_qs + from urlparse import urlparse,parse_qs class Client(object): @@ -473,26 +471,7 @@ class Client(object): """ END DEFAULT THREAD METHODS """ - def removeFriend(self, friend_id=None): - """ - Removes a specifed friend from your friend list - :param friend_id: The id of the friend that you want to remove - :returns error when the removing was unsuccessful - :returns True when the removing was successful - """ - payload = { - "friend_id": friend_id, - "unref": "none", - "confirm": "Confirm", - } - r = self._post(self.req_url.REMOVE_FRIEND,payload) - dict = parse_qs(urlparse(r.url).query) - if "err" not in dict: - print ("Remove was successful!") - return True - else: - print ("Error while removing friend") - return False + """ FETCH METHODS """ @@ -1337,8 +1316,27 @@ class Client(object): r = self._post(self.req_url.CONNECT, data) return r.ok - - + + def removeFriend(self, friend_id=None): + """ + Removes a specifed friend from your friend list + :param friend_id: The id of the friend that you want to remove + :return: Returns error if the removing was unsuccessful, returns True when successful. + """ + payload = { + "friend_id": friend_id, + "unref": "none", + "confirm": "Confirm", + } + r = self._post(self.req_url.REMOVE_FRIEND,payload) + query = parse_qs(urlparse(r.url).query) + if "err" not in query: + log.debug ("Remove was successful!") + return True + else: + log.debug ("Error while removing friend") + return False + """ LISTEN METHODS """ From 67edd19eb8a457dbb2c6d154c1b127333b85f451 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 20 Jun 2018 13:51:12 +0200 Subject: [PATCH 8/8] Small formatting fixes --- fbchat/client.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 099799f..d09b287 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -12,9 +12,9 @@ from .models import * from .graphql import * import time try: - from urllib.parse import urlparse,parse_qs + from urllib.parse import urlparse, parse_qs except ImportError: - from urlparse import urlparse,parse_qs + from urlparse import urlparse, parse_qs class Client(object): @@ -470,8 +470,8 @@ class Client(object): """ END DEFAULT THREAD METHODS - """ - + """ + """ FETCH METHODS """ @@ -1316,10 +1316,10 @@ class Client(object): r = self._post(self.req_url.CONNECT, data) return r.ok - + def removeFriend(self, friend_id=None): - """ - Removes a specifed friend from your friend list + """Removes a specifed friend from your friend list + :param friend_id: The id of the friend that you want to remove :return: Returns error if the removing was unsuccessful, returns True when successful. """ @@ -1328,15 +1328,15 @@ class Client(object): "unref": "none", "confirm": "Confirm", } - r = self._post(self.req_url.REMOVE_FRIEND,payload) + r = self._post(self.req_url.REMOVE_FRIEND, payload) query = parse_qs(urlparse(r.url).query) if "err" not in query: - log.debug ("Remove was successful!") + log.debug("Remove was successful!") return True else: - log.debug ("Error while removing friend") + log.warning("Error while removing friend") return False - + """ LISTEN METHODS """