Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor model parsing #406

Merged
merged 31 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0383d61
Move ActiveStatus pull parsing into the model
madsmtm Mar 7, 2019
403870e
Move emojisize pull parsing into the model
madsmtm Mar 7, 2019
d940b64
Move enum_extend_if_invalid -> Enum._extend_if_invalid
madsmtm Mar 7, 2019
279f637
Move graphql_color_to_enum -> ThreadColor._from_graphql
madsmtm Mar 7, 2019
3440039
Move graphql_to_sticker -> Sticker._from_graphql
madsmtm Mar 7, 2019
e51ce99
Move graphql_to_poll_option -> PollOption._from_graphql
madsmtm Mar 7, 2019
0578ea2
Move graphql_to_poll -> Poll._from_graphql
madsmtm Mar 7, 2019
c28ca58
Add missing attributes to Poll and PollOption `__init__`
madsmtm Mar 7, 2019
c374aca
Fix _util exception import
madsmtm Mar 7, 2019
ee207e9
Move graphql_to_live_location -> LiveLocationAttachment._from_pull
madsmtm Mar 7, 2019
2ce99a2
Split graphql_to_extensible_attachment into smaller methods
madsmtm Mar 7, 2019
789d9d8
Split graphql_to_attachment into smaller methods
madsmtm Mar 7, 2019
9682236
Move plan parsing to the Plan model
madsmtm Mar 10, 2019
ce469d5
Move get_customization_info -> Thread._parse_customization_info
madsmtm Mar 10, 2019
3a5185f
Move graphql_to_user -> User._from_graphql
madsmtm Mar 10, 2019
60ebbd8
Move graphql_to_thread user parsing to User._from_thread_fetch
madsmtm Mar 10, 2019
fd5553a
Move graphql_to_group -> Group._from_graphql
madsmtm Mar 10, 2019
cb2c68e
Move graphql_to_page -> Page._from_graphql
madsmtm Mar 10, 2019
0b99238
Move subattachment parsing to the respective models
madsmtm Mar 10, 2019
53856a3
Move attachment and subattachment dispatching to _file.py
madsmtm Mar 10, 2019
6693ec9
Move graphql_to_extensible_attachment into _message.py
madsmtm Mar 10, 2019
e579e0c
Move graphql_to_quick_reply into _quick_reply.py
madsmtm Mar 10, 2019
1f961b2
Move thread parser dispatching into _client.py
madsmtm Mar 10, 2019
f20a04b
Move graphql_to_message -> Message._from_graphql
madsmtm Mar 10, 2019
28c867a
Simplify _graphql.py imports
madsmtm Mar 10, 2019
e166b47
Move message pull parsing into Message._from_pull
madsmtm Mar 10, 2019
71f19dd
Move fetchAllUsers parsing into User._from_all_fetch
madsmtm Mar 10, 2019
8e6ee46
Move gender dict into _user.py
madsmtm Mar 10, 2019
6636d49
Remove graphql.py
madsmtm Mar 10, 2019
18ec1f5
Merge branch 'master' into refactor-model-parsing
madsmtm Apr 17, 2019
86a6e07
Merge branch 'master' into refactor-model-parsing
madsmtm Apr 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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