diff --git a/fbchat/__init__.py b/fbchat/__init__.py index 412d42e..5ce8559 100644 --- a/fbchat/__init__.py +++ b/fbchat/__init__.py @@ -15,7 +15,7 @@ from .client import * __copyright__ = 'Copyright 2015 by Taehoon Kim' -__version__ = '0.0.2' +__version__ = '0.0.3' __license__ = 'BSD' __author__ = 'Taehoon Kim' __email__ = 'carpedm20@gmail.com' diff --git a/fbchat/client.py b/fbchat/client.py index aa382de..fbe8acb 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -65,7 +65,7 @@ class Client(object): self.threads = [] self.threads = [] - self.data = data + def _console(self, msg): if self.debug: print(msg) @@ -150,12 +150,12 @@ class Client(object): r = self._get("https://www.facebook.com/ajax/typeahead/search.php", payload) self.j = j = get_json(r.text) self.r = r - + users = [] for entry in j['payload']['entries']: if entry['type'] == 'user': users.append(User(entry)) - return users + return users # have bug TypeError: __repr__ returned non-string (type bytes) def sendMessage(self, message, thread_id): timestamp = now() @@ -193,7 +193,7 @@ class Client(object): 'message_batch[0][has_attachment]' : False } - r = self._post("https://www.facebook.com/ajax/mercury/send_messages.php", form) + r = self._post("https://www.facebook.com/ajax/mercury/send_messages.php", data) return r.ok def getThreadList(self, start, end=None): diff --git a/fbchat/utils.py b/fbchat/utils.py index 82ab364..868a2bb 100644 --- a/fbchat/utils.py +++ b/fbchat/utils.py @@ -1,7 +1,7 @@ import re import json from time import time - +from random import random, choice USER_AGENTS = [ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/601.1.10 (KHTML, like Gecko) Version/8.0.5 Safari/601.1.10", @@ -15,7 +15,7 @@ def now(): return int(time()*1000) def get_json(text): - return json.loads(re.sub(r"for.*(;;).*;", '', text.decode("unicode-escape").encode('utf-8'), 1)) + return json.loads(re.sub(r"for.*(.*;.*;.*).*;", '', text.encode('utf-8').decode("unicode-escape"), 1)) def digit_to_char(digit): if digit < 10: @@ -34,4 +34,3 @@ def generateMessageID(client_id=None): k = now() l = int(random() * 4294967295) return ("<%s:%s-%s@mail.projektitan.com>" % (k, l, client_id)); - diff --git a/setup.py b/setup.py index a96e7ad..ec05f26 100644 --- a/setup.py +++ b/setup.py @@ -57,6 +57,7 @@ setup( 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Programming Language :: Python',