Ejemplo n.º 1
0
def edit_data_interactive(olddata, skip_imdb=False):
    """given the Entry, invoke editor on user to edit the entry. Return the
    Entry with possibly updated info."""

    with tempfile.NamedTemporaryFile(mode='w+') as tf:
        oldform = fill_in_form(olddata)
        newform = invoke_editor(oldform, tf)
        newdata = parse_string(newform)

        if not newdata.movie:
            raise UserCancel()

        try:
            newdata.imdb = imdbutils.just_work_dammit(newdata, olddata,
                                                      skip=skip_imdb)
        except Exception as e:
            # Yes, again the old dilemma: should we keep existing
            # value or clear it? I say, clear it, because the user
            # will be notified of the problem and he can try again
            # soon.
            print("IMDB couldn't be reached!", e)
            newdata.imdb = ''

        if olddata and olddata.rating and not is_valid_rating(newdata.rating):
            newdata.rating = olddata.rating
        elif not is_valid_rating(newdata.rating):
            newdata.rating = '0'

        newdata.update = datetime.datetime.now()

        return newdata
Ejemplo n.º 2
0
Archivo: moary.py Proyecto: progo/moary
def do_add(args):
    """CLI func to call when doing subtask "add". """
    # Three kinds of cases here in a mess:
    # 1. movie name provided (possibly other info) (go batch)
    # 2. movie name not provided, IMDB provided (go batch)
    # 3. neither is provided, go interactive
    # TODO refactoring needed. Replace functions and so on.
    db = data.DataFacilities(dbfile=args.db_file)
    if args.movie:
        # 1. batch
        newflick = Entry(args.movie,
                         args.rating,
                         args.imdb,
                         args.message or "")
        newflick.imdb = imdbutils.just_work_dammit(newflick,
                skip=args.skip_imdb)
    elif args.imdb:
        # 2. batch: No movie name given but something of an IMDB id
        if args.skip_imdb:
            print("Can't do this without querying IMDB!")
            return
        try:
            moviename = imdbutils.query_imdb_name(args.imdb)
            clean_id = imdbutils.clean_imdb_id(args.imdb)
        except imdbutils.BadIMDBIdException:
            print("Malformed IMDB id, aborting.")
            return
        except imdbutils.NoIMDBpyException:
            print("Can't do this without querying IMDB! (No IMDBpy)")
            return
        newflick = Entry(moviename, imdb=clean_id, rating=args.rating,
                         message=args.message or "")
    else:
        # 3. interactive
        try:
            newflick = edit_entry.edit_data_interactive(None,
                    skip_imdb=args.skip_imdb)
            if not args.skip_imdb:
                from textwrap import fill
                #triv = imdbutils.query_random_trivia(newflick.imdb)
                #if triv: print 'TRIVIA:',fill(triv )
        except edit_entry.UserCancel:
            print("Empty name, exiting...")
            return 0
    if args.debug:
        print(newflick.__dict__)
    else:
        db.store_entry(newflick)
Ejemplo n.º 3
0
def edit_data_interactive(olddata, skip_imdb=False):
    """given the Entry, invoke editor on user to edit the entry. Return the
    Entry with possibly updated info."""

    with tempfile.NamedTemporaryFile() as tf:
        oldform = fill_in_form(olddata)
        newform = invoke_editor(oldform, tf)
        newdata = parse_string(newform)

        if not newdata.movie:
            raise UserCancel()

        newdata.imdb = imdbutils.just_work_dammit(newdata, olddata,
                skip=skip_imdb)

        if olddata and olddata.rating and not is_valid_rating(newdata.rating):
            newdata.rating = olddata.rating
        elif not is_valid_rating(newdata.rating):
            newdata.rating = '0'

        newdata.update = datetime.datetime.now()

        return newdata