Compare commits

...

4 Commits

Author SHA1 Message Date
Mads Marquart
8d25540445 Version up, thanks to @kapi2289 2019-02-03 22:07:44 +01:00
Mads Marquart
6ea174bfd4 Merge pull request #389 from kapi2289/fix-388
Fix #388 issue
2019-02-03 22:06:26 +01:00
Kacper Ziubryniewicz
56e43aec0e Apply suggestions and fixes from review 2019-02-03 19:03:43 +01:00
Kacper Ziubryniewicz
491d120c25 Fix #388 issue 2019-02-03 14:45:10 +01:00
2 changed files with 42 additions and 41 deletions

View File

@@ -10,7 +10,7 @@ from __future__ import unicode_literals
from .client import * from .client import *
__title__ = "fbchat" __title__ = "fbchat"
__version__ = "1.6.2" __version__ = "1.6.3"
__description__ = "Facebook Chat (Messenger) for Python" __description__ = "Facebook Chat (Messenger) for Python"
__copyright__ = "Copyright 2015 - 2019 by Taehoon Kim" __copyright__ = "Copyright 2015 - 2019 by Taehoon Kim"

View File

@@ -142,19 +142,22 @@ def graphql_to_extensible_attachment(a):
if target: if target:
_type = target["__typename"] _type = target["__typename"]
if _type == "MessageLocation": if _type == "MessageLocation":
url = story.get("url")
latitude, longitude = get_url_parameter( latitude, longitude = get_url_parameter(
get_url_parameter(story["url"], "u"), "where1" get_url_parameter(url, "u"), "where1"
).split(", ") ).split(", ")
rtn = LocationAttachment( rtn = LocationAttachment(
uid=int(story["deduplication_key"]), uid=int(story["deduplication_key"]),
latitude=float(latitude), latitude=float(latitude),
longitude=float(longitude), longitude=float(longitude),
) )
if story["media"]: media = story.get("media")
rtn.image_url = story["media"]["image"]["uri"] if media and media.get("image"):
rtn.image_width = story["media"]["image"]["width"] image = media["image"]
rtn.image_height = story["media"]["image"]["height"] rtn.image_url = image.get("uri")
rtn.url = story["url"] rtn.image_width = image.get("width")
rtn.image_height = image.get("height")
rtn.url = url
return rtn return rtn
elif _type == "MessageLiveLocation": elif _type == "MessageLiveLocation":
rtn = LiveLocationAttachment( rtn = LiveLocationAttachment(
@@ -166,53 +169,50 @@ def graphql_to_extensible_attachment(a):
if story["target"].get("coordinate") if story["target"].get("coordinate")
else None, else None,
name=story["title_with_entities"]["text"], name=story["title_with_entities"]["text"],
expiration_time=story["target"]["expiration_time"] expiration_time=story["target"].get("expiration_time"),
if story["target"].get("expiration_time") is_expired=story["target"].get("is_expired"),
else None,
is_expired=story["target"]["is_expired"],
) )
if story["media"]: media = story.get("media")
rtn.image_url = story["media"]["image"]["uri"] if media and media.get("image"):
rtn.image_width = story["media"]["image"]["width"] image = media["image"]
rtn.image_height = story["media"]["image"]["height"] rtn.image_url = image.get("uri")
rtn.url = story["url"] rtn.image_width = image.get("width")
rtn.image_height = image.get("height")
rtn.url = story.get("url")
return rtn return rtn
elif _type in ["ExternalUrl", "Story"]: elif _type in ["ExternalUrl", "Story"]:
return ShareAttachment( url = story.get("url")
rtn = ShareAttachment(
uid=a.get("legacy_attachment_id"), uid=a.get("legacy_attachment_id"),
author=story["target"]["actors"][0]["id"] author=story["target"]["actors"][0]["id"]
if story["target"].get("actors") if story["target"].get("actors")
else None, else None,
url=story["url"], url=url,
original_url=get_url_parameter(story["url"], "u") original_url=get_url_parameter(url, "u")
if "/l.php?u=" in story["url"] if "/l.php?u=" in url
else story["url"], else url,
title=story["title_with_entities"].get("text"), title=story["title_with_entities"].get("text"),
description=story["description"].get("text") description=story["description"].get("text")
if story.get("description") if story.get("description")
else None, else None,
source=story["source"]["text"], source=story["source"].get("text"),
image_url=story["media"]["image"]["uri"]
if story.get("media")
else None,
original_image_url=(
get_url_parameter(story["media"]["image"]["uri"], "url")
if "/safe_image.php" in story["media"]["image"]["uri"]
else story["media"]["image"]["uri"]
)
if story.get("media")
else None,
image_width=story["media"]["image"]["width"]
if story.get("media")
else None,
image_height=story["media"]["image"]["height"]
if story.get("media")
else None,
attachments=[ attachments=[
graphql_to_subattachment(attachment) graphql_to_subattachment(attachment)
for attachment in story.get("subattachments") for attachment in story.get("subattachments")
], ],
) )
media = story.get("media")
if media and media.get("image"):
image = media["image"]
rtn.image_url = image.get("uri")
rtn.original_image_url = (
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
else: else:
return UnsentMessage(uid=a.get("legacy_attachment_id")) return UnsentMessage(uid=a.get("legacy_attachment_id"))
@@ -220,10 +220,11 @@ def graphql_to_extensible_attachment(a):
def graphql_to_subattachment(a): def graphql_to_subattachment(a):
_type = a["target"]["__typename"] _type = a["target"]["__typename"]
if _type == "Video": if _type == "Video":
media = a["media"]
return VideoAttachment( return VideoAttachment(
duration=a["media"].get("playable_duration_in_ms"), duration=media.get("playable_duration_in_ms"),
preview_url=a["media"].get("playable_url"), preview_url=media.get("playable_url"),
medium_image=a["media"].get("image"), medium_image=media.get("image"),
uid=a["target"].get("video_id"), uid=a["target"].get("video_id"),
) )