From c84fca30a2318df87de693699bf755942cfd058c Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 15 Dec 2018 21:40:44 +0100
Subject: [PATCH] Refactor Venue and Location
---
.../types/messages_and_media/location.py | 17 ++++++++++-
.../client/types/messages_and_media/venue.py | 28 +++++++++++++------
2 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/pyrogram/client/types/messages_and_media/location.py b/pyrogram/client/types/messages_and_media/location.py
index be8c839f..3ab9bfa7 100644
--- a/pyrogram/client/types/messages_and_media/location.py
+++ b/pyrogram/client/types/messages_and_media/location.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
+from pyrogram.api import types
from pyrogram.api.core import Object
@@ -32,6 +33,20 @@ class Location(Object):
ID = 0xb0700012
- def __init__(self, longitude: float, latitude: float):
+ def __init__(self, longitude: float, latitude: float, *,
+ client=None, raw=None):
self.longitude = longitude
self.latitude = latitude
+
+ self._client = client
+ self._raw = raw
+
+ @staticmethod
+ def parse(client, geo_point: types.GeoPoint) -> "Location":
+ if isinstance(geo_point, types.GeoPoint):
+ return Location(
+ longitude=geo_point.long,
+ latitude=geo_point.lat,
+ client=client,
+ raw=geo_point
+ )
diff --git a/pyrogram/client/types/messages_and_media/venue.py b/pyrogram/client/types/messages_and_media/venue.py
index 3c5b2b05..8225c36b 100644
--- a/pyrogram/client/types/messages_and_media/venue.py
+++ b/pyrogram/client/types/messages_and_media/venue.py
@@ -16,7 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
+from pyrogram.api import types
from pyrogram.api.core import Object
+from .location import Location
class Venue(Object):
@@ -43,16 +45,26 @@ class Venue(Object):
ID = 0xb0700013
- def __init__(
- self,
- location,
- title: str,
- address: str,
- foursquare_id: str = None,
- foursquare_type: str = None
- ):
+ def __init__(self, location, title: str, address: str, *,
+ foursquare_id: str = None, foursquare_type: str = None,
+ client=None, raw=None):
self.location = location
self.title = title
self.address = address
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
+
+ self._client = client
+ self._raw = raw
+
+ @staticmethod
+ def parse(client, venue: types.MessageMediaVenue):
+ return Venue(
+ location=Location.parse(client, venue.geo),
+ title=venue.title,
+ address=venue.address,
+ foursquare_id=venue.venue_id or None,
+ foursquare_type=venue.venue_type,
+ client=client,
+ raw=venue
+ )