Merge branch 'master' into master
This commit is contained in:
@@ -40,6 +40,7 @@ PingURL ="https://0-channel-proxy-06-ash2.facebook.com/active_ping"
|
|||||||
UploadURL ="https://upload.facebook.com/ajax/mercury/upload.php"
|
UploadURL ="https://upload.facebook.com/ajax/mercury/upload.php"
|
||||||
UserInfoURL ="https://www.facebook.com/chat/user_info/"
|
UserInfoURL ="https://www.facebook.com/chat/user_info/"
|
||||||
RemoveUserURL="https://www.facebook.com/chat/remove_participants/"
|
RemoveUserURL="https://www.facebook.com/chat/remove_participants/"
|
||||||
|
LogoutURL ="https://www.facebook.com/logout.php"
|
||||||
|
|
||||||
class Client(object):
|
class Client(object):
|
||||||
"""A client for the Facebook Chat (Messenger).
|
"""A client for the Facebook Chat (Messenger).
|
||||||
@@ -160,6 +161,7 @@ class Client(object):
|
|||||||
r = self._get(BaseURL)
|
r = self._get(BaseURL)
|
||||||
soup = bs(r.text, "lxml")
|
soup = bs(r.text, "lxml")
|
||||||
self.fb_dtsg = soup.find("input", {'name':'fb_dtsg'})['value']
|
self.fb_dtsg = soup.find("input", {'name':'fb_dtsg'})['value']
|
||||||
|
self.fb_h = soup.find("input", {'name':'h'})['value']
|
||||||
self._setttstamp()
|
self._setttstamp()
|
||||||
# Set default payload
|
# Set default payload
|
||||||
self.payloadDefault['__rev'] = int(r.text.split('"revision":',1)[1].split(",",1)[0])
|
self.payloadDefault['__rev'] = int(r.text.split('"revision":',1)[1].split(",",1)[0])
|
||||||
@@ -188,6 +190,19 @@ class Client(object):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def logout(self, timeout=30):
|
||||||
|
data = {}
|
||||||
|
data['ref'] = "mb"
|
||||||
|
data['h'] = self.fb_h
|
||||||
|
payload=self._generatePayload(data)
|
||||||
|
r = self._session.get(LogoutURL, headers=self._header, params=payload, timeout=timeout)
|
||||||
|
# reset value
|
||||||
|
self.payloadDefault={}
|
||||||
|
self._session = requests.session()
|
||||||
|
self.req_counter = 1
|
||||||
|
self.seq = "0"
|
||||||
|
return r
|
||||||
|
|
||||||
def listen(self):
|
def listen(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -327,21 +342,27 @@ class Client(object):
|
|||||||
# Strip the start and parse out the returned image_id
|
# Strip the start and parse out the returned image_id
|
||||||
return json.loads(r._content[9:])['payload']['metadata'][0]['image_id']
|
return json.loads(r._content[9:])['payload']['metadata'][0]['image_id']
|
||||||
|
|
||||||
def getThreadInfo(self, userID, start, end=None):
|
def getThreadInfo(self, userID, start, end=None, thread_type='user'):
|
||||||
"""Get the info of one Thread
|
"""Get the info of one Thread
|
||||||
|
|
||||||
:param userID: ID of the user you want the messages from
|
:param userID: ID of the user you want the messages from
|
||||||
:param start: the start index of a thread
|
:param start: the start index of a thread
|
||||||
:param end: (optional) the last index of a thread
|
:param end: (optional) the last index of a thread
|
||||||
|
:param thread_type: (optional) change from 'user' for group threads
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not end: end = start + 20
|
if not end: end = start + 20
|
||||||
if end <= start: end = start + end
|
if end <= start: end = start + end
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
data['messages[user_ids][%s][offset]'%userID] = start
|
if thread_type == 'user':
|
||||||
data['messages[user_ids][%s][limit]'%userID] = end
|
key = 'user_ids'
|
||||||
data['messages[user_ids][%s][timestamp]'%userID] = now()
|
else:
|
||||||
|
key = 'thread_fbids'
|
||||||
|
|
||||||
|
data['messages[{}][{}][offset]'.format(key, userID)] = start
|
||||||
|
data['messages[{}][{}][limit]'.format(key, userID)] = end
|
||||||
|
data['messages[{}][{}][timestamp]'.format(key, userID)] = now()
|
||||||
|
|
||||||
r = self._post(MessagesURL, query=data)
|
r = self._post(MessagesURL, query=data)
|
||||||
if not r.ok or len(r.text) == 0:
|
if not r.ok or len(r.text) == 0:
|
||||||
|
Reference in New Issue
Block a user