{"id":290227,"date":"2018-10-02T20:05:02","date_gmt":"2018-10-02T16:05:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=290227"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=290227","title":{"rendered":"\u041f\u043e\u0434\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u0435\u043c \u0447\u0430\u0442 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0432\u043e\u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u0417\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043a\u0430\u043a-\u0442\u043e \u043c\u043d\u0435, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0447\u0430\u0442\u043e\u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u043b\u0438\u0441\u044c \u0443 \u043c\u0435\u043d\u044f \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 (\u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044f \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430). \u041d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438\u0445 \u043f\u043e\u0431\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0442\u0438\u0432\u043e\u0432, \u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e\u0439 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0435 \u0435\u0441\u0442\u044c \u0431\u043e\u0442\u044b. \u041d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0435\u0439, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u044b\u0445 \u0431\u043e\u0442\u0430\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: &quot;<a href=\"https:\/\/habr.com\/post\/264035\/\">\u0427\u0430\u0442-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u043d\u0430 \u0441\u0430\u0439\u0442<\/a>&quot;.<\/p>\n<p>  <\/p>\n<p>\u0411\u043e\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0434\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u043e\u0442\u0430 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0442\u0435\u043b\u0435\u0444\u043e\u043d \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u043e\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u044b\u043c. \u041d\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u043e\u0442\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0441\u043b\u043e\u0432\u043e &quot;bot&quot;, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0443 \u0445\u043e\u0437\u044f\u0438\u043d\u0430 \u0447\u0430\u0442\u0430 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b. <\/p>\n<p>  <\/p>\n<p>\u041d\u043e, \u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u2014 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u043e\u043c\u0435 &quot;API telegram bot&quot; \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0435\u0449\u0435 \u0438 &quot;API telegram client&quot;, \u0442.\u0435. API \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u0437\u0430\u0440\u0435\u0433\u0435\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e (\u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043a \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0443) \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0447\u0442\u043e \u043c\u043d\u0435 \u043a\u0430\u043a \u0440\u0430\u0437 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 (\u044f \u0443\u0436\u0435 \u0437\u0430\u0440\u0435\u0433\u0435\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0432 \u0447\u0430\u0442\u0435).<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430 \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a API \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c: <a href=\"https:\/\/telegram.org\/apps#source-code\">https:\/\/telegram.org\/apps#source-code<\/a><\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0441\u0430\u043c\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0430 python: <a href=\"https:\/\/github.com\/LonamiWebs\/Telethon\">Pure Python 3 MTProto API Telegram client library<\/a> \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <strong>&quot;telethon&quot;<\/strong><\/p>\n<p>  <\/p>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u042f \u043d\u0435 \u0437\u043d\u0430\u044e \u043f\u0438\u0442\u043e\u043d. \u041d\u0443 \u0447\u0442\u043e \u0436, \u0435\u0441\u0442\u044c \u043f\u043e\u0432\u043e\u0434 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f.<br \/>  \u041a\u0430\u043a \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u043c\u0430\u043d\u0443\u0430\u043b \u043f\u043e \u0442\u0435\u043b\u0435\u0442\u043e\u043d\u0443, \u0438\u043d\u0441\u0442\u0430\u043b\u043b\u044f\u0446\u0438\u044f \u0435\u0433\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">pip3 install telethon<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438, \u0432\u0441\u0442\u0440\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u043c\u043d\u043e\u044e \u043f\u0440\u0438 \u0438\u043d\u0441\u0442\u0430\u043b\u043b\u044f\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043d\u0435 \u0438\u043d\u0441\u0442\u0430\u043b\u043b\u0438\u0440\u043e\u0432\u0430\u043d pip3 (\u0438\u043d\u0441\u0442\u0430\u043b\u043b\u044f\u0442\u043e\u0440 \u0434\u043b\u044f \u043f\u0438\u0442\u043e\u043d\u0430). <\/li>\n<\/ul>\n<p>  <\/p>\n<p>sudo apt-get -y install python3-pip<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043f\u0438\u0442\u043e\u043d\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 &gt;3.5. \u0422\u0430\u043a \u0447\u0442\u043e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0435\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u043e\u0441\u044c. \u041b\u0438\u0441\u0442\u0430\u0435\u043c readme.txt \u0434\u0430\u043b\u044c\u0448\u0435. <\/p>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u0449\u0438\u043c \u043f\u0443\u043d\u043a\u0442\u043e\u043c \u0438\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430\u2026 \u041a\u0430\u043a, \u0443\u0436\u0435? \u041d\u0443 \u0434\u0430, \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e. \u041f\u0440\u0430\u0432\u0434\u0430, \u0441\u043f\u0435\u0440\u0432\u0430 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u044f \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0441\u0430\u0439\u0442 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430: <a href=\"https:\/\/my.telegram.org\">https:\/\/my.telegram.org<\/a><br \/>  \u0412\u0432\u043e\u0434\u0438\u043c \u0442\u0435\u043b\u0435\u0444\u043e\u043d \u0438 \u0436\u0434\u0435\u043c \u043a\u043e\u0434 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043d\u0430 \u0440\u043e\u0434\u043d\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430. \u041e\u043d \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043b\u0438\u043d\u043d\u044b\u0439 (12 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432) \u0438 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430. <\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u043f\u0443\u043d\u043a\u0442 &quot;<a href=\"https:\/\/core.telegram.org\/api\">API<\/a>&quot;. \u0418\u0449\u0435\u043c &quot;Telegram API&quot; \u0438 \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 &quot;Creating an application&quot; (<a href=\"https:\/\/my.telegram.org\/apps\">https:\/\/my.telegram.org\/apps<\/a>). <\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u043e\u043b\u044f <strong>App title<\/strong> \u0438 <strong>Short name<\/strong>, \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c <strong>\u00abCreate application\u00bb<\/strong> \u0438 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435: <strong>api_id<\/strong> \u0438 <strong>api_hash<\/strong>. <\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0448\u043b\u0430 \u043f\u043e\u0440\u0430 \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<p>  <\/p>\n<pre><code>from telethon import TelegramClient, sync  # \u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c api_id \u0438 api_hash api_id = 12345 api_hash = '0123456789abcdef0123456789abcdef'  client = TelegramClient('session_name', api_id, api_hash) client.start()<\/code><\/pre>\n<p>  <\/p>\n<p>session_name \u2014 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0438\u043c\u044f. \u0412\u0430\u0441 \u043f\u043e\u043f\u0440\u043e\u0441\u044f\u0442 \u0432\u0432\u0435\u0441\u0442\u0438 \u0442\u0435\u043b\u0435\u0444\u043e\u043d \u0438 \u043f\u0440\u0438\u0448\u043b\u044e\u0442 \u043a\u043e\u0434 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0435\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 (\u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0435 session_name). \u0420\u044f\u0434\u043e\u043c \u0441 \u0432\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043e\u0439 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0444\u0430\u0439\u043b <strong>session_name.session<\/strong><\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435\u0442, \u043a\u043b\u0438\u0435\u043d\u0442 \u0433\u043e\u0442\u043e\u0432. \u0422\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u0442, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u0444\u043c\u0430\u0446\u0438\u044e.<\/p>\n<p>  <\/p>\n<p>\u0423\u0437\u043d\u0430\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0441\u0435\u0431\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">print(client.get_me().stringify())<\/code><\/pre>\n<p>  <\/p>\n<p>\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">User(     photo=None,     last_name='Pupkin',     first_name='Vasya',     id=123456789,     phone='79041234567', .... - \u0447\u0442\u043e-\u0442\u043e \u0435\u0449\u0435... )<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 \u0441\u0435\u0431\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">client.send_message('username', 'Hello! Talking to you from Telethon')<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">client.send_file('username', '\/home\/myself\/Pictures\/holidays.jpg')<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043c\u0435\u043d\u044f \u0432\u0438\u0434\u044f\u0442 \u0434\u0440\u0443\u0433\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">client.download_profile_photo('me')<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0430 \u043a\u0430\u043a\u0438\u0435 \u0447\u0430\u0442\u044b \u043c\u044b \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u044b:<\/p>\n<p>  <\/p>\n<pre><code>print all chats name for dialog in client.iter_dialogs():     print(dialog.title)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0447\u0438\u0442\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0447\u0430\u0442\u0430 &quot;chat_name&quot; (\u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e, \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e)<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">messages = client.get_entity('chat_name') print(messages)<\/code><\/pre>\n<p>  <\/p>\n<p>\u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0447\u0430\u0442\u0430<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">participants = client.get_participants('chat_name') print(participants)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0431\u0430\u043b\u043e\u0432\u0430\u043b\u0438\u0441\u044c?<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u043e, \u0440\u0430\u0434\u0438 \u0447\u0435\u0433\u043e \u043c\u044b \u0432\u0441\u0435 \u044d\u0442\u043e \u0437\u0430\u0442\u0435\u044f\u043b\u0438&#8230;<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043a\u0430, \u0441\u043b\u0435\u0434\u044f\u0449\u0430\u044f \u0437\u0430 \u043d\u043e\u0432\u044b\u043c\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043a\u0430\u043d\u0430\u043b\u0435. <\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u043b \u0440\u0430\u0431\u043e\u0442\u0443, \u043f\u043e\u0441\u043b\u0435 client.start() \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">client.run_until_disconnected()<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f (\u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 client.start()) \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u0432\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code>@client.on(events.NewMessage(chats=('chat_name'))) async def normal_handler(event): #    print(event.message)     print(event.message.to_dict()['message'])<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f. <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">@client.on(events.NewMessage(chats=('chat_name')))<\/code><\/pre>\n<p>  <\/p>\n<p>\u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u043f\u0440\u0438 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"> print(event.message)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">Message(edit_date=None, views=None, reply_markup=None, fwd_from=None, id=187, entities=[], post=False, mentioned=False, via_bot_id=None, media_unread=False, out=True, media=None, date=datetime.datetime(2018, 10, 1, 9, 26, 21, tzinfo=datetime.timezone.utc), to_id=PeerChannel(channel_id=123456789), reply_to_msg_id=None, from_id=123456789, silent=False, grouped_id=None, post_author=None, message='hello telegram')<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0437 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0435: &quot;message=&#8217;hello telegram&#8217;&quot;: <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">    print(event.message.to_dict()['message'])<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438, \u043d\u043e \u043e\u0442 \u043a\u043e\u0433\u043e \u043e\u043d\u043e, \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0442.\u043a. \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0427\u0442\u043e\u0431\u044b \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c ID \u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0447\u0430\u0442\u0430 \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0438\u0445 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c (\u0445\u044d\u0448) \u0432 \u0432\u0438\u0434\u0435 d[id]=&quot;first_name last_name&quot;<\/p>\n<p>  <\/p>\n<pre><code>participants = client.get_participants(group) users={}  for partic in client.iter_participants(group):     lastname=&quot;&quot;     if partic.last_name:        lastname=partic.last_name     users[partic.id]=partic.first_name+&quot; &quot;+lastname<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0442\u043e \u043f\u043e\u0441\u043b\u0430\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code>s_user_id=event.message.to_dict()['from_id'] user_id=int(s_user_id) user=d.get(user_id)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043d\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0435\u043c\u043d\u043e\u0433\u043e, \u043f\u0440\u043e\u0449\u0435 \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u043c. <\/p>\n<p>  <\/p>\n<p>\u0412\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u043c \u0438\u0437 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u0430\u0442\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438: <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">mess_date=event.message.to_dict()['date']<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0441\u0435, \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u0445 \u0432 \u0444\u0430\u0439\u043b.<br \/>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0444\u0430\u0439\u043b \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">f=open('messages_from_chat', 'a') <\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code>f.write(mess_date.strftime(&quot;%d-%m-%Y %H:%M&quot;)+&quot;\\n&quot;) f.write(user+&quot;\\n&quot;) f.write(user_mess+&quot;\\n\\n&quot;) f.flush()<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435! \u0412\u0441\u0435, \u0447\u0442\u043e \u043c\u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0443\u0436\u043d\u043e, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043a\u0430 \u0434\u0435\u043b\u0430\u0435\u0442. \u0423\u0442\u0438\u043b\u0438\u0442\u043a\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u044b\u0440\u043e\u0432\u0430\u0442\u0430, \u043d\u043e \u0441\u0432\u043e\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>Python \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043d\u0435 \u0442\u0430\u043a\u0438\u043c \u0443\u0436 \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c <strike>\u043a\u0430\u043a \u0435\u0433\u043e \u043c\u0430\u043b\u044e\u044e\u0442<\/strike>, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043f\u043e\u043b\u043d\u044b\u043c-\u043f\u043e\u043b\u043d\u043e. \u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0449\u0435 \u043f\u0430\u0440\u0443 \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u043a \u0438 \u043f\u0440\u0438\u0432\u044b\u043a\u043d\u0443\u0432 \u043a \u043d\u0435\u043c\u0443, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432\u044b\u0439 \u044f\u0437\u044b\u043a \u0432\u043c\u0435\u0441\u0442\u043e bash. <\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u0435\u0441\u044c \u0442\u0435\u043a\u0441\u0442 \u0443\u0442\u0438\u043b\u0438\u0442\u044b:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>from telethon import TelegramClient, sync, events  api_id = 12345 api_hash = '0123456789abcdef0123456789abcdef'  client = TelegramClient('session_name', api_id, api_hash)  @client.on(events.NewMessage(chats=('chat_name'))) async def normal_handler(event): #    print(event.message)     user_mess=event.message.to_dict()['message']      s_user_id=event.message.to_dict()['from_id']     user_id=int(s_user_id)     user=d.get(user_id)      mess_date=event.message.to_dict()['date']      f.write(mess_date.strftime(&quot;%d-%m-%Y %H:%M&quot;)+&quot;\\n&quot;)     f.write(user+&quot;\\n&quot;)     f.write(user_mess+&quot;\\n\\n&quot;)      f.flush()  client.start()  group='group_name'  participants = client.get_participants(group) users={}  for partic in client.iter_participants(group):     lastname=&quot;&quot;     if partic.last_name:        lastname=partic.last_name     users[partic.id]=partic.first_name+&quot; &quot;+lastname  f=open('messages_from_chat', 'a')   client.run_until_disconnected() f.close()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p><a href=\"https:\/\/media.readthedocs.org\/pdf\/telethon\/stable\/telethon.pdf\">\u041f\u043e\u043b\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/a>.<\/p>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \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\/post\/425151\/\"> https:\/\/habr.com\/post\/425151\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u0417\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043a\u0430\u043a-\u0442\u043e \u043c\u043d\u0435, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0447\u0430\u0442\u043e\u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u043b\u0438\u0441\u044c \u0443 \u043c\u0435\u043d\u044f \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 (\u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044f \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430). \u041d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438\u0445 \u043f\u043e\u0431\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0442\u0438\u0432\u043e\u0432, \u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e\u0439 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u0435 \u0435\u0441\u0442\u044c \u0431\u043e\u0442\u044b. \u041d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0435\u0439, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u044b\u0445 \u0431\u043e\u0442\u0430\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: &quot;<a href=\"https:\/\/habr.com\/post\/264035\/\">\u0427\u0430\u0442-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u043d\u0430 \u0441\u0430\u0439\u0442<\/a>&quot;.<\/p>\n<p>  <\/p>\n<p>\u0411\u043e\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0434\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u043e\u0442\u0430 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0442\u0435\u043b\u0435\u0444\u043e\u043d \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u043e\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u044b\u043c. \u041d\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u043e\u0442\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0441\u043b\u043e\u0432\u043e &quot;bot&quot;, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0443 \u0445\u043e\u0437\u044f\u0438\u043d\u0430 \u0447\u0430\u0442\u0430 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b. <\/p>\n<p>  <\/p>\n<p>\u041d\u043e, \u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u2014 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u043e\u0442\u0432\u0435\u0442\u0430.<\/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-290227","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/290227","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=290227"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/290227\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=290227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=290227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=290227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}