d_skat

Untitled

May 11th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. def get_updates(offset=None):
  2.     while True:
  3.         try:
  4.             URL = url + 'getUpdates'
  5.             if offset:
  6.                 URL += '?offset={}'.format(offset)
  7.  
  8.             res = requests.get(URL)
  9.             while (res.status_code != 200 or len(res.json()['result']) == 0):
  10.                 sleep(1)
  11.                 res = requests.get(URL)
  12.             print(res.url)
  13.             return res.json()
  14.  
  15.         except:
  16.             pass
  17.  
  18.  
  19. def get_last(data):
  20.     results = data['result']
  21.     count = len(results)
  22.     last = count - 1
  23.     last_update = results[last]
  24.     return last_update
  25.  
  26.  
  27. def get_last_id_text(updates):
  28.     last_update = get_last(updates)
  29.     chat_id = last_update['message']['chat']['id']
  30.     update_id = last_update['update_id']
  31.     try:
  32.         text = last_update['message']['text']
  33.     except:
  34.         text = ''
  35.     return chat_id, text, update_id
  36.  
  37.  
  38. def main():
  39.     chat_id, text, update_id = get_last_id_text(get_updates())
  40.     chat_id, text, update_id = start(chat_id)
  41.  
  42.     while text.lower() != 'y':
  43.         sleep(1)
  44.         text = 'начать!'
  45.         menu(chat_id, text, update_id)
  46.         chat_id, text, update_id = get_last_id_text(get_updates())
  47.         text = end(chat_id, text, update_id)
Advertisement
Add Comment
Please, Sign In to add comment