2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Refactor Venue and Location

This commit is contained in:
Dan 2018-12-15 21:40:44 +01:00
parent e5e0b17809
commit c84fca30a2
2 changed files with 36 additions and 9 deletions

View File

@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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
)

View File

@ -16,7 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
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
)