Merge pull request #87 from MKolman/python3-patch
Fixes the issue #60 for Python3
This commit is contained in:
@@ -133,12 +133,12 @@ class Client(object):
|
|||||||
def _cleanPost(self, url, query=None, timeout=30):
|
def _cleanPost(self, url, query=None, timeout=30):
|
||||||
self.req_counter += 1
|
self.req_counter += 1
|
||||||
return self._session.post(url, headers=self._header, data=query, timeout=timeout)
|
return self._session.post(url, headers=self._header, data=query, timeout=timeout)
|
||||||
|
|
||||||
def _postFile(self, url, files=None, timeout=30):
|
def _postFile(self, url, files=None, timeout=30):
|
||||||
payload=self._generatePayload(None)
|
payload=self._generatePayload(None)
|
||||||
return self._session.post(url, data=payload, timeout=timeout, files=files)
|
return self._session.post(url, data=payload, timeout=timeout, files=files)
|
||||||
|
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
if not (self.email and self.password):
|
if not (self.email and self.password):
|
||||||
raise Exception("id and password or config is needed")
|
raise Exception("id and password or config is needed")
|
||||||
@@ -282,12 +282,12 @@ class Client(object):
|
|||||||
'has_attachment' : image_id != None,
|
'has_attachment' : image_id != None,
|
||||||
'other_user_fbid' : recipient_id,
|
'other_user_fbid' : recipient_id,
|
||||||
'specific_to_list[0]' : 'fbid:' + str(recipient_id),
|
'specific_to_list[0]' : 'fbid:' + str(recipient_id),
|
||||||
'specific_to_list[1]' : 'fbid:' + str(self.uid),
|
'specific_to_list[1]' : 'fbid:' + str(self.uid),
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if image_id:
|
if image_id:
|
||||||
@@ -310,7 +310,7 @@ class Client(object):
|
|||||||
|
|
||||||
def sendRemoteImage(self, recipient_id, message=None, message_type='user', image=''):
|
def sendRemoteImage(self, recipient_id, message=None, message_type='user', image=''):
|
||||||
"""Send an image from a URL
|
"""Send an image from a URL
|
||||||
|
|
||||||
:param recipient_id: the user id or thread id that you want to send a message to
|
:param recipient_id: the user id or thread id that you want to send a message to
|
||||||
:param message: a text that you want to send
|
:param message: a text that you want to send
|
||||||
:param message_type: determines if the recipient_id is for user or thread
|
:param message_type: determines if the recipient_id is for user or thread
|
||||||
@@ -320,10 +320,10 @@ class Client(object):
|
|||||||
remote_image = requests.get(image).content
|
remote_image = requests.get(image).content
|
||||||
image_id = self.uploadImage({'file': (image, remote_image, mimetype)})
|
image_id = self.uploadImage({'file': (image, remote_image, mimetype)})
|
||||||
return self.send(recipient_id, message, message_type, None, image_id)
|
return self.send(recipient_id, message, message_type, None, image_id)
|
||||||
|
|
||||||
def sendLocalImage(self, recipient_id, message=None, message_type='user', image=''):
|
def sendLocalImage(self, recipient_id, message=None, message_type='user', image=''):
|
||||||
"""Send an image from a file path
|
"""Send an image from a file path
|
||||||
|
|
||||||
:param recipient_id: the user id or thread id that you want to send a message to
|
:param recipient_id: the user id or thread id that you want to send a message to
|
||||||
:param message: a text that you want to send
|
:param message: a text that you want to send
|
||||||
:param message_type: determines if the recipient_id is for user or thread
|
:param message_type: determines if the recipient_id is for user or thread
|
||||||
@@ -332,13 +332,15 @@ class Client(object):
|
|||||||
mimetype = guess_type(image)[0]
|
mimetype = guess_type(image)[0]
|
||||||
image_id = self.uploadImage({'file': (image, open(image), mimetype)})
|
image_id = self.uploadImage({'file': (image, open(image), mimetype)})
|
||||||
return self.send(recipient_id, message, message_type, None, image_id)
|
return self.send(recipient_id, message, message_type, None, image_id)
|
||||||
|
|
||||||
def uploadImage(self, image):
|
def uploadImage(self, image):
|
||||||
"""Upload an image and get the image_id for sending in a message
|
"""Upload an image and get the image_id for sending in a message
|
||||||
|
|
||||||
:param image: a tuple of (file name, data, mime type) to upload to facebook
|
:param image: a tuple of (file name, data, mime type) to upload to facebook
|
||||||
"""
|
"""
|
||||||
r = self._postFile(UploadURL, image)
|
r = self._postFile(UploadURL, image)
|
||||||
|
if isinstance(r._content, str) is False:
|
||||||
|
r._content = r._content.decode("utf-8")
|
||||||
# Strip the start and parse out the returned image_id
|
# Strip the start and parse out the returned image_id
|
||||||
return json.loads(r._content[9:])['payload']['metadata'][0]['image_id']
|
return json.loads(r._content[9:])['payload']['metadata'][0]['image_id']
|
||||||
|
|
||||||
@@ -580,13 +582,13 @@ class Client(object):
|
|||||||
break
|
break
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def getUserInfo(self,*user_ids):
|
def getUserInfo(self,*user_ids):
|
||||||
"""Get user info from id. Unordered.
|
"""Get user info from id. Unordered.
|
||||||
|
|
||||||
:param user_ids: one or more user id(s) to query
|
:param user_ids: one or more user id(s) to query
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = {"ids[{}]".format(i):user_id for i,user_id in enumerate(user_ids)}
|
data = {"ids[{}]".format(i):user_id for i,user_id in enumerate(user_ids)}
|
||||||
r = self._post(UserInfoURL, data)
|
r = self._post(UserInfoURL, data)
|
||||||
info = get_json(r.text)
|
info = get_json(r.text)
|
||||||
|
Reference in New Issue
Block a user