コード例 #1
0
def prompt_add_movie():
    title = input("Enter movie name: ")
    release_date = input("Enter the release date (dd-mm-YYYY): ")
    parsed_date = datetime.datetime.strptime(release_date, "%d-%m-%Y")
    timestamp = parsed_date.timestamp()
    database.add_movie(title, timestamp)
    os.system('clear')
コード例 #2
0
def prompt_add_movie():
    title = input("Movie title: ")
    release_date = input("Release date (dd-mm-yyyy): ")
    parsed_date = datetime.datetime.strptime(release_date, "%d-%m-%Y")
    timestamp = parsed_date.timestamp()

    database.add_movie(title, timestamp)
コード例 #3
0
def prompt_add_movie():
    title = input("Enter movie title: ")
    release_date = input("Insert movie release date (mm-dd-YYYY): ")
    parsed_datetime = datetime.datetime.strptime(release_date, "%m-%d-%Y")
    timestamp = parsed_datetime.timestamp()

    database.add_movie(title, timestamp)
コード例 #4
0
def prompt_add_movie():
    title = input("Movie title: ")
    release_date = input("Release date (dd-mm-YYYY): "
                         ) or datetime.datetime.today().strftime("%d-%m-%Y")
    release_timestamp = datetime.datetime.strptime(release_date,
                                                   "%d-%m-%Y").timestamp()
    database.add_movie(title, release_timestamp)
コード例 #5
0
def prompt_add_movie():
    title = input("Movie title: ")
    release_date = input("Relase date (dd-mm-yyyy): ")
    #parse the string into a datetime object(release_date string, format string(what format the string is in))
    parsed_date = datetime.datetime.strptime(release_date, "%d-%m-%Y")#object
    timestamp = parsed_date.timestamp()
    database.add_movie(title, timestamp)
コード例 #6
0
def prompt_add_movie():
    title = input("Название фильма: ")
    release_date = input("Дата появления (дд.мм.гггг): ")
    print("---- \n")
    parsed_date = datetime.datetime.strptime(release_date, "%d.%m.%Y")
    timestamp = parsed_date.timestamp()

    database.add_movie(title, timestamp)
コード例 #7
0
def test_add_movie_with_empty_title_string_raises_value_error(connection, session, monkeypatch):
    expected = "Year string expected but got empty string."
    monkeypatch.setattr(database.logging, 'error', lambda msg: None)
    
    bad_row = dict(title='Hamlet', director='Branagh', minutes=242, year='')
    with pytest.raises(ValueError) as exc:
        database.add_movie(bad_row)
    assert str(exc.value) == expected
コード例 #8
0
def prompt_inputs():
    input_title = input('Enter movie title: ')
    input_date = input(
        'Enter the release date of the movie (ex. yyyy-mm-dd): ')

    parsed_date = datetime.datetime.strptime(input_date, '%Y-%m-%d')
    timestamp = parsed_date.timestamp()

    add_movie(input_title, timestamp)
コード例 #9
0
def test_add_movie_with_empty_title_string_logs_error(connection, session, monkeypatch):
    expected = "Year string expected but got empty string."
    calls = []
    monkeypatch.setattr(database.logging, 'error', lambda msg: calls.append(msg))
    
    bad_row = dict(title='Hamlet', director='Branagh', minutes=242, year='')
    with pytest.raises(ValueError):
        database.add_movie(bad_row)
    assert calls == [expected]
コード例 #10
0
def prompt_add_movie():
    title = input("Movie Name: ")
    release_date = input("Release date (dd-mm-yyyy): ")
    parsed_date = datetime.datetime.strptime(
        release_date,
        "%d-%m-%Y")  # date and format of the date we are gonna parse
    timestamp = parsed_date.timestamp()

    database.add_movie(title, timestamp)
コード例 #11
0
def test_add_movie(connection, session, hamlet):
    expected = tuple(hamlet.values())
    database.add_movie(hamlet)
    result = (session.query(database.Movie.title,
                            database.Movie.director,
                            database.Movie.minutes,
                            database.Movie.year, )
              .one())
    assert result == expected
コード例 #12
0
def prompt_add_movie():
    """
    A function asking the user to add new movie and release date.
    :return:
    """
    title = input("Movie title: ")
    release_date = input('Release date in format dd-mm-YYYY: ')
    parsed_date = datetime.datetime.strptime(release_date, '%d-%m-%Y')
    timestamp = parsed_date.timestamp()
    database.add_movie(title, timestamp)
コード例 #13
0
def test_add_movie_with_notes(connection, session, revanche):
    expected = tuple(revanche.values())
    database.add_movie(revanche)
    result = (session.query(database.Movie.title,
                            database.Movie.director,
                            database.Movie.minutes,
                            database.Movie.year,
                            database.Movie.notes, )
              .one())
    assert result == expected
コード例 #14
0
def add_movie_callback(movie: config.MovieTypedDict,
                       selected_tags: Sequence[str]):
    """ Add user supplied data to the database.

    Args:
        movie:
        selected_tags:
    """
    database.add_movie(movie)
    movie = config.MovieKeyTypedDict(title=movie['title'], year=movie['year'])
    for tag in selected_tags:
        database.add_movie_tag_link(tag, movie)
コード例 #15
0
def todos_list():
    form = TodoForm()
    error = ""
    if request.method == "POST":
        if form.validate_on_submit():
            database.add_movie(form.data)
        return redirect(url_for("todos_list"))

    return render_template("todos.html",
                           form=form,
                           todos=database.select_all(),
                           error=error)
コード例 #16
0
    def test_add_twice_the_same_movie_and_delete(self):
        cortege = {
            'title': 'add_function_test_title', 'year': 2014,
            'genre': '', 'rating': '',
            'description': '', 'path': ''
        }
        title, year = cortege['title'], cortege['year']
        database.delete_movie(title, year)

        self.assertTrue(database.add_movie(cortege))
        self.assertFalse(database.add_movie(cortege))
        self.assertTrue(database.delete_movie(title, year))
コード例 #17
0
def create_todo():
    if not request.get_json(force=True) or not 'title' in request.get_json(
            force=True):
        print(request.get_json(force=True))
        abort(404)
    todo = {
        'title': request.get_json(force=True)['title'],
        'description': request.get_json(force=True).get('description', ""),
        'done': False
    }
    database.add_movie(todo)
    return jsonify({'todo': todo}), 201
コード例 #18
0
def test_add_movie_with_non_numeric_values(connection, session, monkeypatch):
    bad_int = 'forty two'
    expected = f"invalid literal for int() with base 10: '{bad_int}'"
    logging_msg = (f'{expected}\nA non-integer value has been supplied for either the year '
                   f'or the minute column.')
    calls = []
    monkeypatch.setattr(database.logging, 'error', lambda msg: calls.append(msg))

    bad_row = dict(title='Hamlet', director='Branagh', minutes=bad_int, year='1942')
    with pytest.raises(ValueError) as exc:
        database.add_movie(bad_row)
    assert str(exc.value) == expected
    assert calls[0] == logging_msg
コード例 #19
0
    def test_add_cortege_with_primary_key_title_equal_to_none(self):
        movie_row_title_none = {
            'title': None, 'year': '',
            'genre': '', 'rating': '',
            'description': '', 'path': ''
        }

        self.assertFalse(database.add_movie(movie_row_title_none))
コード例 #20
0
    def test_add_movie_with_title_equal_to_number_and_delete(self):
        cortege = {
            'title': 123456789, 'year': 2014,
            'genre': '', 'rating': '',
            'description': '', 'path': ''
        }
        title, year = cortege['title'], cortege['year']
        database.delete_movie(title, year)

        self.assertTrue(database.add_movie(cortege))
        self.assertTrue(database.delete_movie(title, year))
コード例 #21
0
 def create_cortege(self):
     movie_row = {
         'title': self.title.text(),
         'year': int(self.year.currentText()),
         'genre': '/'.join([item.text() for item in self.genre.selectedItems()]),
         'rating': self.rating.currentText(),
         'description': self.description.toPlainText(),
         'path': self.path_display.text()
     }
     if not database.add_movie(movie_row):
         self.warning_message("Movie already exist!")
     else:
         self.added.emit()
         self.done(True)
         self.closeEvent(QCloseEvent)
コード例 #22
0
ファイル: impexp.py プロジェクト: trin5tensa/moviedb
def import_movies(fn: str):
    """Import a csv file into the database.

    File format
    The first record will be a header row which must contain the column names 'title' and 'year'.
    It may contain column names 'minutes', 'director', and 'notes'.
    The fields of each row must comply with the columns defined by the headed row.

    Validation
    The entire file will be rejected if there are any invalid names in the first row.
    Individual records will be rejected if they are the wrong length or if they violate
    the database's integrity rules.

    Output FIle
    Rejected records will be written to a file of the same name with a suffix of '_reject.csv'.
    The valid header row will be written to that file as the first record as a convenience to the user.

    Args:
        fn: Name of import file.
    """
    reject_file_created = False

    with open(fn, newline='', encoding='utf-8') as csvfile:
        movies_reader = csv.reader(csvfile)

        # Get headers and validate.
        header_row = next(movies_reader)
        header_row = list(map(str.lower, header_row))
        valid_len = len(header_row)
        write_reject_file = create_reject_file(fn, header_row)

        for row in movies_reader:
            # Validate row length
            if len(row) != valid_len:
                msg = ("Row has too many or too few items.",)
                write_reject_file(msg, row)
                reject_file_created = True
                continue

            # Write movie to database
            movie = dict(zip(header_row, row))
            try:
                database.add_movie(movie)

            except database.sqlalchemy.exc.IntegrityError as exception:
                msg = (str(exception),)
                write_reject_file(msg, row)
                reject_file_created = True

            # ValueError is raised by invalid row values.
            except ValueError:
                msg = (f'{sys.exc_info()[0].__name__}: {sys.exc_info()[1]}',)
                write_reject_file(msg, row)
                reject_file_created = True

            # TypeError is raised by faulty headers so halt row processing.
            except TypeError:
                msg = (f"{sys.exc_info()[0].__name__}: The header row is bad.\n"
                       "It is missing a required column, has an invalid column, or has a "
                       "blank column.\n"
                       "Note that only the first error is reported.\n"
                       f"{sys.exc_info()[1]}"),
                row = ('',)
                write_reject_file(msg, row)
                reject_file_created = True
                break

    # Let the user know there if there are input data problems which need fixing.
    if reject_file_created:
        msg = (f"The import file '{fn}' has invalid data. "
               f"See '{fn}_reject.csv' file for details.")
        raise MoviedbInvalidImportData(msg)
コード例 #23
0
def prompt_add_movie():
    title = input('Movie title: ')
    release_date = input('Release date (dd-mm-YYYY): ')
    parsed_date = datetime.datetime.strptime(release_date, '%d-%m-%Y')
    timestamp = parsed_date.timestamp()
    database.add_movie(title, timestamp)
コード例 #24
0
ファイル: movies.core.py プロジェクト: eleijonmarck/code
def add_a_movie():
    title = input("what title is the movie")
    description = input("describe what the movie is about")
    likes = int(input("how do you like it from one to 10"))
    database.add_movie(title,description,likes)
    return print("Movie %s added to the collection" % (title))