Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4a8ef00442 |
@@ -1,5 +1,10 @@
|
|||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from datetime import datetime
|
||||||
|
from .client import *
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
fbchat
|
fbchat
|
||||||
~~~~~~
|
~~~~~~
|
||||||
@@ -10,11 +15,9 @@
|
|||||||
:license: BSD, see LICENSE for more details.
|
:license: BSD, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from .client import *
|
|
||||||
|
|
||||||
__copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year)
|
__copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year)
|
||||||
__version__ = '1.0.1'
|
__version__ = '1.0.3'
|
||||||
__license__ = 'BSD'
|
__license__ = 'BSD'
|
||||||
__author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart'
|
__author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart'
|
||||||
__email__ = 'carpedm20@gmail.com'
|
__email__ = 'carpedm20@gmail.com'
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import requests
|
import requests
|
||||||
import urllib
|
import urllib
|
||||||
|
import traceback
|
||||||
from uuid import uuid1
|
from uuid import uuid1
|
||||||
from random import choice
|
from random import choice
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -420,7 +421,8 @@ class Client(object):
|
|||||||
|
|
||||||
for key in j['payload']:
|
for key in j['payload']:
|
||||||
k = j['payload'][key]
|
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
|
return users
|
||||||
|
|
||||||
@@ -1298,9 +1300,6 @@ class Client(object):
|
|||||||
Does one cycle of the listening loop.
|
Does one cycle of the listening loop.
|
||||||
This method is useful if you want to control fbchat from an external event 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
|
:param markAlive: Whether this should ping the Facebook server before running
|
||||||
:type markAlive: bool
|
:type markAlive: bool
|
||||||
:return: Whether the loop should keep running
|
:return: Whether the loop should keep running
|
||||||
@@ -1380,7 +1379,7 @@ class Client(object):
|
|||||||
|
|
||||||
:param exception: The exception that was encountered
|
: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={}):
|
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))
|
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
|
Called when the client just started listening
|
||||||
|
|
||||||
|
@@ -108,17 +108,17 @@ def now():
|
|||||||
def strip_to_json(text):
|
def strip_to_json(text):
|
||||||
try:
|
try:
|
||||||
return text[text.index('{'):]
|
return text[text.index('{'):]
|
||||||
except ValueError as e:
|
except ValueError:
|
||||||
return None
|
raise Exception('No JSON object found: {}, {}'.format(repr(text), text.index('{')))
|
||||||
|
|
||||||
def get_decoded(r):
|
def get_decoded_r(r):
|
||||||
if not isinstance(r._content, str):
|
return get_decoded(r._content)
|
||||||
return r._content.decode(facebookEncoding)
|
|
||||||
else:
|
def get_decoded(content):
|
||||||
return r._content
|
return content.decode(facebookEncoding)
|
||||||
|
|
||||||
def get_json(r):
|
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):
|
def digitToChar(digit):
|
||||||
if digit < 10:
|
if digit < 10:
|
||||||
@@ -162,16 +162,17 @@ def checkRequest(r, do_json_check=True):
|
|||||||
if not r.ok:
|
if not r.ok:
|
||||||
raise Exception('Error when sending request: Got {} response'.format(r.status_code))
|
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:
|
if content is None or len(content) == 0:
|
||||||
raise Exception('Error when sending request: Got empty response')
|
raise Exception('Error when sending request: Got empty response')
|
||||||
|
|
||||||
if do_json_check:
|
if do_json_check:
|
||||||
|
content = strip_to_json(content)
|
||||||
try:
|
try:
|
||||||
j = json.loads(strip_to_json(content))
|
j = json.loads(content)
|
||||||
except Exception as e:
|
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)
|
check_json(j)
|
||||||
return j
|
return j
|
||||||
else:
|
else:
|
||||||
|
2
setup.py
2
setup.py
@@ -17,7 +17,7 @@ with open('README.rst') as f:
|
|||||||
readme_content = f.read().strip()
|
readme_content = f.read().strip()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
requirements = [line.rstrip('\n') for line in open('fbchat.egg-info/requires.txt')]
|
requirements = [line.rstrip('\n') for line in open(os.path.join('fbchat.egg-info', 'requires.txt'))]
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
requirements = [line.rstrip('\n') for line in open('requirements.txt')]
|
requirements = [line.rstrip('\n') for line in open('requirements.txt')]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user