GithubHelp home page GithubHelp logo

asyncio's Introduction

Установка и запуск

Подготовка

Для запуска необходимо заполнить файл .env.template

POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=
DB_HOST=127.0.0.1
DB_PORT=5431

Создайте вертуально окружение

python -m venv ...

Активируйте окружение

.../Scripts/Activate

Установите зависимости

pip install -r requirements.txt

Запустить файл docker compose командой. Будет создана БД.

docker compose up -d

Запустите файл main.py

main.py

Подключитесь к БД для проверки. Параметры для подключения такие же как указали в .env.template. Обратите внимение на PORT: 5431

POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=
DB_HOST=127.0.0.1
DB_PORT=5431

Результат работы программы находится в файле result

Домашнее задание к лекции «Asyncio»

В этом задании мы будем выгружать из API персонажей Start Wars и загружать в базу данных.
Документация по API находится здесь: SWAPI.
Пример запроса: https://swapi.dev/api/people/1/
В результате запроса получаем персонажа с ID 1:

{
    "birth_year": "19 BBY",
    "eye_color": "Blue",
    "films": [
        "https://swapi.dev/api/films/1/",
        ...
    ],
    "gender": "Male",
    "hair_color": "Blond",
    "height": "172",
    "homeworld": "https://swapi.dev/api/planets/1/",
    "mass": "77",
    "name": "Luke Skywalker",
    "skin_color": "Fair",
    "created": "2014-12-09T13:50:51.644000Z",
    "edited": "2014-12-10T13:52:43.172000Z",
    "species": [
        "https://swapi.dev/api/species/1/"
    ],
    "starships": [
        "https://swapi.dev/api/starships/12/",
        ...
    ],
    "url": "https://swapi.dev/api/people/1/",
    "vehicles": [
        "https://swapi.dev/api/vehicles/14/"
        ...
    ]
}

Необходимо выгрузить cледующие поля:
id - ID персонажа
birth_year
eye_color
films - строка с названиями фильмов через запятую
gender
hair_color
height
homeworld
mass
name
skin_color
species - строка с названиями типов через запятую
starships - строка с названиями кораблей через запятую
vehicles - строка с названиями транспорта через запятую
Данные по каждому персонажу необходимо загрузить в любую базу данных.
Выгрузка из апи и загрузка в базу должна происходить асинхронно.

Результатом работы будет:

  1. скрипт миграции базы данных
  2. скрипт загрузки данных из API в базу

В базу должны быть загружены все персонажи

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.