コード例 #1
0
ファイル: moary.py プロジェクト: 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)
コード例 #2
0
ファイル: edit_entry.py プロジェクト: progo/moary
def parse_string(string):
    """Read in the [multiline] string and parse it into an Entry."""
    # TODO could use a rewrite without lazy patches

    def clean_line(s):
        """remove initial label from the beginning of the line"""
        return re.sub(r"\A.*?: ?", "", s.strip()).strip()

    f = io.StringIO(string.lstrip())
    f.seek(0)

    # now just go through the file format
    entry = Entry(movie=clean_line(f.readline()))
    entry.rating = clean_line(f.readline())
    entry.imdb = clean_line(f.readline())
    f.readline()
    entry.message = f.read().strip()
    return entry