2

I am scraping telegram and I could get every message instance with client.iter_messages in a chat but I want to get the latitude and longitude of the location if the message instance is a location share message.

for message in client.iter_messages('John'):
     print(message.text)   #prints message
     ------------------    #I want the latitude and longitude of the location if the message is a location share message and not a text message

A little help would be appreciated, Thank You.

Dr.Die_OXide
  • 300
  • 2
  • 18

1 Answers1

3

First act only when the message is a location share message (message.geo), else no need

location = message.geo   #returns a GeoPoint class if the message is a location share message else returns None
if location is not None:
     longitude = location.long
     latitude = location.lat
     print(longitude, latitude)
Lonami
  • 5,945
  • 2
  • 20
  • 38
Dr.Die_OXide
  • 300
  • 2
  • 18