Fixed a few bugs, updated to v. 1.0.3
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from datetime import datetime
|
||||
from .client import *
|
||||
|
||||
|
||||
"""
|
||||
fbchat
|
||||
~~~~~~
|
||||
@@ -10,11 +15,9 @@
|
||||
:license: BSD, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from .client import *
|
||||
|
||||
__copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year)
|
||||
__version__ = '1.0.1'
|
||||
__version__ = '1.0.3'
|
||||
__license__ = 'BSD'
|
||||
__author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart'
|
||||
__email__ = 'carpedm20@gmail.com'
|
||||
|
@@ -3,6 +3,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import requests
|
||||
import urllib
|
||||
import traceback
|
||||
from uuid import uuid1
|
||||
from random import choice
|
||||
from datetime import datetime
|
||||
@@ -420,7 +421,8 @@ class Client(object):
|
||||
|
||||
for key in j['payload']:
|
||||
k = j['payload'][key]
|
||||
users.append(User(k['id'], first_name=k['firstName'], url=k['uri'], photo=k['thumbSrc'], name=k['name'], is_friend=k['is_friend'], gender=GENDERS[k['gender']]))
|
||||
if k['type'] in ['user', 'friend']:
|
||||
users.append(User(k['id'], first_name=k.get('firstName'), url=k.get('uri'), photo=k.get('thumbSrc'), name=k.get('name'), is_friend=k.get('is_friend'), gender=GENDERS[k.get('gender')]))
|
||||
|
||||
return users
|
||||
|
||||
@@ -1298,9 +1300,6 @@ class Client(object):
|
||||
Does one cycle of the listening loop.
|
||||
This method is useful if you want to control fbchat from an external event loop
|
||||
|
||||
.. note::
|
||||
markAlive is currently broken, and is ignored
|
||||
|
||||
:param markAlive: Whether this should ping the Facebook server before running
|
||||
:type markAlive: bool
|
||||
:return: Whether the loop should keep running
|
||||
@@ -1380,7 +1379,7 @@ class Client(object):
|
||||
|
||||
:param exception: The exception that was encountered
|
||||
"""
|
||||
raise exception
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
def onMessage(self, mid=None, author_id=None, message=None, thread_id=None, thread_type=ThreadType.USER, ts=None, metadata=None, msg={}):
|
||||
@@ -1558,7 +1557,7 @@ class Client(object):
|
||||
"""
|
||||
log.info('Inbox event: {}, {}, {}'.format(unseen, unread, recent_unread))
|
||||
|
||||
def onQprimer(self, made=None, msg={}):
|
||||
def onQprimer(self, ts=None, msg={}):
|
||||
"""
|
||||
Called when the client just started listening
|
||||
|
||||
|
@@ -108,17 +108,17 @@ def now():
|
||||
def strip_to_json(text):
|
||||
try:
|
||||
return text[text.index('{'):]
|
||||
except ValueError as e:
|
||||
return None
|
||||
except ValueError:
|
||||
raise Exception('No JSON object found: {}, {}'.format(repr(text), text.index('{')))
|
||||
|
||||
def get_decoded(r):
|
||||
if not isinstance(r._content, str):
|
||||
return r._content.decode(facebookEncoding)
|
||||
else:
|
||||
return r._content
|
||||
def get_decoded_r(r):
|
||||
return get_decoded(r._content)
|
||||
|
||||
def get_decoded(content):
|
||||
return content.decode(facebookEncoding)
|
||||
|
||||
def get_json(r):
|
||||
return json.loads(strip_to_json(get_decoded(r)))
|
||||
return json.loads(strip_to_json(get_decoded_r(r)))
|
||||
|
||||
def digitToChar(digit):
|
||||
if digit < 10:
|
||||
@@ -162,16 +162,17 @@ def checkRequest(r, do_json_check=True):
|
||||
if not r.ok:
|
||||
raise Exception('Error when sending request: Got {} response'.format(r.status_code))
|
||||
|
||||
content = get_decoded(r)
|
||||
content = get_decoded_r(r)
|
||||
|
||||
if content is None or len(content) == 0:
|
||||
raise Exception('Error when sending request: Got empty response')
|
||||
|
||||
if do_json_check:
|
||||
content = strip_to_json(content)
|
||||
try:
|
||||
j = json.loads(strip_to_json(content))
|
||||
j = json.loads(content)
|
||||
except Exception as e:
|
||||
raise Exception('Error while parsing JSON: {}'.format(repr(content)))
|
||||
raise Exception('Error while parsing JSON: {}'.format(repr(content)), e)
|
||||
check_json(j)
|
||||
return j
|
||||
else:
|
||||
|
Reference in New Issue
Block a user