{"componentChunkName":"component---src-templates-material-js","path":"/workshops/2021/05/01/pishem-svoego-robota-na-python-urok-4/index.html","result":{"pageContext":{"pageParameters":{"isPreview":false,"isMirror":true,"delay_to_show_donate_popup_seconds":7,"about_page":false,"games_page":true,"games_page_link_in_header":false,"donate_popup_show_ru":true,"donate_popup_title_ru":"Без вас — нас не будет","donate_popup_content_ru":"Помогите нам добывать и рассказывать важные истории. Участие каждого — важно!","donate_popup_show_en":true,"donate_popup_title_en":"We can’t do it alone!","donate_popup_content_en":"Help us uncover and share the stories that matter. Every contribution makes a difference","display_regular_donors_banner":false,"showPatreonMethod":true,"useNewMaterialDonationBanner":true,"new_donations_page_design":true,"donations_popup_variants":{"ru":[{"id":"kc19b","title":"Сохраните журналистику для людей в России ","subtitle":"Читают нас прежде всего люди в России, но будущее «Важных историй» зависит от тех, кто живет за пределами страны. Поддержите нас ежемесячным донатом — сохраните независимую журналистику для ваших близких, которые остаются в России.","is_active":true,"background":"linear-gradient(10deg, #421f20 5%, #994146)"},{"id":"33tc9","title":"У пропаганды есть миллиарды из бюджета. У нас — только вы","subtitle":"Перемены возможны, если независимые от власти журналисты продолжают свою работу день за днем, год за годом. Мы рассказываем важные истории уже шесть лет. Помогите нам продолжать.","is_active":true,"background":"linear-gradient(10deg, #421f20 5%, #994146)"}],"en":[{"id":"nj1py","title":"Important stories don’t tell themselves","subtitle":"Independent journalism comes at a cost. We answer to no owners or advertisers — only to you, our readers.  Your ongoing support allows us to keep exposing the truth. Without you, we won’t be here.","is_active":true,"background":"linear-gradient(10deg, #421f20 5%, #994146)"},{"id":"xdfc1","title":"Help us outlast the Kremlin censorship","subtitle":"Censorship lose to journalism that keeps showing up, year after year. Monthly donors are what make that possible","is_active":true,"background":"linear-gradient(10deg, #421f20 5%, #994146)"},{"id":"ck121","title":"State propaganda has billions to spend. We have only you to rely on","subtitle":"Change happens when independent journalists keep showing up — day after day, year after year. Six years in, we're still showing up. Help us keep going with a monthly donation.","is_active":true,"background":"linear-gradient(10deg, #421f20 5%, #994146)"}]},"feedback_page":true,"donorsCount":0,"showAuthorsRequestAfterMaterial":true,"radioPage":true,"radioExists":{"ru":true,"en":false},"singlePlaylistPath":{"ru":"/radio/2025/12/22/razgovori-ovazhnikh/index.html"},"with_bookmarks":true,"news_feed":true,"news_feed_skeleton":false,"news_page_redesign":true,"with_topics":true,"materials_topics":false,"topics_page":true,"with_pdf_share":false,"with_native_share":false,"preferred_source_page":true,"charon_new_form":true,"preferred_source_promos":true,"charon_en_page":true},"pk":265,"header":"Пишем своего робота на Python. Урок 4","lead":"Узнаем, какие именно данные мы можем получить из API проекта «ГосЗатраты» и как правильно запрашивать их","category":"workshops","entry_image":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-1920x960px_1x.webp","url_2x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-1920x960px_2x.webp","for_width":1920,"for_height":960,"real_width_1x":1920,"real_width_2x":3840,"real_height_1x":960,"real_height_2x":1920},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-1920x960px_1x.png","url_2x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-1920x960px_2x.png","for_width":1920,"for_height":960,"real_width_1x":1920,"real_width_2x":3840,"real_height_1x":960,"real_height_2x":1920},{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-1272x636px_1x.webp","url_2x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-1272x636px_2x.webp","for_width":1272,"for_height":636,"real_width_1x":1272,"real_width_2x":2544,"real_height_1x":636,"real_height_2x":1272},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-1272x636px_1x.png","url_2x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-1272x636px_2x.png","for_width":1272,"for_height":636,"real_width_1x":1272,"real_width_2x":2544,"real_height_1x":636,"real_height_2x":1272},{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-912x456px_1x.webp","url_2x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-912x456px_2x.webp","for_width":912,"for_height":456,"real_width_1x":912,"real_width_2x":1824,"real_height_1x":456,"real_height_2x":912},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-912x456px_1x.png","url_2x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-912x456px_2x.png","for_width":912,"for_height":456,"real_width_1x":912,"real_width_2x":1824,"real_height_1x":456,"real_height_2x":912},{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-600x400px_1x.webp","url_2x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-600x400px_2x.webp","for_width":600,"for_height":400,"real_width_1x":600,"real_width_2x":1200,"real_height_1x":400,"real_height_2x":800},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-600x400px_1x.png","url_2x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-600x400px_2x.png","for_width":600,"for_height":400,"real_width_1x":600,"real_width_2x":1200,"real_height_1x":400,"real_height_2x":800},{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-360x360px_1x.webp","url_2x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-360x360px_2x.webp","for_width":360,"for_height":360,"real_width_1x":360,"real_width_2x":720,"real_height_1x":360,"real_height_2x":720},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-360x360px_1x.png","url_2x":"https://static.istories.media/uploaded/images/2fb5170799b24d3ebd6d8dc10f75f8ec-360x360px_2x.png","for_width":360,"for_height":360,"real_width_1x":360,"real_width_2x":720,"real_height_1x":360,"real_height_2x":720}],"entry_image_credit":"","blocks":[{"data":"Мы продолжаем знакомиться с возможностями API проекта&nbsp;«ГосЗатраты» в рамках нашего мини-курса, где мы пишем робота, который собирает данные о контрактах, анализирует их и присылает результаты нам на почту. Сегодня мы разберемся, на какие именно данные от «ГосЗатрат» мы можем рассчитывать.","type":"p","className":""},{"data":{"id":2465,"data":{"url":"https://www.youtube.com/embed/dXUtq7ZLmWA","text":"Видео: Глеб Лиманский","provider":"youtube","rawInput":"https://www.youtube.com/watch?v=dXUtq7ZLmWA&t=39s","ratio_mobile":"16:9","ratio_desktop":"16:9"},"category":"video-embed"},"type":"video-embed"},{"data":"Откроем наш проект в редакторе Visual Studio Code и в терминале запустим виртуальное окружение командой <strong>pipenv shell</strong>, которое мы создавали в <a href=\"https://istories.media/workshops/2021/04/16/pishem-svoego-robota-na-python-urok-2/\" data-type=\"usual\" target=\"_blank\">одном из прошлых выпусков</a>.&nbsp;В этом проекте у нас уже есть функция, которая на входе получает номер региона, а возвращает контракты, которые были заключены в этом регионе. Давайте используем эту функцию, а возвращенный результат запишем в JSON-файл.&nbsp;Так нам сегодня будет удобнее работать, потому что каждый раз, когда мы запускаем код, где есть строчка <strong>request.get</strong>, мы отправляем новый запрос к серверу API «ГосЗатрат». Мы не хотим злоупотреблять и зря расходовать их ресурсы. Поэтому запустим код один раз и запишем результат в JSON-файл, с которым дальше будем работать. Давайте закомментируем <strong>print(result)</strong> с помощью символа <strong># </strong>в начале строки.","type":"p","className":""},{"data":"Чтобы сохранить JSON-файл, нам потребуется одноименная библиотека <strong>json</strong>. Импортируем ее с помощью <strong>import json</strong>. Затем запишем данные которые лежат в переменной <strong>result</strong> в файл под названием<strong> result.json</strong> и запустим наш код.","type":"p","className":""},{"data":{"id":2380,"data":{"images":[{"imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/b019f9aa95f04cc1903ea1ff4dba4153-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/b019f9aa95f04cc1903ea1ff4dba4153-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":530,"real_height_2x":1059},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/b019f9aa95f04cc1903ea1ff4dba4153-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/b019f9aa95f04cc1903ea1ff4dba4153-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":530,"real_height_2x":1059}]}]},"category":"image-embed"},"type":"image-embed"},{"data":"Можем проверить папку с проектом и увидеть, что файл создался. Перед тем, как начать с ним работать, давайте посмотрим, что лежит внутри этого файла — откроем его в браузере. В Firefox он открывается в удобном виде. Наш файл — это как бы словарь, в котором хранятся списки и другие словари. Главный ключ это <strong>contracts</strong>, сами контракты лежат в ключе <strong>data</strong>, они пронумерованы. Раскроем первый контракт и посмотрим, какие поля в нем есть и какие нам было бы интересно собрать.&nbsp;","type":"p","className":""},{"data":{"id":2381,"data":{"images":[{"imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/75e009597a474b4e8b008bd3b26f214f-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/75e009597a474b4e8b008bd3b26f214f-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":679,"real_height_2x":1358},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/75e009597a474b4e8b008bd3b26f214f-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/75e009597a474b4e8b008bd3b26f214f-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":679,"real_height_2x":1358}]}]},"category":"image-embed"},"type":"image-embed"},{"data":"Нам интересны: ссылка на сам контракт (ведет на официальный портал госзакупок), дата подписания контракта, цена заключенного контракта, заказчик и данные о нем, поставщики и данные о них, данные о предметах контракта. Попробуем достать эти сущности из нашего файла.","type":"p","className":""},{"data":"Чтобы работать с файлом <strong>result.json</strong>, создадим в нашем проекте еще один, чтобы наша функция для получения контрактов осталась целой и невредимой — в следующих уроках мы будем ее дорабатывать. Создаем проект через терминал с помощью <strong>touch sandbox.py</strong> (<strong>sandbox</strong> это название нового проекта).","type":"p","className":""},{"data":{"id":2382,"data":{"images":[{"imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/fa0e809f92a148589ef0161660f9984f-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/fa0e809f92a148589ef0161660f9984f-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":119,"real_height_2x":238},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/fa0e809f92a148589ef0161660f9984f-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/fa0e809f92a148589ef0161660f9984f-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":119,"real_height_2x":238}]}]},"category":"image-embed"},"type":"image-embed"},{"data":"Как и в главном проекте <strong>main.py</strong> нам понадобится библиотека для работы с JSON, поэтому вводим в окне нового проекта<strong> import json</strong>. После этого откроем файл <strong>result.json</strong>.","type":"p","className":""},{"data":{"id":2383,"data":{"images":[{"imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/5efbf94de7f5418083b5e98b6491b63e-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/5efbf94de7f5418083b5e98b6491b63e-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":522,"real_height_2x":1044},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/5efbf94de7f5418083b5e98b6491b63e-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/5efbf94de7f5418083b5e98b6491b63e-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":522,"real_height_2x":1044}]}]},"category":"image-embed"},"type":"image-embed"},{"data":"Как мы уже говорили, JSON-файл состоит из списков и словарей, поэтому обращаться к нему мы будем соответственно — начнем с главного ключа <strong>contracts</strong>, затем в <strong>data</strong>, опускаясь вглубь до нужных нам полей. Назовем переменную <strong>data</strong> и посмотрим, что там лежит.","type":"p","className":""},{"data":{"id":2384,"data":{"images":[{"imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/7e18f81dfa984de98b50039f1565c4f4-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/7e18f81dfa984de98b50039f1565c4f4-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":459,"real_height_2x":918},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/7e18f81dfa984de98b50039f1565c4f4-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/7e18f81dfa984de98b50039f1565c4f4-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":459,"real_height_2x":918}]}]},"category":"image-embed"},"type":"image-embed"},{"data":"В терминале мы видим все наши контракты. Теперь перебирая циклом <strong>for contract in data</strong> каждый элемент в <strong>data</strong> мы можем обращаться к каждому контракту и доставать нужные нам поля. Например, попробуем достать URL с помощью <strong>print (contract[‘ContractUrl’])</strong>. Таким способом мы можем получать данные из любого ключа в файле. Дописываем ключи <strong>price</strong> и <strong>regionCode</strong> —&nbsp;получаем цены контрактов и регион заключения (в нашем случае он один и тот же).","type":"p","className":""},{"data":{"id":2385,"data":{"images":[{"imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/13e93072f9a24805bc4b730049579948-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/13e93072f9a24805bc4b730049579948-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":558,"real_height_2x":1116},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/13e93072f9a24805bc4b730049579948-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/13e93072f9a24805bc4b730049579948-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":558,"real_height_2x":1116}]}]},"category":"image-embed"},"type":"image-embed"},{"data":"Для распаковки таких словарей и списков мы можем использовать функцию, которую изучали в <a href=\"https://istories.media/workshops/2021/02/11/vvedenie-v-python-chast-12-rekursiya/\" data-type=\"usual\" target=\"_blank\">уроке про рекурсию</a>. Эта функция принимает на вход два аргумента, один из них —&nbsp;ключ, по которому нужно найти значение, а второй —&nbsp;объект, в котором мы будем искать этот ключ и значение. Если объект будет равен <strong>None</strong>, функция вернет <strong>None</strong>.&nbsp;","type":"p","className":""},{"data":{"id":2386,"data":{"images":[{"imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/93357964349d431297c95276e4924404-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/93357964349d431297c95276e4924404-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":702,"real_height_2x":1404},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/93357964349d431297c95276e4924404-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/93357964349d431297c95276e4924404-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":702,"real_height_2x":1404}]}]},"category":"image-embed"},"type":"image-embed"},{"data":"Перепишем наш код с использованием этой функции. В<strong> contract_url </strong>введем <strong>recurs_find_key (‘ContractUrl’, contract)</strong> и далее по образцу.","type":"p","className":""},{"data":{"id":2387,"data":{"images":[{"imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/ea226a11825c4f0386fd6691139ec0c4-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/ea226a11825c4f0386fd6691139ec0c4-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":502,"real_height_2x":1004},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/ea226a11825c4f0386fd6691139ec0c4-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/ea226a11825c4f0386fd6691139ec0c4-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":502,"real_height_2x":1004}]}]},"category":"image-embed"},"type":"image-embed"},{"data":"На пунктах <strong>customer</strong>, <strong>supplier</strong> и <strong>products</strong> (заказчик, поставщики и предметы контракта соответственно) остановимся отдельно. Если мы посмотрим в файл, то увидим, что внутри, например, заказчика есть еще <a href=\"https://istories.media/workshops/2020/12/09/vvedenie-v-python-chast-6-slovari/\" data-type=\"usual\" target=\"_blank\">словарь</a>. Там лежит ИНН и название организации.&nbsp;","type":"p","className":""},{"data":{"id":2388,"data":{"images":[{"imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/8d19915767214637a649539797531cfb-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/8d19915767214637a649539797531cfb-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":443,"real_height_2x":886},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/8d19915767214637a649539797531cfb-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/8d19915767214637a649539797531cfb-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":443,"real_height_2x":886}]}]},"category":"image-embed"},"type":"image-embed"},{"data":"Если мы распечатаем данные как есть, то увидим, что нам возвращаются словари, и с этим не очень удобно работать — нам нужны название и ИНН отдельно. Перепишем функцию так, чтобы она обращалась непосредственно к ключу <strong>customer</strong> по каждой из нужных нам деталей.","type":"p","className":""},{"data":{"id":2389,"data":{"images":[{"imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/f1364e2dc61248a4a6ee8914db4fa18b-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/f1364e2dc61248a4a6ee8914db4fa18b-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":776,"real_height_2x":1551},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/f1364e2dc61248a4a6ee8914db4fa18b-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/f1364e2dc61248a4a6ee8914db4fa18b-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":776,"real_height_2x":1551}]}]},"category":"image-embed"},"type":"image-embed"},{"data":"С <strong>supplier</strong> и <strong>products</strong> немного другая история. Поставщиков и продуктов по контракту может быть больше, чем один. Поэтому в <strong>suppliers</strong> в JSON-файле лежит список. Чтобы предусмотреть этот нюанс, нужно перебрать каждого поставщика и достать из него название и ИНН. Для этого сделаем словарь <strong>suppliers_dict </strong>и для каждого поставщика в списке создадим функцию, которая будет выводить ИНН и название организации. Дальше добавим это в наш словарь, где ключом будет ИНН, а значением —&nbsp;название.&nbsp;","type":"p","className":""},{"data":{"id":2390,"data":{"images":[{"imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/fa89d50f012b4d58bdd283f8dafa46f7-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/fa89d50f012b4d58bdd283f8dafa46f7-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":511,"real_height_2x":1022},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/fa89d50f012b4d58bdd283f8dafa46f7-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/fa89d50f012b4d58bdd283f8dafa46f7-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":511,"real_height_2x":1022}]}]},"category":"image-embed"},"type":"image-embed"},{"data":"С <strong>products</strong> та же самая история. Сначала нам нужно получить имя каждой закупки. Снова воспользуемся нашей рекурсивной функцией, передадим ей список словарей, из которого будем доставать <strong>name</strong>. А дальше воспользуемся уже известными нам <a href=\"https://istories.media/workshops/2021/01/22/vvedenie-v-python-chast-10-generatori-spiskov/\" data-type=\"usual\" target=\"_blank\">генераторами списков</a>, чтобы получить список всех наименований, и превратим его в строчку функцией <strong>join</strong>, разделяя названия точкой с запятой. Назовем эту переменную <strong>subjects</strong>.","type":"p","className":""},{"data":{"id":2392,"data":{"images":[{"credit":"Используем recurs_find_key, чтобы достать ИНН и название","imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/4526e8e3665d4fe6a7321ecbecfe7f2a-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/4526e8e3665d4fe6a7321ecbecfe7f2a-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":516,"real_height_2x":1032},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/4526e8e3665d4fe6a7321ecbecfe7f2a-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/4526e8e3665d4fe6a7321ecbecfe7f2a-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":516,"real_height_2x":1032}]},{"credit":"Там, где предметов больше одного, они перечислены через точку с запятой","imagesList":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/c04d568e236a41268516d613d8f421b8-1200xautopx_1x.webp","url_2x":"https://static.istories.media/uploaded/images/c04d568e236a41268516d613d8f421b8-1200xautopx_2x.webp","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":336,"real_height_2x":672},{"format":"png","url_1x":"https://static.istories.media/uploaded/images/c04d568e236a41268516d613d8f421b8-1200xautopx_1x.png","url_2x":"https://static.istories.media/uploaded/images/c04d568e236a41268516d613d8f421b8-1200xautopx_2x.png","for_width":1200,"for_height":"auto","real_width_1x":1200,"real_width_2x":2400,"real_height_1x":336,"real_height_2x":672}]}]},"category":"two-images-embed"},"type":"two-images-embed"},{"data":"Сегодня мы достали все необходимые значения, с которыми можем что-то делать, а в следующий раз усовершенствуем нашу функцию получения данных из API «ГосЗатрат». Если у вас возникли вопросы — как всегда, пишите в наш <a href=\"https://t.me/istories_helloworld\" data-type=\"usual\" target=\"_blank\">чат</a> в Telegram.","type":"p","className":""}],"created_at_date":"2021-05-01","updated_at_date":null,"created_at_date_time":null,"updated_at_date_time":null,"is_exclusive":false,"is_urgent":false,"initially_published_at":"2021-05-23T10:27:14.006Z","has_additional_facts":false,"locale":"ru","has_visualization_without_fallback":false,"spec_project":null,"header_secondary":"","warning":"","is_translated_by_ai":false,"with_donation_banner":true,"donation_banner_header":"","donation_banner_text":"","media_outlet__codename":null,"with_authors_request_banner":false,"faq":[],"_path":"/workshops/2021/05/01/pishem-svoego-robota-na-python-urok-4/","is_published":true,"authors_list":[{"id":8,"lead":"Главная редакторка «Важных историй»","_path":"alesya-marokhovskaya","avatar":[{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-896x504px_1x.webp","url_2x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-896x504px_2x.webp","for_width":896,"for_height":504,"original_url":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-original.jpg","real_width_1x":896,"real_width_2x":1792,"real_height_1x":504,"real_height_2x":1008},{"format":"jpg","url_1x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-896x504px_1x.jpg","url_2x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-896x504px_2x.jpg","for_width":896,"for_height":504,"original_url":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-original.jpg","real_width_1x":896,"real_width_2x":1792,"real_height_1x":504,"real_height_2x":1008},{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-688x387px_1x.webp","url_2x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-688x387px_2x.webp","for_width":688,"for_height":387,"original_url":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-original.jpg","real_width_1x":688,"real_width_2x":1376,"real_height_1x":387,"real_height_2x":774},{"format":"jpg","url_1x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-688x387px_1x.jpg","url_2x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-688x387px_2x.jpg","for_width":688,"for_height":387,"original_url":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-original.jpg","real_width_1x":688,"real_width_2x":1376,"real_height_1x":387,"real_height_2x":774},{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-416x234px_1x.webp","url_2x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-416x234px_2x.webp","for_width":416,"for_height":234,"original_url":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-original.jpg","real_width_1x":416,"real_width_2x":832,"real_height_1x":234,"real_height_2x":468},{"format":"jpg","url_1x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-416x234px_1x.jpg","url_2x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-416x234px_2x.jpg","for_width":416,"for_height":234,"original_url":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-original.jpg","real_width_1x":416,"real_width_2x":832,"real_height_1x":234,"real_height_2x":468},{"format":"webp","url_1x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-336x189px_1x.webp","url_2x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-336x189px_2x.webp","for_width":336,"for_height":189,"original_url":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-original.jpg","real_width_1x":336,"real_width_2x":672,"real_height_1x":188,"real_height_2x":378},{"format":"jpg","url_1x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-336x189px_1x.jpg","url_2x":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-336x189px_2x.jpg","for_width":336,"for_height":189,"original_url":"https://static.istories.media/uploaded/images/12285015ded6416c9ce475e3a939d7f7-original.jpg","real_width_1x":336,"real_width_2x":672,"real_height_1x":188,"real_height_2x":378}],"lead_en":"Editor-in-chief","ordering":null,"position":"Редакторка","is_public":true,"last_name":"Мароховская","first_name":"Алеся","position_en":"Editor","last_name_en":"Marokhovskaya","first_name_en":"Alesya"}],"external_authors_list":[],"editors_list":[],"external_editors_list":[],"participants_list":[],"external_participants_list":[],"partners_list":[],"case":null,"translated_material":null,"audio_material":null,"text_material":null,"id":265,"topics":[],"meta":{"og_title":"","og_description":"","twitter_title":"","twitter_description":"","og_image":"https://static.istories.media/uploaded/images/share/59c71dad57ec454f9bc24d65c8929022.png","twitter_image":"https://static.istories.media/uploaded/images/share/59c71dad57ec454f9bc24d65c8929022.png","vk_image":"https://static.istories.media/uploaded/images/share/vk/68dd46102e04474394b3f996a03d069d.png"},"tags":["api","ddj","json","python"],"playlist":null,"socialMediaBanners":[{"id":10,"text":"У пропаганды есть миллиарды из бюджета. У нас — только вы","link":"","codename":"donation"},{"id":14,"text":"Список погибших и пропавших без вести российских военных","link":"","codename":"haron"},{"id":18,"text":"","link":"","codename":"mobile_app"},{"id":6,"text":"Оставайтесь на связи: подпишитесь на нашу рассылку","link":"","codename":"newsletter"}]}},"staticQueryHashes":["764694655"],"slicesMap":{}}