diff --git a/fbchat/client.py b/fbchat/client.py index 594c180..8eb38d5 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -12,7 +12,6 @@ from .utils import * from .models import * from .graphql import * import time -import json @@ -1425,7 +1424,7 @@ class Client(object): mentions = [] if delta.get('data') and delta['data'].get('prng'): try: - mentions = [Mention(str(mention.get('i')), offset=mention.get('o'), length=mention.get('l')) for mention in json.loads(delta['data']['prng'])] + mentions = [Mention(str(mention.get('i')), offset=mention.get('o'), length=mention.get('l')) for mention in parse_json(delta['data']['prng'])] except Exception: log.exception('An exception occured while reading attachments') diff --git a/fbchat/utils.py b/fbchat/utils.py index 25c29f7..8777aa7 100644 --- a/fbchat/utils.py +++ b/fbchat/utils.py @@ -142,6 +142,9 @@ def get_decoded_r(r): def get_decoded(content): return content.decode(facebookEncoding) +def parse_json(content): + return json.loads(content) + def get_json(r): return json.loads(strip_to_json(get_decoded_r(r)))