{"id":467217,"date":"2025-07-16T21:01:59","date_gmt":"2025-07-16T21:01:59","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=467217"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=467217","title":{"rendered":"<span>\u041a\u0430\u043a \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0443 Telegram \u0432 \u0442\u0435\u0440\u043c\u043e\u043c\u0435\u0442\u0440?<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0421\u043d\u043e\u0432\u0430 \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e. \u0412 \u043c\u043e\u0435\u0439 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 &#171;<a href=\"https:\/\/habr.com\/ru\/articles\/926148\/\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 Telegram \u0432 \u0441\u0442\u0430\u0442\u0443\u0441 Steam<\/a>&#187; \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 &#171;<a href=\"https:\/\/habr.com\/ru\/articles\/457078\/\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0443 \u0432 Telegram \u0432 \u0447\u0430\u0441\u044b<\/a>&#187; \u044f \u043e\u043f\u0438\u0441\u0430\u043b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0443\u044e \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e. \u041f\u043e\u0447\u0438\u0442\u0430\u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0441 \u043e\u0431\u0435\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439, \u044f \u043f\u0440\u0438\u0448\u0435\u043b \u043a \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u0439 \u0438\u0434\u0435\u0435. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e &#8212; \u0430\u0432\u0430\u0442\u0430\u0440 \u0441 \u0442\u0435\u0440\u043c\u043e\u043c\u0435\u0442\u0440\u043e\u043c. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0430\u0442\u044c\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0434\u043b\u044f \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432 \u0422\u0413.<\/p>\n<p>\u0414\u0430, \u043c\u043e\u0436\u0435\u0442 \u044f \u0438 \u0432\u044b\u0441\u0430\u0441\u044b\u0432\u0430\u044e \u0438\u0434\u0435\u044e \u0438\u0437 \u043f\u0430\u043b\u044c\u0446\u0430, \u043d\u043e \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u044d\u0442\u043e \u0432\u0435\u0441\u044c\u043c\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c. \u0412\u0435\u0434\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0437\u0430\u043c\u0435\u0442\u0435\u043d, \u0430 \u0441\u043c\u0435\u043d\u0430 \u0430\u0432\u0430\u0442\u0430\u0440\u0430 \u0447\u0430\u0441\u043e\u0432 \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c flood-\u0431\u0430\u043d. <\/p>\n<h2>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043a\u043e\u0434\u0443<\/h2>\n<p>\u0417\u0434\u0435\u0441\u044c \u0431\u043e\u043b\u0435\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0447\u0435\u043c \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/p>\n<pre><code>pip install requests pip install Telethon pip install pillow pip install beautifulsoup4<\/code><\/pre>\n<p>\u0418 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043c\u043e\u0434\u0443\u043b\u0438<\/p>\n<pre><code class=\"python\">import requests from bs4 import BeautifulSoup as bs from PIL import Image, ImageDraw, ImageFont from datetime import datetime from telethon import TelegramClient from telethon.tl.functions.photos import UploadProfilePhotoRequest, DeletePhotosRequest from telethon.tl.types import InputPhoto import time<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/p>\n<pre><code class=\"python\">URL_TEMPLATE = \"https:\/\/pogoda.mail.ru\/prognoz\/krasnodar\/24hours\/\" FONT_LARGE = ImageFont.truetype(\"shr1.ttf\", 80) FONT_SMALL = ImageFont.truetype(\"shr2.ttf\", 30) client = TelegramClient(\"anon\", api_id, \"api_hash\") client.start() city = \"Krasnodar\"<\/code><\/pre>\n<p><strong>URL_TEMPLATE<\/strong> &#8212; \u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0430\u0439\u0442 \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430. \u041f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0445\u043e\u0434\u0438\u0442\u0435 \u0441\u044e\u0434\u0430<br \/><strong>FONT_LARGE<\/strong> \u0438 <strong>FONT_SMALL<\/strong> &#8212; \u0448\u0440\u0438\u0444\u0442\u044b. \u041c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0445 \u0442\u0443\u0442. \u042f, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0443\u0436\u0435 \u043d\u0435 \u0441\u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u044f, \u0438\u0431\u043e \u0448\u0440\u0438\u0444\u0442\u044b \u0431\u044b\u043b\u0438 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b.<br \/><strong>client<\/strong> &#8212; \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430 telethon. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0437\u044f\u0442\u044c api_id \u0438 api_hash\u00a0<a href=\"https:\/\/my.telegram.org\/auth\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.  <br \/><strong>city<\/strong> &#8212; \u041d\u0430\u0434\u043f\u0438\u0441\u044c \u043f\u043e\u0434 \u043f\u043e\u0434 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043e\u0439 <\/p>\n<h2>\u041f\u0430\u0440\u0441\u0438\u043d\u0433 \u043f\u043e\u0433\u043e\u0434\u044b<\/h2>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c requests \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 bs4 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. \u041f\u0430\u0440\u0441\u0438\u0442\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441 \u0441\u0430\u0439\u0442\u0430 <a href=\"http:\/\/pogoda.mail.ru\" rel=\"noopener noreferrer nofollow\">pogoda.mail.ru<\/a><\/p>\n<pre><code class=\"python\">def weather_parse():     r = requests.get(URL_TEMPLATE)     soup = bs(r.text, \"html.parser\")     temperature = soup.find_all('span', class_='p-forecast__temperature-value')[0]  #   &lt;span class=\"p-forecast__temperature-value\"&gt;+24\u00b0&lt;\/span&gt;     return temperature.text<\/code><\/pre>\n<p>\u041e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0430\u0440\u0441\u0438\u0442 \u043f\u043e\u0433\u043e\u0434\u0443. \u041f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0445\u043e\u0434\u0438\u0442\u0435 <a href=\"https:\/\/pogoda.mail.ru\/prognoz\/\" rel=\"noopener noreferrer nofollow\">\u0441\u044e\u0434\u0430<\/a>, \u0438\u0449\u0438\u0442\u0435 \u0441\u0432\u043e\u0439 \u0433\u043e\u0440\u043e\u0434 \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>URL_TEMPLATE.<\/strong><\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043e\u0439<\/h2>\n<pre><code class=\"python\">def img_weather(hour, show=False):     temperature = weather_parse()     print(temperature)     if hour &lt; 6:         color = \"#0000CD\"     elif hour &lt; 12:         color = \"#FFD700\"     elif hour &lt; 18:         color = \"#FFFACD\"     else:         color = \"#FF8C00\"      image = Image.new('RGB', (256, 256), color='black')     draw = ImageDraw.Draw(image)     text_width = draw.textlength(temperature, font=FONT_LARGE)     draw.text(((256 - text_width) \/\/ 2, 80), temperature, font=FONT_LARGE, fill=\"white\")     subtext = city     subtext_width = draw.textlength(subtext, font=FONT_SMALL)     draw.text(((256 - subtext_width) \/\/ 2, 150), subtext, font=FONT_SMALL, fill=color)     if show:         image.show()     return image<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0439. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>hour<\/strong>. \u042d\u0442\u043e \u0447\u0430\u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430 \u0434\u0432\u043e\u0440\u0435. \u041f\u043e\u0442\u043e\u043c \u0438\u0434\u0435\u0442 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041e\u0442 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0446\u0432\u0435\u0442 \u043d\u0430\u0434\u043f\u0438\u0441\u0438 \u043f\u043e\u0434 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043e\u0439. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u044d\u0442\u0438 \u0446\u0432\u0435\u0442\u0430, \u0438\u0431\u043e \u044f \u0434\u0430\u043b\u044c\u0442\u043e\u043d\u0438\u043a \ud83d\ude00<br \/>\u0417\u0430\u0434\u0430\u0435\u043c \u0447\u0435\u0440\u043d\u044b\u0439 \u0444\u043e\u043d, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u043f\u043e \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u0438 \u043d\u0430 \u043d\u0443\u0436\u043d\u043e\u0439 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u0438, \u0430 \u0444\u043e\u0440\u043c\u0430\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f 256*256 (\u043a\u0432\u0430\u0434\u0440\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 Telegram). <\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b36\/04f\/082\/b3604f082a5c9b84c8020a705b4950dd.png\" alt=\"3 \u0447\u0430\u0441\u0430\" title=\"3 \u0447\u0430\u0441\u0430\" width=\"256\" height=\"255\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/b36\/04f\/082\/b3604f082a5c9b84c8020a705b4950dd.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b36\/04f\/082\/b3604f082a5c9b84c8020a705b4950dd.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>3 \u0447\u0430\u0441\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u043e \u0438\u0442\u043e\u0433\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0435 \u0432\u043e\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u041c\u043d\u0435 \u043b\u0438\u0447\u043d\u043e \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0442\u0430\u043a. \u041c\u043e\u0436\u0435\u0442 \u043c\u043e\u0436\u043d\u043e \u0442\u0443\u0434\u0430 \u0437\u0430\u0441\u0443\u043d\u0443\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0435\u0449\u0435.<\/p>\n<h2>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0430\u0432\u0430\u0442\u0430\u0440\u0430<\/h2>\n<pre><code class=\"python\">async def update_profile_photo(hour):     try:         try:             # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u0443\u044e \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044e (\u0441 await)             photos = await client.get_profile_photos('me')             if photos:                 await client(DeletePhotosRequest(                     id=[InputPhoto(                         id=photos[0].id,                         access_hash=photos[0].access_hash,                         file_reference=photos[0].file_reference                     )]                 ))         except Exception as e:             print(\"\u041d\u0435\u0442 \u0430\u0432\u0430\u0442\u0430\u0440\u043e\u043a \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f:\", e)         image = img_weather(hour)         image.save(\"vrem.png\")         with open(\"vrem.png\", 'rb') as file:             file1 = await client.upload_file(file)             await client(UploadProfilePhotoRequest(file=file1))         return \"True\"     except Exception as e:         return str(e)<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e. \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u0443\u044e \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0443, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u0435\u0435 \u043a\u0430\u043a \u0430\u0432\u0430\u0442\u0430\u0440. \u0415\u0441\u043b\u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0437\u043d\u0430\u0447\u0438\u0442 \u0430\u0432\u0430\u0442\u0430\u0440\u043e\u043a \u043d\u0435\u0442\u0443. <\/p>\n<h2>Main()<\/h2>\n<pre><code class=\"python\">async def main():     await client.start()     last_time = \"\"     while True:         current_time = datetime.now().hour         if current_time != last_time:             last_time = current_time             result = await update_profile_photo(current_time)             if result != \"True\":                 print(f\"\u041e\u0448\u0438\u0431\u043a\u0430: {result}\")             else:                 print(f\"{current_time}hour - \u0423\u0434\u0430\u0447\u043d\u0430\u044f \u0441\u043c\u0435\u043d\u0430\")         await asyncio.sleep(20) if __name__ == \"__main__\":     with client:         client.loop.run_until_complete(main())<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0435 20 \u0441\u0435\u043a\u0443\u043d\u0434 \u0447\u0430\u0441, \u0435\u0441\u043b\u0438 \u0447\u0430\u0441 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043c\u0435\u043d\u044b \u0430\u0432\u0430\u0442\u0430\u0440\u0430. \u0417\u0430\u0447\u0435\u043c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u043c\u0435\u043d\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0447\u0430\u0441\u0430? \u042d\u0442\u043e \u0437\u0430 \u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u043d\u044f\u0442\u044c \u0433\u0440\u0430\u0434\u0443\u0441 \u0442\u043e\u0447\u044c-\u0432-\u0442\u043e\u0447\u044c \u0441 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u043c. \u0412 \u043f\u0440\u043e\u0447\u0435\u043c \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e.<\/p>\n<h2>\u0422\u0435\u0441\u0442<\/h2>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/758\/7d4\/294\/7587d4294f1884cccc57fe7690ab4fb1.png\" width=\"418\" height=\"182\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/758\/7d4\/294\/7587d4294f1884cccc57fe7690ab4fb1.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/758\/7d4\/294\/7587d4294f1884cccc57fe7690ab4fb1.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u043e\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u0448 \u043f\u0440\u043e\u0444\u0438\u043b\u044c<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import asyncio import requests from bs4 import BeautifulSoup as bs from PIL import Image, ImageDraw, ImageFont from datetime import datetime from telethon import TelegramClient from telethon.tl.functions.photos import UploadProfilePhotoRequest, DeletePhotosRequest from telethon.tl.types import InputPhoto url_yandex = \"https:\/\/yandex.ru\/pogoda\/ru\/krasnodar\" url_mail = \"https:\/\/pogoda.mail.ru\/prognoz\/krasnodar\/24hours\/\" FONT_LARGE = ImageFont.truetype(\"porn2.ttf\", 80) FONT_SMALL = ImageFont.truetype(\"porn3.ttf\", 30) client = TelegramClient(\"vology\", 21079830, \"fa59df8ecab7c0ffabff817922f1df56\") city = \"Krasnodar\" def weather_parse():     try:  # \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u044f\u043d\u0434\u0435\u043a\u0441 \u043f\u043e\u0433\u043e\u0434\u044b (\u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u0430\u044f)         r = requests.get(url_yandex)         soup = bs(r.text, \"html.parser\")         temperature = soup.find_all('span', class_='AppFactTemperature_value__2qhsG')[0]         if temperature.text.strip() == \"0\":             return \"0\"         znak = soup.find_all('span', class_='AppFactTemperature_sign__1MeN4')[0]         return f\"{znak.text}{temperature.text}\u00b0\"     except:   # \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u043c\u0430\u0438\u043b \u0440\u0443 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u043f\u043e\u043b\u043e\u043c\u043a\u0438 \u044f\u043d\u0434\u0435\u043a\u0441\u0430         r = requests.get(url_mail)         soup = bs(r.text, \"html.parser\")         temperature = soup.find_all('span', class_='p-forecast__temperature-value')[0]         return temperature.text def img_weather(hour, show=False):     temperature = weather_parse()     print(temperature)     if hour &lt; 6:         color = \"#0000CD\"     elif hour &lt; 12:         color = \"#FFD700\"     elif hour &lt; 18:         color = \"#FFFACD\"     else:         color = \"#FF8C00\"      image = Image.new('RGB', (256, 256), color='black')     draw = ImageDraw.Draw(image)     text_width = draw.textlength(temperature, font=FONT_LARGE)     draw.text(((256 - text_width) \/\/ 2, 80), temperature, font=FONT_LARGE, fill=\"white\")     subtext = city     subtext_width = draw.textlength(subtext, font=FONT_SMALL)     draw.text(((256 - subtext_width) \/\/ 2, 150), subtext, font=FONT_SMALL, fill=color)     if show:         image.show()     return image async def update_profile_photo(hour):     try:         try:             # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u0443\u044e \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044e (\u0441 await)             photos = await client.get_profile_photos('me')             if photos:                 await client(DeletePhotosRequest(                     id=[InputPhoto(                         id=photos[0].id,                         access_hash=photos[0].access_hash,                         file_reference=photos[0].file_reference                     )]                 ))         except Exception as e:             print(\"\u041d\u0435\u0442 \u0430\u0432\u0430\u0442\u0430\u0440\u043e\u043a \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f:\", e)         image = img_weather(hour)         image.save(\"vrem.png\")         with open(\"vrem.png\", 'rb') as file:             file1 = await client.upload_file(file)             await client(UploadProfilePhotoRequest(file=file1))         return \"True\"     except Exception as e:         return str(e) async def main():     await client.start()     last_time = \"\"     while True:         current_time = datetime.now().hour         if current_time != last_time:             last_time = current_time             result = await update_profile_photo(current_time)             if result != \"True\":                 print(f\"\u041e\u0448\u0438\u0431\u043a\u0430: {result}\")             else:                 print(f\"{current_time}hour - \u0423\u0434\u0430\u0447\u043d\u0430\u044f \u0441\u043c\u0435\u043d\u0430\")         await asyncio.sleep(20) if __name__ == \"__main__\":     with client:         client.loop.run_until_complete(main())<\/code><\/pre>\n<\/div>\n<\/details>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u042d\u0442\u043e \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0438\u0437 \u0442\u043e\u043b\u043f\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041a\u0440\u0435\u0430\u0442\u0438\u0432\u043d\u0438\u0447\u0430\u0439\u0442\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0441\u0432\u043e\u0438 \u0438\u0434\u0435\u0438 \u0438 \u043c\u043e\u0434\u0435\u0440\u043d\u0438\u0437\u0438\u0440\u0443\u0439\u0442\u0435 \u0432\u0430\u0448\u0443 \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0443. \u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><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\/ru\/articles\/928358\/\"> https:\/\/habr.com\/ru\/articles\/928358\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0421\u043d\u043e\u0432\u0430 \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e. \u0412 \u043c\u043e\u0435\u0439 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 &#171;<a href=\"https:\/\/habr.com\/ru\/articles\/926148\/\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 Telegram \u0432 \u0441\u0442\u0430\u0442\u0443\u0441 Steam<\/a>&#187; \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 &#171;<a href=\"https:\/\/habr.com\/ru\/articles\/457078\/\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0443 \u0432 Telegram \u0432 \u0447\u0430\u0441\u044b<\/a>&#187; \u044f \u043e\u043f\u0438\u0441\u0430\u043b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0443\u044e \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e. \u041f\u043e\u0447\u0438\u0442\u0430\u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0441 \u043e\u0431\u0435\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439, \u044f \u043f\u0440\u0438\u0448\u0435\u043b \u043a \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u0439 \u0438\u0434\u0435\u0435. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e &#8212; \u0430\u0432\u0430\u0442\u0430\u0440 \u0441 \u0442\u0435\u0440\u043c\u043e\u043c\u0435\u0442\u0440\u043e\u043c. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0430\u0442\u044c\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0434\u043b\u044f \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432 \u0422\u0413.<\/p>\n<p>\u0414\u0430, \u043c\u043e\u0436\u0435\u0442 \u044f \u0438 \u0432\u044b\u0441\u0430\u0441\u044b\u0432\u0430\u044e \u0438\u0434\u0435\u044e \u0438\u0437 \u043f\u0430\u043b\u044c\u0446\u0430, \u043d\u043e \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u044d\u0442\u043e \u0432\u0435\u0441\u044c\u043c\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c. \u0412\u0435\u0434\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0437\u0430\u043c\u0435\u0442\u0435\u043d, \u0430 \u0441\u043c\u0435\u043d\u0430 \u0430\u0432\u0430\u0442\u0430\u0440\u0430 \u0447\u0430\u0441\u043e\u0432 \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c flood-\u0431\u0430\u043d. <\/p>\n<h2>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043a\u043e\u0434\u0443<\/h2>\n<p>\u0417\u0434\u0435\u0441\u044c \u0431\u043e\u043b\u0435\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0447\u0435\u043c \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/p>\n<pre><code>pip install requests pip install Telethon pip install pillow pip install beautifulsoup4<\/code><\/pre>\n<p>\u0418 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043c\u043e\u0434\u0443\u043b\u0438<\/p>\n<pre><code class=\"python\">import requests from bs4 import BeautifulSoup as bs from PIL import Image, ImageDraw, ImageFont from datetime import datetime from telethon import TelegramClient from telethon.tl.functions.photos import UploadProfilePhotoRequest, DeletePhotosRequest from telethon.tl.types import InputPhoto import time<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/p>\n<pre><code class=\"python\">URL_TEMPLATE = \"https:\/\/pogoda.mail.ru\/prognoz\/krasnodar\/24hours\/\" FONT_LARGE = ImageFont.truetype(\"shr1.ttf\", 80) FONT_SMALL = ImageFont.truetype(\"shr2.ttf\", 30) client = TelegramClient(\"anon\", api_id, \"api_hash\") client.start() city = \"Krasnodar\"<\/code><\/pre>\n<p><strong>URL_TEMPLATE<\/strong> &#8212; \u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0430\u0439\u0442 \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430. \u041f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0445\u043e\u0434\u0438\u0442\u0435 \u0441\u044e\u0434\u0430<br \/><strong>FONT_LARGE<\/strong> \u0438 <strong>FONT_SMALL<\/strong> &#8212; \u0448\u0440\u0438\u0444\u0442\u044b. \u041c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0445 \u0442\u0443\u0442. \u042f, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0443\u0436\u0435 \u043d\u0435 \u0441\u043c\u043e\u0433\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u044f, \u0438\u0431\u043e \u0448\u0440\u0438\u0444\u0442\u044b \u0431\u044b\u043b\u0438 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b.<br \/><strong>client<\/strong> &#8212; \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430 telethon. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0437\u044f\u0442\u044c api_id \u0438 api_hash\u00a0<a href=\"https:\/\/my.telegram.org\/auth\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.  <br \/><strong>city<\/strong> &#8212; \u041d\u0430\u0434\u043f\u0438\u0441\u044c \u043f\u043e\u0434 \u043f\u043e\u0434 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043e\u0439 <\/p>\n<h2>\u041f\u0430\u0440\u0441\u0438\u043d\u0433 \u043f\u043e\u0433\u043e\u0434\u044b<\/h2>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c requests \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 bs4 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. \u041f\u0430\u0440\u0441\u0438\u0442\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441 \u0441\u0430\u0439\u0442\u0430 <a href=\"http:\/\/pogoda.mail.ru\" rel=\"noopener noreferrer nofollow\">pogoda.mail.ru<\/a><\/p>\n<pre><code class=\"python\">def weather_parse():     r = requests.get(URL_TEMPLATE)     soup = bs(r.text, \"html.parser\")     temperature = soup.find_all('span', class_='p-forecast__temperature-value')[0]  #   &lt;span class=\"p-forecast__temperature-value\"&gt;+24\u00b0&lt;\/span&gt;     return temperature.text<\/code><\/pre>\n<p>\u041e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0430\u0440\u0441\u0438\u0442 \u043f\u043e\u0433\u043e\u0434\u0443. \u041f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0445\u043e\u0434\u0438\u0442\u0435 <a href=\"https:\/\/pogoda.mail.ru\/prognoz\/\" rel=\"noopener noreferrer nofollow\">\u0441\u044e\u0434\u0430<\/a>, \u0438\u0449\u0438\u0442\u0435 \u0441\u0432\u043e\u0439 \u0433\u043e\u0440\u043e\u0434 \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>URL_TEMPLATE.<\/strong><\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043e\u0439<\/h2>\n<pre><code class=\"python\">def img_weather(hour, show=False):     temperature = weather_parse()     print(temperature)     if hour &lt; 6:         color = \"#0000CD\"     elif hour &lt; 12:         color = \"#FFD700\"     elif hour &lt; 18:         color = \"#FFFACD\"     else:         color = \"#FF8C00\"      image = Image.new('RGB', (256, 256), color='black')     draw = ImageDraw.Draw(image)     text_width = draw.textlength(temperature, font=FONT_LARGE)     draw.text(((256 - text_width) \/\/ 2, 80), temperature, font=FONT_LARGE, fill=\"white\")     subtext = city     subtext_width = draw.textlength(subtext, font=FONT_SMALL)     draw.text(((256 - subtext_width) \/\/ 2, 150), subtext, font=FONT_SMALL, fill=color)     if show:         image.show()     return image<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0439. \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>hour<\/strong>. \u042d\u0442\u043e \u0447\u0430\u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430 \u0434\u0432\u043e\u0440\u0435. \u041f\u043e\u0442\u043e\u043c \u0438\u0434\u0435\u0442 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041e\u0442 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0446\u0432\u0435\u0442 \u043d\u0430\u0434\u043f\u0438\u0441\u0438 \u043f\u043e\u0434 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043e\u0439. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u044d\u0442\u0438 \u0446\u0432\u0435\u0442\u0430, \u0438\u0431\u043e \u044f \u0434\u0430\u043b\u044c\u0442\u043e\u043d\u0438\u043a \ud83d\ude00<br \/>\u0417\u0430\u0434\u0430\u0435\u043c \u0447\u0435\u0440\u043d\u044b\u0439 \u0444\u043e\u043d, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u043f\u043e \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u0438 \u043d\u0430 \u043d\u0443\u0436\u043d\u043e\u0439 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u0438, \u0430 \u0444\u043e\u0440\u043c\u0430\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f 256*256 (\u043a\u0432\u0430\u0434\u0440\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 Telegram). <\/p>\n<figure class=\"\">\n<div><figcaption>3 \u0447\u0430\u0441\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u043e \u0438\u0442\u043e\u0433\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0435 \u0432\u043e\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u041c\u043d\u0435 \u043b\u0438\u0447\u043d\u043e \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0442\u0430\u043a. \u041c\u043e\u0436\u0435\u0442 \u043c\u043e\u0436\u043d\u043e \u0442\u0443\u0434\u0430 \u0437\u0430\u0441\u0443\u043d\u0443\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0435\u0449\u0435.<\/p>\n<h2>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0430\u0432\u0430\u0442\u0430\u0440\u0430<\/h2>\n<pre><code class=\"python\">async def update_profile_photo(hour):     try:         try:             # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u0443\u044e \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044e (\u0441 await)             photos = await client.get_profile_photos('me')             if photos:                 await client(DeletePhotosRequest(                     id=[InputPhoto(                         id=photos[0].id,                         access_hash=photos[0].access_hash,                         file_reference=photos[0].file_reference                     )]                 ))         except Exception as e:             print(\"\u041d\u0435\u0442 \u0430\u0432\u0430\u0442\u0430\u0440\u043e\u043a \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f:\", e)         image = img_weather(hour)         image.save(\"vrem.png\")         with open(\"vrem.png\", 'rb') as file:             file1 = await client.upload_file(file)             await client(UploadProfilePhotoRequest(file=file1))         return \"True\"     except Exception as e:         return str(e)<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e. \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u0443\u044e \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0443, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u0435\u0435 \u043a\u0430\u043a \u0430\u0432\u0430\u0442\u0430\u0440. \u0415\u0441\u043b\u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0437\u043d\u0430\u0447\u0438\u0442 \u0430\u0432\u0430\u0442\u0430\u0440\u043e\u043a \u043d\u0435\u0442\u0443. <\/p>\n<h2>Main()<\/h2>\n<pre><code class=\"python\">async def main():     await client.start()     last_time = \"\"     while True:         current_time = datetime.now().hour         if current_time != last_time:             last_time = current_time             result = await update_profile_photo(current_time)             if result != \"True\":                 print(f\"\u041e\u0448\u0438\u0431\u043a\u0430: {result}\")             else:                 print(f\"{current_time}hour - \u0423\u0434\u0430\u0447\u043d\u0430\u044f \u0441\u043c\u0435\u043d\u0430\")         await asyncio.sleep(20) if __name__ == \"__main__\":     with client:         client.loop.run_until_complete(main())<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0435 20 \u0441\u0435\u043a\u0443\u043d\u0434 \u0447\u0430\u0441, \u0435\u0441\u043b\u0438 \u0447\u0430\u0441 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043c\u0435\u043d\u044b \u0430\u0432\u0430\u0442\u0430\u0440\u0430. \u0417\u0430\u0447\u0435\u043c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u043c\u0435\u043d\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0447\u0430\u0441\u0430? \u042d\u0442\u043e \u0437\u0430 \u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u043d\u044f\u0442\u044c \u0433\u0440\u0430\u0434\u0443\u0441 \u0442\u043e\u0447\u044c-\u0432-\u0442\u043e\u0447\u044c \u0441 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u043c. \u0412 \u043f\u0440\u043e\u0447\u0435\u043c \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e.<\/p>\n<h2>\u0422\u0435\u0441\u0442<\/h2>\n<figure class=\"\"><\/figure>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u043e\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u0448 \u043f\u0440\u043e\u0444\u0438\u043b\u044c<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import asyncio import requests from bs4 import BeautifulSoup as bs from PIL import Image, ImageDraw, ImageFont from datetime import datetime from telethon import TelegramClient from telethon.tl.functions.photos import UploadProfilePhotoRequest, DeletePhotosRequest from telethon.tl.types import InputPhoto url_yandex = \"https:\/\/yandex.ru\/pogoda\/ru\/krasnodar\" url_mail = \"https:\/\/pogoda.mail.ru\/prognoz\/krasnodar\/24hours\/\" FONT_LARGE = ImageFont.truetype(\"porn2.ttf\", 80) FONT_SMALL = ImageFont.truetype(\"porn3.ttf\", 30) client = TelegramClient(\"vology\", 21079830, \"fa59df8ecab7c0ffabff817922f1df56\") city = \"Krasnodar\" def weather_parse():     try:  # \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u044f\u043d\u0434\u0435\u043a\u0441 \u043f\u043e\u0433\u043e\u0434\u044b (\u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u0430\u044f)         r = requests.get(url_yandex)         soup = bs(r.text, \"html.parser\")         temperature = soup.find_all('span', class_='AppFactTemperature_value__2qhsG')[0]         if temperature.text.strip() == \"0\":             return \"0\"         znak = soup.find_all('span', class_='AppFactTemperature_sign__1MeN4')[0]         return f\"{znak.text}{temperature.text}\u00b0\"     except:   # \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u043c\u0430\u0438\u043b \u0440\u0443 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u043f\u043e\u043b\u043e\u043c\u043a\u0438 \u044f\u043d\u0434\u0435\u043a\u0441\u0430         r = requests.get(url_mail)         soup = bs(r.text, \"html.parser\")         temperature = soup.find_all('span', class_='p-forecast__temperature-value')[0]         return temperature.text def img_weather(hour, show=False):     temperature = weather_parse()     print(temperature)     if hour &lt; 6:         color = \"#0000CD\"     elif hour &lt; 12:         color = \"#FFD700\"     elif hour &lt; 18:         color = \"#FFFACD\"     else:         color = \"#FF8C00\"      image = Image.new('RGB', (256, 256), color='black')     draw = ImageDraw.Draw(image)     text_width = draw.textlength(temperature, font=FONT_LARGE)     draw.text(((256 - text_width) \/\/ 2, 80), temperature, font=FONT_LARGE, fill=\"white\")     subtext = city     subtext_width = draw.textlength(subtext, font=FONT_SMALL)     draw.text(((256 - subtext_width) \/\/ 2, 150), subtext, font=FONT_SMALL, fill=color)     if show:         image.show()     return image async def update_profile_photo(hour):     try:         try:             # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u0443\u044e \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044e (\u0441 await)             photos = await client.get_profile_photos('me')             if photos:                 await client(DeletePhotosRequest(                     id=[InputPhoto(                         id=photos[0].id,                         access_hash=photos[0].access_hash,                         file_reference=photos[0].file_reference                     )]                 ))         except Exception as e:             print(\"\u041d\u0435\u0442 \u0430\u0432\u0430\u0442\u0430\u0440\u043e\u043a \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f:\", e)         image = img_weather(hour)         image.save(\"vrem.png\")         with open(\"vrem.png\", 'rb') as file:             file1 = await client.upload_file(file)             await client(UploadProfilePhotoRequest(file=file1))         return \"True\"     except Exception as e:         return str(e) async def main():     await client.start()     last_time = \"\"     while True:         current_time = datetime.now().hour         if current_time != last_time:             last_time = current_time             result = await update_profile_photo(current_time)             if result != \"True\":                 print(f\"\u041e\u0448\u0438\u0431\u043a\u0430: {result}\")             else:                 print(f\"{current_time}hour - \u0423\u0434\u0430\u0447\u043d\u0430\u044f \u0441\u043c\u0435\u043d\u0430\")         await asyncio.sleep(20) if __name__ == \"__main__\":     with client:         client.loop.run_until_complete(main())<\/code><\/pre>\n<\/div>\n<\/details>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u042d\u0442\u043e \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0438\u0437 \u0442\u043e\u043b\u043f\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041a\u0440\u0435\u0430\u0442\u0438\u0432\u043d\u0438\u0447\u0430\u0439\u0442\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0441\u0432\u043e\u0438 \u0438\u0434\u0435\u0438 \u0438 \u043c\u043e\u0434\u0435\u0440\u043d\u0438\u0437\u0438\u0440\u0443\u0439\u0442\u0435 \u0432\u0430\u0448\u0443 \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0443. \u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><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\/ru\/articles\/928358\/\"> https:\/\/habr.com\/ru\/articles\/928358\/<\/a><br \/><\/br><\/br><\/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-467217","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/467217","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=467217"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/467217\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=467217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=467217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=467217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}