Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a0b978004c | ||
|
efc8776e70 | ||
|
915f9a3782 | ||
|
e136d77ade | ||
|
04aec15833 | ||
|
dd5e1024db | ||
|
31d13f8fae | ||
|
19b4d929e2 |
7
.bumpversion.cfg
Normal file
7
.bumpversion.cfg
Normal file
@@ -0,0 +1,7 @@
|
||||
[bumpversion]
|
||||
current_version = 1.7.3
|
||||
commit = True
|
||||
tag = True
|
||||
|
||||
[bumpversion:file:fbchat/__init__.py]
|
||||
|
@@ -9,7 +9,7 @@ fbchat: Facebook Chat (Messenger) for Python
|
||||
:target: https://pypi.python.org/pypi/fbchat
|
||||
:alt: Supported python versions: 2.7, 3.4, 3.5, 3.6, 3.7 and pypy
|
||||
|
||||
.. image:: https://readthedocs.org/projects/fbchat/badge/?version=master
|
||||
.. image:: https://readthedocs.org/projects/fbchat/badge/?version=latest
|
||||
:target: https://fbchat.readthedocs.io
|
||||
:alt: Documentation
|
||||
|
||||
|
@@ -13,7 +13,7 @@ from ._client import Client
|
||||
from ._util import log # TODO: Remove this (from examples too)
|
||||
|
||||
__title__ = "fbchat"
|
||||
__version__ = "1.7.1"
|
||||
__version__ = "1.7.3"
|
||||
__description__ = "Facebook Chat (Messenger) for Python"
|
||||
|
||||
__copyright__ = "Copyright 2015 - 2019 by Taehoon Kim"
|
||||
|
@@ -251,7 +251,12 @@ class Client(object):
|
||||
|
||||
for i in range(1, max_tries + 1):
|
||||
try:
|
||||
state = State.login(email, password, user_agent=user_agent)
|
||||
state = State.login(
|
||||
email,
|
||||
password,
|
||||
on_2fa_callback=self.on2FACode,
|
||||
user_agent=user_agent,
|
||||
)
|
||||
uid = state.get_user_id()
|
||||
if uid is None:
|
||||
raise FBchatException("Could not find user id")
|
||||
|
@@ -35,6 +35,7 @@ class EmojiSize(Enum):
|
||||
class MessageReaction(Enum):
|
||||
"""Used to specify a message reaction"""
|
||||
|
||||
HEART = "❤"
|
||||
LOVE = "😍"
|
||||
SMILE = "😆"
|
||||
WOW = "😮"
|
||||
|
@@ -24,6 +24,12 @@ def session_factory(user_agent=None):
|
||||
return session
|
||||
|
||||
|
||||
def is_home(url):
|
||||
parts = _util.urlparse(url)
|
||||
# Check the urls `/home.php` and `/`
|
||||
return "home" in parts.path or "/" == parts.path
|
||||
|
||||
|
||||
def _2fa_helper(session, code, r):
|
||||
soup = find_input_fields(r.text)
|
||||
data = dict()
|
||||
@@ -39,7 +45,7 @@ def _2fa_helper(session, code, r):
|
||||
|
||||
r = session.post(url, data=data)
|
||||
|
||||
if "home" in r.url:
|
||||
if is_home(r.url):
|
||||
return r
|
||||
|
||||
del data["approvals_code"]
|
||||
@@ -52,7 +58,7 @@ def _2fa_helper(session, code, r):
|
||||
# At this stage, we have dtsg, nh, name_action_selected, submit[Continue]
|
||||
r = session.post(url, data=data)
|
||||
|
||||
if "home" in r.url:
|
||||
if is_home(r.url):
|
||||
return r
|
||||
|
||||
del data["name_action_selected"]
|
||||
@@ -60,7 +66,7 @@ def _2fa_helper(session, code, r):
|
||||
# At this stage, we have dtsg, nh, submit[Continue]
|
||||
r = session.post(url, data=data)
|
||||
|
||||
if "home" in r.url:
|
||||
if is_home(r.url):
|
||||
return r
|
||||
|
||||
del data["submit[Continue]"]
|
||||
@@ -69,7 +75,7 @@ def _2fa_helper(session, code, r):
|
||||
# At this stage, we have dtsg, nh, submit[This was me]
|
||||
r = session.post(url, data=data)
|
||||
|
||||
if "home" in r.url:
|
||||
if is_home(r.url):
|
||||
return r
|
||||
|
||||
del data["submit[This was me]"]
|
||||
@@ -107,7 +113,7 @@ class State(object):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def login(cls, email, password, user_agent=None):
|
||||
def login(cls, email, password, on_2fa_callback, user_agent=None):
|
||||
session = session_factory(user_agent=user_agent)
|
||||
|
||||
soup = find_input_fields(session.get("https://m.facebook.com/").text)
|
||||
@@ -131,7 +137,7 @@ class State(object):
|
||||
if "save-device" in r.url:
|
||||
r = session.get("https://m.facebook.com/login/save-device/cancel/")
|
||||
|
||||
if "home" in r.url:
|
||||
if is_home(r.url):
|
||||
return cls.from_session(session=session)
|
||||
else:
|
||||
raise _exception.FBchatUserError(
|
||||
@@ -143,7 +149,7 @@ class State(object):
|
||||
# Send a request to the login url, to see if we're directed to the home page
|
||||
url = "https://m.facebook.com/login.php?login_attempt=1"
|
||||
r = self._session.get(url, allow_redirects=False)
|
||||
return "Location" in r.headers and "home" in r.headers["Location"]
|
||||
return "Location" in r.headers and is_home(r.headers["Location"])
|
||||
|
||||
def logout(self):
|
||||
logout_h = self._logout_h
|
||||
|
@@ -136,7 +136,7 @@ def handle_payload_error(j):
|
||||
|
||||
def handle_graphql_errors(j):
|
||||
errors = []
|
||||
if "error" in j:
|
||||
if j.get("error"):
|
||||
errors = [j["error"]]
|
||||
if "errors" in j:
|
||||
errors = j["errors"]
|
||||
|
@@ -60,3 +60,7 @@ docs = [
|
||||
lint = [
|
||||
"black",
|
||||
]
|
||||
tools = [
|
||||
# Fork of bumpversion, see https://github.com/c4urself/bump2version
|
||||
"bump2version~=0.5.0",
|
||||
]
|
||||
|
Reference in New Issue
Block a user