Skip to content

Commit 61502ed

Browse files
authored
Merge pull request #406 from carpedm20/refactor-model-parsing
Refactor model parsing
2 parents a71835a + 86a6e07 commit 61502ed

21 files changed

Lines changed: 876 additions & 870 deletions

fbchat/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
# These imports are far too general, but they're needed for backwards compatbility.
1010
from .utils import *
11-
from .graphql import *
1211
from .models import *
12+
13+
from ._graphql import graphql_queries_to_json, graphql_response_to_json, GraphQL
1314
from ._client import Client
1415

1516
__title__ = "fbchat"

fbchat/_attachment.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import unicode_literals
33

44
import attr
5+
from . import _util
56

67

78
@attr.s(cmp=False)
@@ -46,3 +47,40 @@ class ShareAttachment(Attachment):
4647

4748
# Put here for backwards compatibility, so that the init argument order is preserved
4849
uid = attr.ib(None)
50+
51+
@classmethod
52+
def _from_graphql(cls, data):
53+
from . import _file
54+
55+
url = data.get("url")
56+
rtn = cls(
57+
uid=data.get("deduplication_key"),
58+
author=data["target"]["actors"][0]["id"]
59+
if data["target"].get("actors")
60+
else None,
61+
url=url,
62+
original_url=_util.get_url_parameter(url, "u")
63+
if "/l.php?u=" in url
64+
else url,
65+
title=data["title_with_entities"].get("text"),
66+
description=data["description"].get("text")
67+
if data.get("description")
68+
else None,
69+
source=data["source"].get("text"),
70+
attachments=[
71+
_file.graphql_to_subattachment(attachment)
72+
for attachment in data.get("subattachments")
73+
],
74+
)
75+
media = data.get("media")
76+
if media and media.get("image"):
77+
image = media["image"]
78+
rtn.image_url = image.get("uri")
79+
rtn.original_image_url = (
80+
_util.get_url_parameter(rtn.image_url, "url")
81+
if "/safe_image.php" in rtn.image_url
82+
else rtn.image_url
83+
)
84+
rtn.image_width = image.get("width")
85+
rtn.image_height = image.get("height")
86+
return rtn

0 commit comments

Comments
 (0)