{"id":305818,"date":"2020-06-23T15:01:36","date_gmt":"2020-06-23T15:01:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=305818"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=305818","title":{"rendered":"\u0411\u043e\u0442 Telegram \u0434\u043b\u044f \u043f\u0438\u0446\u0446\u0435\u0440\u0438\u0438 \u043d\u0430 Python \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e telebot"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/507840\/\">\n<h2 id=\"vstuplenie\">\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u041d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0443\u0436\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/448310\/\">\u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u043e Telegram \u0431\u043e\u0442\u0435, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u043c \u043d\u0430 Python \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e telebot. \u041f\u0440\u0438\u0437\u043d\u0430\u0442\u044c\u0441\u044f, \u0441\u0432\u043e\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441 \u0447\u0430\u0442-\u0431\u043e\u0442\u0430\u043c\u0438 \u0432 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440\u0435 \u044f \u043d\u0430\u0447\u0438\u043d\u0430\u043b \u0441 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438. \u041c\u043e\u044f \u043f\u0438\u0441\u0430\u043d\u0438\u043d\u0430 \u2014 \u044d\u0442\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0435 \u0432 \u0441\u0435\u0431\u044f \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 Inline \u043a\u043d\u043e\u043f\u043a\u0430\u043c\u0438 \u0438 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<h2 id=\"ustanovka-biblioteki\">\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/h2>\n<p>  <\/p>\n<p>Telebot \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 Telegram API, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u043b\u0430 \u043c\u0435\u043d\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432 \u043e\u043d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0432\u0441\u0435 100%.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u0432\u0432\u0435\u0434\u0438\u0442\u0435 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443.<\/p>\n<p>  <\/p>\n<p><code>pip install pytelegrambotapi<\/code><\/p>\n<p>  <\/p>\n<h2 id=\"poluchenie-api-tokena\">\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 API-\u0442\u043e\u043a\u0435\u043d\u0430<\/h2>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0431\u043e\u0442\u0430, \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a &quot;\u043e\u0442\u0446\u0443&quot; \u0432\u0441\u0435\u0445 \u0431\u043e\u0442\u043e\u0432 \u2014 @BotFather. \u041e\u0442\u043f\u0440\u0430\u0432\u044c\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>\/newbot<\/code>, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u0432\u0435\u0434\u0438\u0442\u0435 \u0438\u043c\u044f \u0431\u043e\u0442\u0430, \u0437\u0430\u0442\u0435\u043c \u0430\u043b\u0438\u0430\u0441, \u043e\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u043d\u0430 <strong>bot<\/strong>.<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/72\/u5\/qq\/72u5qqmfvjy1tqwrv_rm1anfnd8.jpeg\" alt=\"image\"  width=\"360\"\/><\/div>\n<p>  <\/p>\n<h2 id=\"pishem-kod\">\u041f\u0438\u0448\u0435\u043c \u043a\u043e\u0434<\/h2>\n<p>  <\/p>\n<p>\u041b\u0443\u0447\u0448\u0435 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c API-\u0442\u043e\u043a\u0435\u043d\u044b, \u043d\u043e\u043c\u0435\u0440\u0430 \u043a\u043e\u0448\u0435\u043b\u044c\u043a\u0430 \u0438 \u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <strong>config.py<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">TOKEN = &quot;1176585885:AAH-RA2kZym9E5tR8JFLtYYjNxrMHnsJr0o&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 bot.py <\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u0438\u043c\u043f\u043e\u0440\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 import telebot  # \u041f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d \u0431\u043e\u0442\u0430 \u0438 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0437\u0430 \u043f\u0438\u0446\u0446\u0443 from config import TOKEN  # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u043e\u0442\u0430 bot = telebot.TeleBot(TOKEN)  # \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0441\u0435\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 @bot.message_handler(content_types=['text']) def all_messages(msg):     # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f     message = msg.text      # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c Telegram id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u043d \u0441\u0432\u043e\u0439)     user_id = msg.chat.id      # \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435     bot.send_message(user_id, f&quot;\u0412\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438: {message}&quot;)  # \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0431\u043e\u0442\u0430, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b 24\/7 if __name__ == '__main__':     bot.polling(none_stop=True)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u044d\u0445\u043e-\u0431\u043e\u0442\u0430. \u041f\u043e\u0434\u0443\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c \u0431\u043e\u0442\u0435:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0411\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u043d\u0435\u0439 \u0445\u0440\u0430\u043d\u0438\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u0438\u0446\u0446\u0435. \u0414\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0411\u0414 \u043b\u0443\u0447\u0448\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u2014 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0438\u0446\u0446\u044b. <\/li>\n<li>\u041a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b. \u041f\u043e\u043c\u043e\u0433\u0443\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0443\u0434\u043e\u0431\u043d\u044b\u043c.\u00a0<\/li>\n<li>\u041e\u043f\u043b\u0430\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 QIWI.<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"baza-dannyh\">\u0411\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>  <\/p>\n<p>\u042f \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c SQLiteStudio \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>  <\/p>\n<p><strong>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/strong><\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/wr\/uc\/eu\/wruceunendmbnyxfhrwlqqvrmeu.png\"\/><\/p>\n<p>  <\/p>\n<ul>\n<li><strong>id<\/strong> \u2014 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0422\u0430\u043a\u0438\u043c \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0435\u0437 \u0437\u0430\u0437\u0440\u0435\u043d\u0438\u044f \u0441\u043e\u0432\u0435\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e. <\/li>\n<li><strong>stat<\/strong> \u2014 \u0441\u0442\u0430\u0442\u0443\u0441 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u043e\u0442\u043e\u043c. \u0417\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u043d\u0430 \u043a\u0430\u043a\u043e\u043c \u0448\u0430\u0433\u0435 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c.<\/li>\n<li><strong>ord<\/strong>. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0445\u0440\u0430\u043d\u0438\u043c \u0437\u0430\u043a\u0430\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041f\u043e\u043a\u0430 \u044f \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0439\u0442\u0435 \u0438\u0434\u0435\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/li>\n<li><strong>random_code<\/strong>. \u0412 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0431\u0443\u0434\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u043e\u043f\u043b\u0430\u0442\u044b \u0447\u0435\u0440\u0435\u0437 QIWI.<\/li>\n<li><strong>time<\/strong>. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u043a\u0430\u0437, \u0430 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u044d\u0442\u043e \u043f\u043e\u043b\u0435.<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u043f\u0438\u0446\u0446\u044b<\/strong><\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ga\/lq\/lo\/galqlooo4whiz1gfokq6twefkpi.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043f\u0438\u0446\u0446\u0430\u043c:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/x_\/tz\/se\/x_tzsexk70t17i0q2wvyd08mzri.png\"\/><\/p>\n<p>  <\/p>\n<p>\u041f\u043e <strong>name<\/strong> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0438\u0446\u0446\u044b \u0438 \u0435\u0451 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c.\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044e. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e data, \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043c \u0432 \u043d\u0435\u0435 img, \u0430 \u0443\u0436\u0435 \u0442\u0430\u043c \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. <\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/0e\/zs\/b1\/0ezsb1zl-sgfdnplo5swabcawtg.png\"\/><\/p>\n<p>  <\/p>\n<h3 id=\"klassy-dlya-vzaimodeystviya-s-bazoy-dannyh\">\u041a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>  <\/p>\n<p>\u0422\u0430\u043a, \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0437\u0434\u0430\u043b\u0438, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043a\u043b\u0430\u0441\u0441\u0430\u043c. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b user.py, \u0432 \u043d\u0451\u043c \u043a\u043b\u0430\u0441\u0441 User. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0430\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 import sqlite3  class User:     # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0411\u0414     def connect_to_db(self):         self.connect = sqlite3.connect('PizzaApplication.db')         self.cursor = self.connect.cursor()      # \u0417\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0411\u0414     def close(self):         self.connect.close()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0411\u043e\u0442\u0430 \u043e\u0442\u043a\u0440\u044b\u043b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u044e\u0437\u0435\u0440\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0412\u0442\u043e\u0440\u043e\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0432\u0448\u0435\u0433\u043e &quot;\/start&quot; \u0432 \u0411\u0414. <\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c id \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043f\u043e\u0437\u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u044d\u0442\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435     def get_all_id(self):         self.connect_to_db()         request = &quot;SELECT id FROM user&quot;         result = self.cursor.execute(request).fetchall()         self.close()          return [i[0] for i in result]      # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f     def add_id_to_db(self, user_id):         self.connect_to_db()         request = &quot;INSERT INTO user(id, stat) VALUES(?, ?)&quot;         self.cursor.execute(request, (user_id, &quot;start&quot;))         self.connect.commit()         self.close()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u043f\u043e\u043b\u0435\u0439, \u043d\u043e \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0442\u0430\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u0430\u044f, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0435.\u00a0<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">    # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u043f\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e     def get_field(self, user_id, field):         self.connect_to_db()         request = f&quot;SELECT {field} FROM user WHERE id=?&quot;         result = self.cursor.execute(request, (user_id,)).fetchone()         self.close()         return result[0]      # \u041c\u0435\u043d\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f     def set_field(self, user_id, field, value):         self.connect_to_db()         request = f&quot;UPDATE user SET {field}=? WHERE id=?&quot;         self.cursor.execute(request, (value, user_id))         self.connect.commit()         self.close()<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b. \u041f\u043e\u0437\u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443, \u0430 \u043f\u043e\u043a\u0430 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043f\u0438\u0446\u0446\u0435. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b pizza.py, \u0432 \u043d\u0451\u043c \u043a\u043b\u0430\u0441\u0441 Pizza. \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0442\u0430\u043a\u0438\u0435 \u0436\u0435, \u043a\u0430\u043a \u0443 User. <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import sqlite3  class Pizza:     # \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445     def connect_to_db(self):         self.connect = sqlite3.connect('PizzaApplication.db')         self.cursor = self.connect.cursor()      # \u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445     def close(self):         self.connect.close()<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0411\u0414. <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">    def get_field(self, pizza_name, field):         self.connect_to_db()         request = f&quot;SELECT {field} FROM pizza WHERE name=?&quot;         result = self.cursor.execute(request, (pizza_name,)).fetchone()         self.close()          return result[0]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0430\u0434\u043c\u0438\u043d-\u043f\u0430\u043d\u0435\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f set_field (\u043f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u0435\u0441\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 User), \u043d\u043e \u0435\u0451 \u044f \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043b. <\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b \u0438 \u043d\u0430\u0447\u043d\u0451\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 bot.py. <strong>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/strong><\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/507840\/\"> https:\/\/habr.com\/ru\/post\/507840\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/507840\/\">\n<h2 id=\"vstuplenie\">\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u041d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0443\u0436\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/448310\/\">\u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u043e Telegram \u0431\u043e\u0442\u0435, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u043c \u043d\u0430 Python \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e telebot. \u041f\u0440\u0438\u0437\u043d\u0430\u0442\u044c\u0441\u044f, \u0441\u0432\u043e\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441 \u0447\u0430\u0442-\u0431\u043e\u0442\u0430\u043c\u0438 \u0432 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440\u0435 \u044f \u043d\u0430\u0447\u0438\u043d\u0430\u043b \u0441 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438. \u041c\u043e\u044f \u043f\u0438\u0441\u0430\u043d\u0438\u043d\u0430 \u2014 \u044d\u0442\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0435 \u0432 \u0441\u0435\u0431\u044f \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 Inline \u043a\u043d\u043e\u043f\u043a\u0430\u043c\u0438 \u0438 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<h2 id=\"ustanovka-biblioteki\">\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/h2>\n<p>  <\/p>\n<p>Telebot \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 Telegram API, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u043b\u0430 \u043c\u0435\u043d\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432 \u043e\u043d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0432\u0441\u0435 100%.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-305818","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/305818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=305818"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/305818\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=305818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=305818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=305818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}