{"id":298296,"date":"2020-02-06T09:00:22","date_gmt":"2020-02-06T09:00:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=298296"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=298296","title":{"rendered":"\u0410\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430 \u0434\u043b\u044f Telegram-\u0431\u043e\u0442\u043e\u0432, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 Python"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/487208\/\">\u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0443\u043c \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c-\u0431\u043e\u0442\u043e\u0432 \u043d\u0430\u0447\u0430\u043b \u0441\u0445\u043e\u0434\u0438\u0442\u044c, \u043d\u043e \u0442\u0435\u043c\u0430 \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0435 \u0442\u0435\u0440\u044f\u0435\u0442 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 Telegram Bot API, \u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u043e\u0442\u0430 \u044f \u0442\u0430\u043a \u0438 \u043d\u0435 \u043d\u0430\u0448\u0451\u043b \u0441\u043a\u0440\u0438\u043f\u0442\u0430(\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438) \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0431\u043e\u0442\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0431\u043e\u0442\u043e\u0432 \u043d\u0430 Python. \u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c, \u043b\u043e\u0433\u0438\u0440\u0443\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044f \u043b\u043e\u0433\u0438 \u0432 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0432\u0438\u0434.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/webt\/gs\/0b\/nj\/gs0bnjjso8jrzyea-6-p6wibb4y.png\"\/><\/div>\n<p> <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0440\u0435\u0434\u044b<\/h2>\n<p>  \u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<pre><code class=\"python\">pip install datetime pip install pandas<\/code><\/pre>\n<p>  <\/p>\n<h2>\u041a\u0430\u043a \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0443 \u0432 \u0441\u0432\u043e\u0435\u0433\u043e \u0431\u043e\u0442\u0430?<\/h2>\n<p>  \u0421\u043a\u0430\u0447\u0430\u0439\u0442\u0435 \u0441 <a href=\"https:\/\/github.com\/AleksandSP\/tg_analytic\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/a> py-\u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u043e\u0434 \u0441\u0432\u043e\u044e \u041e\u0421 \u0438 data.csv \u0444\u0430\u0439\u043b. \u0420\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u0435 \u0438\u0445 \u0432 \u043f\u0430\u043f\u043a\u0435, \u0433\u0434\u0435 \u043b\u0435\u0436\u0438\u0442 \u0432\u0430\u0448 \u0431\u043e\u0442.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432\u0430\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0432 \u0444\u0430\u0439\u043b\u0435 \u0441 \u0442\u0435\u043b\u043e\u043c \u0431\u043e\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"python\">import tg_analytic <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 \u0431\u043e\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435:<\/p>\n<pre><code class=\"python\">tg_analytic.statistics(&lt;id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f&gt;, &lt;\u043a\u043e\u043c\u0430\u043d\u0434\u0430&gt;) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 telebot, \u0442\u043e \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/webt\/xq\/5h\/gf\/xq5hgfrewdj9sjbqlh8dlto7pj4.png\"\/><\/div>\n<p>  \u0422\u0430\u043a\u0436\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u0431\u043e\u0442\u0430, \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 message_handler(content_types=[&#8216;text&#8217;]):<\/p>\n<pre><code class=\"python\">if message.text[:(\u0434\u043b\u0438\u043d\u0430 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430)] == '&lt;\u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e&gt;':         st = message.text.split(' ')         if 'txt' in st or '\u0442\u0445\u0442' in st:             tg_analytic.analysis(st,message.chat.id)             with open('%s.txt' %message.chat.id ,'r',encoding='UTF-8') as file:                 bot.send_document(message.chat.id,file)                 tg_analytic.remove(message.chat.id)         else:             messages = tg_analytic.analysis(st,message.chat.id)             bot.send_message(message.chat.id, messages)<\/code><\/pre>\n<p>  \u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0438 \u0432\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0432\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430. \u0412 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u0431\u043e\u0442 \u0441 \u0443\u0436\u0435 \u0432\u043d\u0435\u0434\u0440\u0451\u043d\u043d\u043e\u0439 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u043e\u0439, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0435\u0451 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435. <\/p>\n<h2>\u041a\u0430\u043a\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438?<\/h2>\n<p>  \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0431\u0443\u0434\u0435\u0442 \u00ab\u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430\u00bb:<\/p>\n<pre><code class=\"python\">    if message.text[:10] == '\u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430' or message.text[:10] == 'C\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430':         st = message.text.split(' ')         if 'txt' in st or '\u0442\u0445\u0442' in st:             tg_analytic.analysis(st,message.chat.id)             with open('%s.txt' %message.chat.id ,'r',encoding='UTF-8') as file:                 bot.send_document(message.chat.id,file)                 tg_analytic.remove(message.chat.id)         else:             messages = tg_analytic.analysis(st,message.chat.id)             bot.send_message(message.chat.id, messages) <\/code><\/pre>\n<p>  \u0422\u0435\u043b\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0431\u043e\u0442\u0443 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<blockquote><p>\u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 &lt;\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043d\u0435\u0439&gt; &lt;\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430*&gt;&gt;<\/p><\/blockquote>\n<p>  * \u2014 \u0415\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b: \u00ab\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438\u00bb, \u00ab\u043a\u043e\u043c\u0430\u043d\u0434\u044b\u00bb \u0438 \u00ab\u0442\u0445\u0442\u00bb. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. \u00ab\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438\u00bb \u0434\u0430\u0451\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e \u043b\u044e\u0434\u044f\u043c \u0437\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0432\u0430\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043d\u0435\u0439. \u00ab\u041a\u043e\u043c\u0430\u043d\u0434\u044b\u00bb \u0434\u0430\u0451\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c \u0437\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0432\u0430\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043d\u0435\u0439. \u041f\u0440\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 txt, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0444\u0430\u0439\u043b, \u0432 \u0438\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0432\u0435\u0442 \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434<\/h3>\n<p>  <i>C\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 2 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/i><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/webt\/8u\/bo\/9s\/8ubo9sn7lfyn4piulfsbnzijezi.png\"\/><\/div>\n<p>  <i>C\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 2 \u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/i><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/webt\/ie\/0m\/2w\/ie0m2w16qdct2snb68hikelqpm0.png\"\/><\/div>\n<p>  <i>\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 2 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0442\u0445\u0442<\/i><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/webt\/m-\/9t\/jv\/m-9tjvsidfxrjmwadksygc3-8zc.png\"\/><\/div>\n<p>  <\/p>\n<h2>\u0418\u0437 \u0447\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0441\u043a\u0440\u0438\u043f\u0442?<\/h2>\n<p>  \u0412 \u0446\u0435\u043b\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432\u0430\u0441 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u0442\u043e \u0443\u0436\u0435 \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0438 \u043d\u0430\u0447\u0430\u0442\u044c \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0432 \u0441\u0432\u043e\u0435\u0433\u043e \u0431\u043e\u0442\u0430.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u2014 \u044d\u0442\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u042f \u043f\u0440\u0438\u043d\u044f\u043b \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0430\u0442\u0443, id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0443\u044e \u0438\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code class=\"python\">def statistics(user_id, command):     data = datetime.datetime.today().strftime(&quot;%Y-%m-%d&quot;)     with open('data.csv', 'a', newline=&quot;&quot;, encoding='UTF-8') as fil:         wr = csv.writer(fil, delimiter=';')         wr.writerow([data, user_id, command])<\/code><\/pre>\n<p>  \u0412\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u2014 \u044d\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u0438 \u0432\u044b\u0432\u043e\u0434 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438. \u041c\u044b \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 csv \u0432 Pandas \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c:<\/p>\n<pre><code class=\"python\">season = int(bid[1]) #\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Dataframe df = pd.read_csv('data.csv', delimiter=';', encoding='utf8') #\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0434\u043d\u0435\u0439 number_of_users = len(df['id'].unique()) number_of_days = len(df['data'].unique()) #\u0423\u0437\u043d\u0430\u0451\u043c \u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u043e\u043f\u0440\u0435\u0434\u0451\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u043d\u0438 df_user = df.groupby(['data', 'id']).count().reset_index().groupby('data').count().reset_index() list_of_dates_in_df_user = list(df_user['data']) list_of_number_of_user_in_df_user = list(df_user['id']) list_of_dates_in_df_user = list_of_dates_in_df_user[-season:] list_of_number_of_user_in_df_user = list_of_number_of_user_in_df_user[-season:] #\u0423\u0437\u043d\u0430\u0435\u043c \u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u043f\u043e \u0434\u043d\u044f\u043c df_command = df.groupby(['data', 'command']).count().reset_index() unique_commands = df['command'].unique() commands_in_each_day = [] list_of_dates_in_df_command = list(df_command['data']) list_of_number_of_user_in_df_command = list(df_command['id']) list_of_name_of_command_in_df_command = list(df_command['command']) commands_in_this_day = dict() for i in range(len(list_of_dates_in_df_command)):      commands_in_this_day[list_of_name_of_command_in_df_command[i]] = list_of_number_of_user_in_df_command[i]      if i + 1 &gt;= len(list_of_dates_in_df_command) or list_of_dates_in_df_command[i] != list_of_dates_in_df_command[i + 1]:      commands_in_each_day.append(commands_in_this_day)      commands_in_this_day = dict() commands_in_each_day = commands_in_each_day[-season:] <\/code><\/pre>\n<p>  \u041e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0448\u0430\u0433\u0430:<\/p>\n<pre><code class=\"python\"> message_to_user = '\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u043e\u0442\u0430 \u0437\u0430 %s %s: \\n' % (season, day_type.get(season, '\u0434\u043d\u0435\u0439')) message_to_user += '\u0412\u0441\u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0441\u043e\u0431\u0440\u0430\u043d\u0430 \u0437\u0430 %s %s: \\n' % (number_of_days, day_type.get(season, '\u0434\u043d\u0435\u0439')) if season &gt; number_of_days:      season = number_of_days      message_to_user += '\u0423\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0432\u0430\u043c\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043d\u0435\u0439 \u0431\u043e\u043b\u044c\u0448\u0435,\u0447\u0435\u043c \u0438\u043c\u0435\u0435\u0442\u0441\u044f\\n' \\                         '\u0411\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0437\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f\\n' if '\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438' in bid:     message_to_user += '\u0417\u0430 \u0432\u0441\u0451 \u0432\u0440\u0435\u043c\u044f \u0431\u043e\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u043e: ' + '%s' % number_of_users \\     + ' %s ' % users_type.get(number_of_users, '\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439') + '\\n' \\     '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 %s %s: \\n' % (season, day_type.get(season, '\u0434\u043d\u0435\u0439'))     for days, number, comm_day in zip(list_of_dates_in_df_user, list_of_number_of_user_in_df_user,      commands_in_each_day):       message_to_user += '\u0414\u0430\u0442\u0430:%s \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e:%d \u0418\u0437 \u043d\u0438\u0445 \u043d\u043e\u0432\u044b\u0445:%s\\n' % (days, number, comm_day.get('\/start', 0)) if '\u043a\u043e\u043c\u0430\u043d\u0434\u044b' in bid:     message_to_user += '\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043a\u043e\u043c\u0430\u043d\u0434 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 %s %s: \\n' %       (season,day_type.get(season, '\u0434\u043d\u0435\u0439'))     for days, commands in zip(list_of_dates_in_df_user, commands_in_each_day):        message_to_user += '\u0414\u0430\u0442\u0430:%s\\n' % days        for i in unique_commands:            if i in commands:                 message_to_user += '%s - %s \u0440\u0430\u0437\\n' % (i, commands.get(i))           else:                 message_to_user += '%s - 0 \u0440\u0430\u0437\\n' % i <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0446\u0435, \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0435\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u00ab\u0442\u0445\u0442\u00bb, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u0432 \u043a\u0430\u043a\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c:<\/p>\n<pre><code class=\"python\">if 'txt' in bid or '\u0442\u0445\u0442' in bid:     with open('%s.txt' % user_id, 'w', encoding='UTF-8') as fil:         fil.write(message_to_user)         fil.close()     else:         return message_to_user <\/code><\/pre>\n<p>  <\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0421\u043a\u0440\u0438\u043f\u0442 \u043e\u0442\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0431\u043e\u0442\u0435, \u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043b\u044e\u0431\u043e\u043c \u0438\u0437 \u043c\u043e\u0438\u0445 \u0431\u043e\u0442\u043e\u0432: @exchange_minsk_bot, @pogoda_belarus_bot, @fast_translate_bot.<\/p>\n<p>  \u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e: \u00ab\u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430\u00bb.<\/p>\n<p>  \u041f\u0440\u0438\u044f\u0442\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f!<\/p><\/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\/487208\/\"> https:\/\/habr.com\/ru\/post\/487208\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/487208\/\">\u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0443\u043c \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c-\u0431\u043e\u0442\u043e\u0432 \u043d\u0430\u0447\u0430\u043b \u0441\u0445\u043e\u0434\u0438\u0442\u044c, \u043d\u043e \u0442\u0435\u043c\u0430 \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0435 \u0442\u0435\u0440\u044f\u0435\u0442 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 Telegram Bot API, \u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u043e\u0442\u0430 \u044f \u0442\u0430\u043a \u0438 \u043d\u0435 \u043d\u0430\u0448\u0451\u043b \u0441\u043a\u0440\u0438\u043f\u0442\u0430(\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438) \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0431\u043e\u0442\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0431\u043e\u0442\u043e\u0432 \u043d\u0430 Python. \u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c, \u043b\u043e\u0433\u0438\u0440\u0443\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044f \u043b\u043e\u0433\u0438 \u0432 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0432\u0438\u0434.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/webt\/gs\/0b\/nj\/gs0bnjjso8jrzyea-6-p6wibb4y.png\"\/><\/div>\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-298296","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298296","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=298296"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298296\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=298296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=298296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=298296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}