Merge pull request #7 from wannaphongcom/master
Fix login and sendMessage
This commit is contained in:
@@ -15,7 +15,7 @@ from .client import *
|
|||||||
|
|
||||||
|
|
||||||
__copyright__ = 'Copyright 2015 by Taehoon Kim'
|
__copyright__ = 'Copyright 2015 by Taehoon Kim'
|
||||||
__version__ = '0.0.2'
|
__version__ = '0.0.3'
|
||||||
__license__ = 'BSD'
|
__license__ = 'BSD'
|
||||||
__author__ = 'Taehoon Kim'
|
__author__ = 'Taehoon Kim'
|
||||||
__email__ = 'carpedm20@gmail.com'
|
__email__ = 'carpedm20@gmail.com'
|
||||||
|
@@ -65,7 +65,7 @@ class Client(object):
|
|||||||
|
|
||||||
self.threads = []
|
self.threads = []
|
||||||
self.threads = []
|
self.threads = []
|
||||||
self.data = data
|
|
||||||
|
|
||||||
def _console(self, msg):
|
def _console(self, msg):
|
||||||
if self.debug: print(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)
|
r = self._get("https://www.facebook.com/ajax/typeahead/search.php", payload)
|
||||||
self.j = j = get_json(r.text)
|
self.j = j = get_json(r.text)
|
||||||
self.r = r
|
self.r = r
|
||||||
|
|
||||||
users = []
|
users = []
|
||||||
for entry in j['payload']['entries']:
|
for entry in j['payload']['entries']:
|
||||||
if entry['type'] == 'user':
|
if entry['type'] == 'user':
|
||||||
users.append(User(entry))
|
users.append(User(entry))
|
||||||
return users
|
return users # have bug TypeError: __repr__ returned non-string (type bytes)
|
||||||
|
|
||||||
def sendMessage(self, message, thread_id):
|
def sendMessage(self, message, thread_id):
|
||||||
timestamp = now()
|
timestamp = now()
|
||||||
@@ -193,7 +193,7 @@ 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", form)
|
r = self._post("https://www.facebook.com/ajax/mercury/send_messages.php", data)
|
||||||
return r.ok
|
return r.ok
|
||||||
|
|
||||||
def getThreadList(self, start, end=None):
|
def getThreadList(self, start, end=None):
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
from time import time
|
from time import time
|
||||||
|
from random import random, choice
|
||||||
USER_AGENTS = [
|
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_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",
|
"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)
|
return int(time()*1000)
|
||||||
|
|
||||||
def get_json(text):
|
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):
|
def digit_to_char(digit):
|
||||||
if digit < 10:
|
if digit < 10:
|
||||||
@@ -34,4 +34,3 @@ def generateMessageID(client_id=None):
|
|||||||
k = now()
|
k = now()
|
||||||
l = int(random() * 4294967295)
|
l = int(random() * 4294967295)
|
||||||
return ("<%s:%s-%s@mail.projektitan.com>" % (k, l, client_id));
|
return ("<%s:%s-%s@mail.projektitan.com>" % (k, l, client_id));
|
||||||
|
|
||||||
|
1
setup.py
1
setup.py
@@ -57,6 +57,7 @@ setup(
|
|||||||
'Programming Language :: Python :: 3.3',
|
'Programming Language :: Python :: 3.3',
|
||||||
'Programming Language :: Python :: 3.3',
|
'Programming Language :: Python :: 3.3',
|
||||||
'Programming Language :: Python :: 3.4',
|
'Programming Language :: Python :: 3.4',
|
||||||
|
'Programming Language :: Python :: 3.5',
|
||||||
'Programming Language :: Python :: Implementation :: CPython',
|
'Programming Language :: Python :: Implementation :: CPython',
|
||||||
'Programming Language :: Python :: Implementation :: PyPy',
|
'Programming Language :: Python :: Implementation :: PyPy',
|
||||||
'Programming Language :: Python',
|
'Programming Language :: Python',
|
||||||
|
Reference in New Issue
Block a user