예제 #1
0
def build(src: str, **_) -> str:
    """Build word store from URL(s).

    Args:
        src: source(s) to scrape. Can be URL, or file containing one URL per
            line.

    Returns:
        Words store as json.
    """
    # Make sure src is iterable.
    src_as_file = os.path.abspath(os.path.expanduser(src))
    sources = (
        (s for s in iter_sources(src))
        if os.path.isfile(src_as_file) else
        (s for s in [src])
    )

    # Scrape source(s).
    words = WordStore()
    for source in sources:
        words += scrape(source)

    # Output results.
    return words.to_json()
예제 #2
0
def test_empty():
    words = WordStore()
    json_str = words.to_json()
    reconstructed_words = WordStore.from_json(json_str)

    assert reconstructed_words.store == words.store