Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- token = 'твой токен'
- url = 'https://api.telegram.org/bot{}/'.format(token)
- def get_updates(offset=None):
- while True:
- try:
- URL = url + 'getUpdates'
- if offset:
- URL += '?offset={}'.format(offset)
- res = requests.get(URL)
- while (res.status_code != 200 or len(res.json()['result']) == 0):
- sleep(1)
- res = requests.get(URL)
- print(res.url)
- return res.json()
- except:
- pass
- def get_last(data):
- results = data['result']
- count = len(results)
- last = count - 1
- last_update = results[last]
- return last_update
- def get_last_id_text(updates):
- last_update = get_last(updates)
- chat_id = last_update['message']['chat']['id']
- update_id = last_update['update_id']
- try:
- text = last_update['message']['text']
- except:
- text = ''
- return chat_id, text, update_id
- def ask_location(chat_id):
- text = 'Где ты?'
- keyboard = [[{"text": "Отправить местоположение", "request_location": True}]]
- reply_markup = {"keyboard": keyboard, "one_time_keyboard": True}
- send_message(chat_id, text, json.dumps(reply_markup))
- def get_location(update_id):
- updates = get_updates(update_id+1)
- location = get_last(updates)['message']['location']
- chat_id, text, update_id = get_last_id_text(updates)
- lat = str(location['latitude'])
- lon = str(location['longitude'])
- return lat, lon, update_id
- lat, lon, update_id = get_location(update_id) # твои координаты
Advertisement
Add Comment
Please, Sign In to add comment