Fix LocationAttachment (#395)

Set `LocationAttachment.address` instead of `latitude` and `longitude`, when no GPS coords are supplied. Fixes #392
This commit is contained in:
darylkell
2019-02-19 19:19:20 +08:00
committed by Mads Marquart
parent dfc2d0652f
commit caa2ecd0b7
2 changed files with 16 additions and 7 deletions

View File

@@ -143,13 +143,17 @@ def graphql_to_extensible_attachment(a):
_type = target["__typename"] _type = target["__typename"]
if _type == "MessageLocation": if _type == "MessageLocation":
url = story.get("url") url = story.get("url")
latitude, longitude = get_url_parameter( address = get_url_parameter(get_url_parameter(url, "u"), "where1")
get_url_parameter(url, "u"), "where1" try:
).split(", ") latitude, longitude = [float(x) for x in address.split(", ")]
address = None
except ValueError:
latitude, longitude = None, None
rtn = LocationAttachment( rtn = LocationAttachment(
uid=int(story["deduplication_key"]), uid=int(story["deduplication_key"]),
latitude=float(latitude), latitude=latitude,
longitude=float(longitude), longitude=longitude,
address=address,
) )
media = story.get("media") media = story.get("media")
if media and media.get("image"): if media and media.get("image"):

View File

@@ -444,7 +444,9 @@ class ShareAttachment(Attachment):
class LocationAttachment(Attachment): class LocationAttachment(Attachment):
#: Latidute of the location """Latitude and longitude OR address is provided by Facebook"""
#: Latitude of the location
latitude = None latitude = None
#: Longitude of the location #: Longitude of the location
longitude = None longitude = None
@@ -456,12 +458,15 @@ class LocationAttachment(Attachment):
image_height = None image_height = None
#: URL to Bing maps with the location #: URL to Bing maps with the location
url = None 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):
"""Represents a user location""" """Represents a user location"""
super(LocationAttachment, self).__init__(**kwargs) super(LocationAttachment, self).__init__(**kwargs)
self.latitude = latitude self.latitude = latitude
self.longitude = longitude self.longitude = longitude
self.address = address
class LiveLocationAttachment(LocationAttachment): class LiveLocationAttachment(LocationAttachment):