Compare commits

...

8 Commits

Author SHA1 Message Date
Mads Marquart
a0b978004c Bump version: 1.7.2 → 1.7.3 2019-07-20 17:09:03 +02:00
Mads Marquart
efc8776e70 Fix login check, close #446
Facebook changed something internally, so that the redirected url is no longer always "/home.php", but instead sometimes just "/"
2019-07-20 17:01:54 +02:00
Szczepan Wiśniowski
915f9a3782 Add heart reaction (#445) 2019-07-20 16:21:44 +02:00
Mads Marquart
e136d77ade Fix 2FA login error, closes #442, replaces #443 2019-07-20 16:00:32 +02:00
Mads Marquart
04aec15833 Fix documentation badge 2019-07-04 00:43:34 +02:00
Mads Marquart
dd5e1024db Bump version: 1.7.1 → 1.7.2 2019-07-04 00:34:11 +02:00
Mads Marquart
31d13f8fae Fix #441, introduced in bc551a6 2019-07-04 00:33:08 +02:00
Mads Marquart
19b4d929e2 Add bump2version (to avoid mistakes like pushing wrong tag names) 2019-07-04 00:25:05 +02:00
8 changed files with 34 additions and 11 deletions

7
.bumpversion.cfg Normal file
View File

@@ -0,0 +1,7 @@
[bumpversion]
current_version = 1.7.3
commit = True
tag = True
[bumpversion:file:fbchat/__init__.py]

View File

@@ -9,7 +9,7 @@ fbchat: Facebook Chat (Messenger) for Python
:target: https://pypi.python.org/pypi/fbchat :target: https://pypi.python.org/pypi/fbchat
:alt: Supported python versions: 2.7, 3.4, 3.5, 3.6, 3.7 and pypy :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 :target: https://fbchat.readthedocs.io
:alt: Documentation :alt: Documentation

View File

@@ -13,7 +13,7 @@ from ._client import Client
from ._util import log # TODO: Remove this (from examples too) from ._util import log # TODO: Remove this (from examples too)
__title__ = "fbchat" __title__ = "fbchat"
__version__ = "1.7.1" __version__ = "1.7.3"
__description__ = "Facebook Chat (Messenger) for Python" __description__ = "Facebook Chat (Messenger) for Python"
__copyright__ = "Copyright 2015 - 2019 by Taehoon Kim" __copyright__ = "Copyright 2015 - 2019 by Taehoon Kim"

View File

@@ -251,7 +251,12 @@ class Client(object):
for i in range(1, max_tries + 1): for i in range(1, max_tries + 1):
try: 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() uid = state.get_user_id()
if uid is None: if uid is None:
raise FBchatException("Could not find user id") raise FBchatException("Could not find user id")

View File

@@ -35,6 +35,7 @@ class EmojiSize(Enum):
class MessageReaction(Enum): class MessageReaction(Enum):
"""Used to specify a message reaction""" """Used to specify a message reaction"""
HEART = ""
LOVE = "😍" LOVE = "😍"
SMILE = "😆" SMILE = "😆"
WOW = "😮" WOW = "😮"

View File

@@ -24,6 +24,12 @@ def session_factory(user_agent=None):
return session 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): def _2fa_helper(session, code, r):
soup = find_input_fields(r.text) soup = find_input_fields(r.text)
data = dict() data = dict()
@@ -39,7 +45,7 @@ def _2fa_helper(session, code, r):
r = session.post(url, data=data) r = session.post(url, data=data)
if "home" in r.url: if is_home(r.url):
return r return r
del data["approvals_code"] 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] # At this stage, we have dtsg, nh, name_action_selected, submit[Continue]
r = session.post(url, data=data) r = session.post(url, data=data)
if "home" in r.url: if is_home(r.url):
return r return r
del data["name_action_selected"] del data["name_action_selected"]
@@ -60,7 +66,7 @@ def _2fa_helper(session, code, r):
# At this stage, we have dtsg, nh, submit[Continue] # At this stage, we have dtsg, nh, submit[Continue]
r = session.post(url, data=data) r = session.post(url, data=data)
if "home" in r.url: if is_home(r.url):
return r return r
del data["submit[Continue]"] 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] # At this stage, we have dtsg, nh, submit[This was me]
r = session.post(url, data=data) r = session.post(url, data=data)
if "home" in r.url: if is_home(r.url):
return r return r
del data["submit[This was me]"] del data["submit[This was me]"]
@@ -107,7 +113,7 @@ class State(object):
} }
@classmethod @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) session = session_factory(user_agent=user_agent)
soup = find_input_fields(session.get("https://m.facebook.com/").text) soup = find_input_fields(session.get("https://m.facebook.com/").text)
@@ -131,7 +137,7 @@ class State(object):
if "save-device" in r.url: if "save-device" in r.url:
r = session.get("https://m.facebook.com/login/save-device/cancel/") 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) return cls.from_session(session=session)
else: else:
raise _exception.FBchatUserError( 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 # 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" url = "https://m.facebook.com/login.php?login_attempt=1"
r = self._session.get(url, allow_redirects=False) 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): def logout(self):
logout_h = self._logout_h logout_h = self._logout_h

View File

@@ -136,7 +136,7 @@ def handle_payload_error(j):
def handle_graphql_errors(j): def handle_graphql_errors(j):
errors = [] errors = []
if "error" in j: if j.get("error"):
errors = [j["error"]] errors = [j["error"]]
if "errors" in j: if "errors" in j:
errors = j["errors"] errors = j["errors"]

View File

@@ -60,3 +60,7 @@ docs = [
lint = [ lint = [
"black", "black",
] ]
tools = [
# Fork of bumpversion, see https://github.com/c4urself/bump2version
"bump2version~=0.5.0",
]