0
\$\begingroup\$

I wanted to ask you a favor.

I am recruiting for the position of Junior Python Developer (my first try in IT) and I got a task to create a script to manage the task list.

https://github.com/Lok3rs/Todo-CLI

Could you please give me some feedback about that script? I will be very grateful!

Thanks in advance, keep your fingers crossed!

init.py

import os
from sqlalchemy import create_engine, MetaData
from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql.ddl import CreateTable
from sqlalchemy_utils import database_exists, create_database
from sqlalchemy.exc import OperationalError

from tasks.model.model import Task
from tasks.model.validators import Validator
from tasks.view.terminal import View

engine = create_engine("mysql+mysqldb://{}:{}@{}/{}".format(
    os.environ.get("MYSQL_USERNAME"),
    os.environ.get("MYSQL_PASSWORD"),
    os.environ.get("MYSQL_HOST"),
    os.environ.get("MYSQL_DB")
))

meta = MetaData()
meta.bind = engine
Session = sessionmaker(bind=engine)
session = Session()

view = View()
validator = Validator()

tasks_table = Task.__table__

try:
    if not database_exists(engine.url):
        create_database(engine.url)
        meta.create_all()
        engine.connect().execute(CreateTable(tasks_table))
        print(f"Database named {os.environ.get('MYSQL_DB')} created successfully.")
    else:
        engine.connect()
except OperationalError as err:
    print(err)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.