Ejemplo n.º 1
0
def main(argv):
    args = docopt(__doc__, argv=argv)

    identifiers = [i.strip() for i in open(args['<itemlist.txt>'])]
    workers = int(args.get('--workers', 20)[0])
    miner = get_data_miner(identifiers, workers=workers)

    # If writing all metadata to a single output file, make sure that
    # file is empty.
    if args['--output']:
        open(args['--output'][0], 'w').close()

    for i, item in miner.items():
        metadata = dumps(item.metadata)
        if args['--cache']:
            stdout.write('saving metadata for: {0}\n'.format(item.identifier))
            with open('{0}_meta.json'.format(item.identifier), 'w') as fp:
                fp.write(metadata)
        elif args['--output']:
            stdout.write('saving metadata for: {0}\n'.format(item.identifier))
            with open(args['--output'][0], 'a+') as fp:
                fp.write(metadata + '\n')
        else:
            stdout.write(metadata + '\n')
    exit(0)
Ejemplo n.º 2
0
def main(argv):
    args = docopt(__doc__, argv=argv)

    identifiers = [i.strip() for i in open(args['<itemlist.txt>'])]
    workers = int(args.get('--workers', 20)[0])
    miner = get_data_miner(identifiers, workers=workers)

    # If writing all metadata to a single output file, make sure that 
    # file is empty.
    if args['--output']:
        open(args['--output'][0], 'w').close()

    for i, item in miner.items():
        metadata = dumps(item.metadata)
        if args['--cache']:
            stdout.write('saving metadata for: {0}\n'.format(item.identifier))
            with open('{0}_meta.json'.format(item.identifier), 'w') as fp:
                fp.write(metadata)
        elif args['--output']:
            stdout.write('saving metadata for: {0}\n'.format(item.identifier))
            with open(args['--output'][0], 'a+') as fp:
                fp.write(metadata + '\n')
        else:
            stdout.write(metadata + '\n')
    exit(0)
Ejemplo n.º 3
0
def main(argv):
    args = docopt(__doc__, argv=argv)

    if args['<itemlist.txt>'] == '-':
        itemfile = sys.stdin
    else:
        itemfile = open(args['<itemlist.txt>'])
    with itemfile:
        identifiers = [i.strip() for i in itemfile]

    workers = int(args.get('--workers', 20)[0])
    miner = get_data_miner(identifiers, workers=workers)

    for i, item in miner:
        metadata = json.dumps(item._json)
        if args['--cache']:
            sys.stderr.write('saving metadata for: {0}\n'.format(item.identifier))
            with open('{0}_meta.json'.format(item.identifier), 'w') as fp:
                fp.write(metadata)
        elif args['--output']:
            sys.stderr.write('saving metadata for: {0}\n'.format(item.identifier))
            with open(args['--output'], 'a+') as fp:
                fp.write(metadata + '\n')
        else:
            try:
                sys.stderr.write(metadata + '\n')
            except IOError:
                break
    sys.exit(0)
Ejemplo n.º 4
0
def main(argv):
    args = docopt(__doc__, argv=argv)

    if args['<itemlist.txt>'] == '-':
        itemfile = sys.stdin
    else:
        itemfile = open(args['<itemlist.txt>'])
    with itemfile:
        identifiers = [i.strip() for i in itemfile]

    workers = int(args.get('--workers', 20)[0])
    miner = get_data_miner(identifiers, workers=workers)

    # Progress bar
    if args['--cache'] or args['--output']:
        if args['<itemlist.txt>'] != '-':
            itemfile_fname = args['<itemlist.txt>']
        else:
            itemfile_fname = 'stdin'
        miner = progress.bar(
            miner,
            expected_size=len(identifiers),
            label='mining items from {0}: '.format(itemfile_fname))

    for i, item in miner:
        metadata = json.dumps(item._json)
        if args['--cache']:
            with open('{0}_meta.json'.format(item.identifier), 'w') as fp:
                fp.write(metadata)
        elif args['--output']:
            with open(args['--output'], 'a+') as fp:
                fp.write(metadata + '\n')
        else:
            try:
                sys.stdout.write(metadata + '\n')
            except IOError:
                break
    sys.exit(0)
Ejemplo n.º 5
0
def main(argv):
    args = docopt(__doc__, argv=argv)

    if args["<itemlist.txt>"] == "-":
        itemfile = sys.stdin
    else:
        itemfile = open(args["<itemlist.txt>"])
    with itemfile:
        identifiers = [i.strip() for i in itemfile]

    workers = int(args.get("--workers", 20)[0])
    miner = get_data_miner(identifiers, workers=workers)

    # Progress bar
    if args["--cache"] or args["--output"]:
        if args["<itemlist.txt>"] != "-":
            itemfile_fname = args["<itemlist.txt>"]
        else:
            itemfile_fname = "stdin"
        miner = progress.bar(
            miner, expected_size=len(identifiers), label="mining items from {0}: ".format(itemfile_fname)
        )

    for i, item in miner:
        metadata = json.dumps(item._json)
        if args["--cache"]:
            with open("{0}_meta.json".format(item.identifier), "w") as fp:
                fp.write(metadata)
        elif args["--output"]:
            with open(args["--output"], "a+") as fp:
                fp.write(metadata + "\n")
        else:
            try:
                sys.stderr.write(metadata + "\n")
            except IOError:
                break
    sys.exit(0)
Ejemplo n.º 6
0
def main(argv):
    args = docopt(__doc__, argv=argv)

    if args['<itemlist.txt>'] == '-':
        itemfile = sys.stdin
    else:
        itemfile = open(args['<itemlist.txt>'])
    with itemfile:
        identifiers = [i.strip() for i in itemfile]

    workers = int(args.get('--workers', 20)[0])
    miner = get_data_miner(identifiers, workers=workers)

    # Progress bar
    if args['--cache'] or args['--output']:
        if args['<itemlist.txt>'] != '-':
            itemfile_fname = args['<itemlist.txt>']
        else:
            itemfile_fname = 'stdin'
        miner = progress.bar(miner, expected_size=len(identifiers),
                             label='mining items from {0}: '.format(itemfile_fname))

    for i, item in miner:
        metadata = json.dumps(item._json)
        if args['--cache']:
            with open('{0}_meta.json'.format(item.identifier), 'w') as fp:
                fp.write(metadata)
        elif args['--output']:
            with open(args['--output'], 'a+') as fp:
                fp.write(metadata + '\n')
        else:
            try:
                sys.stdout.write(metadata + '\n')
            except IOError:
                break
    sys.exit(0)