Exemplo n.º 1
0
def main():

    args = get_args()

    if args.database == 'sqlite':
        # Option to use SQLite instead of PostgreSQL
        engine = create_engine('sqlite:///sqlite3.db')
        # sqlite session
        engine, session = create_sqlite_session(engine=engine)

        Base.metadata.create_all(engine)

        # Autoload some data without user/CLI interface
        insert_category_data(session=session)
        insert_director_data(session=session)
        insert_actor_data(session=session)
        insert_account_data(session=session)
        insert_movie_data(session=session)
        insert_theater_data(session=session)

        print_header()

        try:
            while True:
                if find_user_intent() == 'find':
                    cinephile_sqlite.run()
                else:
                    theater_owner_sqlite.run()
        except KeyboardInterrupt:
            return

        session.close()

    else:
        # postgresql session
        engine, session = create_session()

        Base.metadata.create_all(engine)

        # Autoload some data without user/CLI interface
        insert_category_data(session=session)
        insert_director_data(session=session)
        insert_actor_data(session=session)
        insert_account_data(session=session)
        insert_movie_data(session=session)
        insert_theater_data(session=session)

        print_header()

        try:
            while True:
                if find_user_intent() == 'find':
                    cinephile.run()
                else:
                    theater_owner.run()
        except KeyboardInterrupt:
            return

        session.close()
Exemplo n.º 2
0
def main():
    """
    Pydango-pip's main executable function.  Gets the database argument
    from the command-line.  Using SQLAlchemy's ORM pattern, creates an engine
    and session.  The session is then used to create the database schema:
    tables and relations.

    We then automatically load initial data into those tables using 
    insert_<table_name>_data(session=session) functions.

    We then divide our users into two distinct groups with the find_user_intent function:

    1. cinephile (people who want to watch movies)
    2. theater_owner (people who own movies theaters and supply the movies to watch)


    And execute the CLI flow for the respective user types.
    """

    args = get_args()

    if args.database == 'sqlite':
        # Option to use SQLite instead of PostgreSQL
        engine = create_engine('sqlite:///sqlite3.db')
        # sqlite session
        engine, session = create_sqlite_session(engine=engine)

        Base.metadata.create_all(engine)

        # Autoload some data without user/CLI interface
        insert_category_data(session=session)
        insert_director_data(session=session)
        insert_actor_data(session=session)
        insert_account_data(session=session)
        insert_movie_data(session=session)
        insert_theater_data(session=session)

        print_header()

        try:
            while True:
                if find_user_intent() == 'find':
                    cinephile_sqlite.run()
                else:
                    theater_owner_sqlite.run()
        except KeyboardInterrupt:
            return

        session.close()
    else:
        print(
            "\nYou must provide the '-d sqlite' flag to execute this program.\n"
        )
        print("\nFor help:\n")
        print("python -m pydango -h\n")
Exemplo n.º 3
0
    Movie,
    Payment,
    Ticket,
    Theater,
    theater_schedule,
)

from sqlalchemy.sql import (
    update,
    and_,
)

# Unfortunate I could not find a way to get around creating a
# second connection the sqlite DB here
engine = create_engine('sqlite:///sqlite3.db')
engine, session = create_sqlite_session(engine=engine)


def run():
    """

    The main executable function for the cinephile type of user

    """

    print('****************** Hello Cinephile ******************')
    print()

    show_commands()

    while True: