Beispiel #1
0
def download_by(corpus, author, title):
    """Download documents by author and title from a remote corpus. """

    if corpus not in REMOTE_CORPORA:
        click.echo(f"[-] no remote location for '{corpus}'")
    else:
        try:
            c = Corpus(corpus)
            if not (author or title):
                manifest = c.remote_manifest()
                for docix, meta in manifest.items():
                    click.echo(
                        f"[{docix}] {meta['author']}, {meta['title']} [{meta['filename']}]"
                    )
            else:
                n = len(c.manifest)
                with click_spinner.spinner():
                    c.download_by(author, title)
                click.echo(f"[+] downloaded {len(c.manifest) - n} documents")
        except Exception as e:
            click.echo("[-] failed", e)
Beispiel #2
0
def download_by_docix(corpus, docix):
    """Download a document by number from a remote corpus. """

    if corpus not in REMOTE_CORPORA:
        click.echo(f"[-] no remote location for '{corpus}'")
    else:
        c = Corpus(corpus)
        try:
            if not docix:
                manifest = c.remote_manifest()
                for docix, meta in manifest.items():
                    click.echo(
                        f"[{docix}] {meta['author']}, {meta['title']} [{meta['filename']}]"
                    )
            else:
                with click_spinner.spinner():
                    c.download_by_docix(int(docix))
                meta = c.manifest[docix]
                click.echo(
                    f"[{docix}] {meta['author']}, {meta['title']} [{meta['filename']}]"
                )
        except Exception as e:
            click.echo("[-] failed", e)