from pathlib import Path
from xml.etree.ElementTree import parse

import fire
import polars as pl


def run(inpath="data/NSF/2022", outpath="data/NSF/nsf_2022.parquet"):
    titles = []
    abstracts = []

    for file in Path(inpath).glob("*.xml"):
        doc = parse(file)
        award = doc.find("Award")
        titles.append(award.findtext("AwardTitle"))
        abstracts.append(award.findtext("AbstractNarration"))

    df = pl.DataFrame({"title": titles, "abstract": abstracts})
    df.write_parquet(outpath)


if __name__ == "__main__":
    fire.Fire(run)
