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

LocationAttachment fix #395

Merged
merged 11 commits into from
Feb 19, 2019
14 changes: 9 additions & 5 deletions fbchat/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,17 @@ def graphql_to_extensible_attachment(a):
_type = target["__typename"]
if _type == "MessageLocation":
url = story.get("url")
latitude, longitude = get_url_parameter(
get_url_parameter(url, "u"), "where1"
).split(", ")
address = get_url_parameter(get_url_parameter(url, "u"), "where1")
try:
latitude, longitude = [float(x) for x in address.split(", ")]
address = None
except ValueError:
latitude, longitude = None, None
rtn = LocationAttachment(
uid=int(story["deduplication_key"]),
latitude=float(latitude),
longitude=float(longitude),
latitude=latitude,
longitude=longitude,
address=address,
)
media = story.get("media")
if media and media.get("image"):
Expand Down
9 changes: 7 additions & 2 deletions fbchat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ def __init__(


class LocationAttachment(Attachment):
#: Latidute of the location
"""Latitude and longitude OR address is provided by Facebook"""

#: Latitude of the location
latitude = None
#: Longitude of the location
longitude = None
Expand All @@ -456,12 +458,15 @@ class LocationAttachment(Attachment):
image_height = None
#: URL to Bing maps with the location
url = None
# Address of the location
address = None

def __init__(self, latitude=None, longitude=None, **kwargs):
def __init__(self, latitude=None, longitude=None, address=None, **kwargs):
madsmtm marked this conversation as resolved.
Show resolved Hide resolved
"""Represents a user location"""
super(LocationAttachment, self).__init__(**kwargs)
self.latitude = latitude
self.longitude = longitude
self.address = address


class LiveLocationAttachment(LocationAttachment):
Expand Down