aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-03-05 16:59:37 +0100
committerAlex Auvolat <alex@adnab.me>2020-03-05 16:59:37 +0100
commit62dae5a0a2ad9cead08aa13810561e9436d5a40f (patch)
treee9f219c5dcfce4363014720a48b43941f9c266ef
parentb7090546a9baf7ca95f5709ca1ec9f09879078a4 (diff)
downloadeasybridge-62dae5a0a2ad9cead08aa13810561e9436d5a40f.tar.gz
easybridge-62dae5a0a2ad9cead08aa13810561e9436d5a40f.zip
`client_pickle` messenger configuration param
so that a serialized client object can be passed, bypassing the need to re-login at each restart
-rw-r--r--connector/external/config.go5
-rwxr-xr-xexternal/messenger.py49
2 files changed, 34 insertions, 20 deletions
diff --git a/connector/external/config.go b/connector/external/config.go
index 03e1feb..9c8e123 100644
--- a/connector/external/config.go
+++ b/connector/external/config.go
@@ -45,7 +45,10 @@ func init() {
Name: "password",
Description: "Password",
IsPassword: true,
- Required: true,
+ },
+ &ConfigEntry{
+ Name: "client_pickle",
+ Description: "Client pickle (alternative login method)",
},
&ConfigEntry{
Name: "initial_backlog",
diff --git a/external/messenger.py b/external/messenger.py
index b5dd2d3..cd175e1 100755
--- a/external/messenger.py
+++ b/external/messenger.py
@@ -10,6 +10,9 @@ import time
import traceback
from urllib.parse import unquote as UrlUnquote
+import base64
+import getpass
+import zlib
import hashlib
import fbchat
@@ -210,27 +213,17 @@ class MessengerBridge:
self.init_backlog_length = int(cmd["data"]["initial_backlog"])
client_file = "/tmp/fbclient_" + hashlib.sha224(cmd["data"]["email"].encode("utf-8")).hexdigest()
- try:
- f = open(client_file, "rb")
- self.client = pickle.load(f)
- f.close()
- sys.stderr.write("(python messenger) using previous client: {}\n".format(client_file))
- except:
- self.client = None
-
- if self.client is None:
+ if "client_pickle" in cmd["data"]:
+ data = base64.b64decode(cmd["data"]["client_pickle"])
+ data = zlib.decompress(data)
+ self.client = pickle.loads(data)
+ else:
email, password = cmd["data"]["email"], cmd["data"]["password"]
self.client = MessengerBridgeClient(email=email, password=password, max_tries=1)
+ ## TODO: save client in new client_pickle config value
if not self.client.isLoggedIn():
- return {"_type": "rep_error", "error": "Unable to login (?)"}
-
- try:
- f = open(client_file, "wb")
- pickle.dump(self.client, f)
- f.close()
- except:
- pass
+ return {"_type": "rep_error", "error": "Unable to login (invalid pickle?)"}
self.client.setBridge(self)
@@ -524,7 +517,25 @@ class MessengerBridge:
"data": {"name": new_title},
})
+# ---- CLI ----
+
+def createClientPickle():
+ email = input("Email address of Facebook account: ")
+ password = getpass.getpass()
+ client = MessengerBridgeClient(email, password, max_tries=1)
+ if not client.isLoggedIn():
+ print("Could not log in (why???)")
+ return
+ print("")
+ data = pickle.dumps(client)
+ data = zlib.compress(data)
+ data = base64.b64encode(data).decode('ascii')
+ print(data)
+
if __name__ == "__main__":
- bridge = MessengerBridge()
- bridge.run()
+ if "create_client_pickle" in sys.argv:
+ createClientPickle()
+ else:
+ bridge = MessengerBridge()
+ bridge.run()