Merge branch 'master' of http://github.com/pidgeyl/fbchat
This commit is contained in:
@@ -19,6 +19,12 @@ from bs4 import BeautifulSoup as bs
|
|||||||
from .utils import *
|
from .utils import *
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
|
# URLs
|
||||||
|
LoginURL ="https://m.facebook.com/login.php?login_attempt=1"
|
||||||
|
SearchURL ="https://www.facebook.com/ajax/typeahead/search.php"
|
||||||
|
SendURL ="https://www.facebook.com/ajax/mercury/send_messages.php"
|
||||||
|
MessagesURL="https://www.facebook.com/ajax/mercury/threadlist_info.php"
|
||||||
|
|
||||||
class Client(object):
|
class Client(object):
|
||||||
"""A client for the Facebook Chat (Messenger).
|
"""A client for the Facebook Chat (Messenger).
|
||||||
|
|
||||||
@@ -81,13 +87,13 @@ class Client(object):
|
|||||||
if not (self.email and self.password):
|
if not (self.email and self.password):
|
||||||
raise Exception("id and password or config is needed")
|
raise Exception("id and password or config is needed")
|
||||||
|
|
||||||
soup = bs(self._get("https://m.facebook.com/").text)
|
soup = bs(self._get("https://m.facebook.com/").text, "lxml")
|
||||||
data = dict((elem['name'], elem['value']) for elem in soup.findAll("input") if elem.has_attr('value') and elem.has_attr('name'))
|
data = dict((elem['name'], elem['value']) for elem in soup.findAll("input") if elem.has_attr('value') and elem.has_attr('name'))
|
||||||
data['email'] = self.email
|
data['email'] = self.email
|
||||||
data['pass'] = self.password
|
data['pass'] = self.password
|
||||||
data['login'] = 'Log In'
|
data['login'] = 'Log In'
|
||||||
|
|
||||||
r = self._post("https://m.facebook.com/login.php?login_attempt=1", data)
|
r = self._post(LoginURL, data)
|
||||||
self.r = r
|
self.r = r
|
||||||
|
|
||||||
if 'home' in r.url:
|
if 'home' in r.url:
|
||||||
@@ -146,7 +152,7 @@ class Client(object):
|
|||||||
'__rev' : self.rev,
|
'__rev' : self.rev,
|
||||||
}
|
}
|
||||||
|
|
||||||
r = self._get("https://www.facebook.com/ajax/typeahead/search.php", payload)
|
r = self._get(SearchURL, payload)
|
||||||
self.j = j = get_json(r.text)
|
self.j = j = get_json(r.text)
|
||||||
self.r = r
|
self.r = r
|
||||||
|
|
||||||
@@ -192,9 +198,10 @@ class Client(object):
|
|||||||
'message_batch[0][has_attachment]' : False
|
'message_batch[0][has_attachment]' : False
|
||||||
}
|
}
|
||||||
|
|
||||||
r = self._post("https://www.facebook.com/ajax/mercury/send_messages.php", data)
|
r = self._post(SendURL, data)
|
||||||
return r.ok
|
return r.ok
|
||||||
|
|
||||||
|
|
||||||
def getThreadList(self, start, end=None):
|
def getThreadList(self, start, end=None):
|
||||||
if not end:
|
if not end:
|
||||||
end = start + 20
|
end = start + 20
|
||||||
@@ -213,8 +220,8 @@ class Client(object):
|
|||||||
'inbox[limit]' : end,
|
'inbox[limit]' : end,
|
||||||
}
|
}
|
||||||
|
|
||||||
r = self._post("https://www.facebook.com/ajax/mercury/threadlist_info.php", data)
|
r = self._post(MessagesURL, data)
|
||||||
if not r.ok:
|
if not r.ok or len(r.text) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
j = get_json(r.text)
|
j = get_json(r.text)
|
||||||
|
Reference in New Issue
Block a user