Skip to content

Commit

Permalink
Merge pull request #406 from carpedm20/refactor-model-parsing
Browse files Browse the repository at this point in the history
Refactor model parsing
  • Loading branch information
madsmtm authored Apr 25, 2019
2 parents a71835a + 86a6e07 commit 61502ed
Show file tree
Hide file tree
Showing 21 changed files with 876 additions and 870 deletions.
3 changes: 2 additions & 1 deletion fbchat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

# These imports are far too general, but they're needed for backwards compatbility.
from .utils import *
from .graphql import *
from .models import *

from ._graphql import graphql_queries_to_json, graphql_response_to_json, GraphQL
from ._client import Client

__title__ = "fbchat"
Expand Down
38 changes: 38 additions & 0 deletions fbchat/_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

import attr
from . import _util


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

# Put here for backwards compatibility, so that the init argument order is preserved
uid = attr.ib(None)

@classmethod
def _from_graphql(cls, data):
from . import _file

url = data.get("url")
rtn = cls(
uid=data.get("deduplication_key"),
author=data["target"]["actors"][0]["id"]
if data["target"].get("actors")
else None,
url=url,
original_url=_util.get_url_parameter(url, "u")
if "/l.php?u=" in url
else url,
title=data["title_with_entities"].get("text"),
description=data["description"].get("text")
if data.get("description")
else None,
source=data["source"].get("text"),
attachments=[
_file.graphql_to_subattachment(attachment)
for attachment in data.get("subattachments")
],
)
media = data.get("media")
if media and media.get("image"):
image = media["image"]
rtn.image_url = image.get("uri")
rtn.original_image_url = (
_util.get_url_parameter(rtn.image_url, "url")
if "/safe_image.php" in rtn.image_url
else rtn.image_url
)
rtn.image_width = image.get("width")
rtn.image_height = image.get("height")
return rtn
Loading

0 comments on commit 61502ed

Please sign in to comment.