-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vox_run
executable file
·56 lines (38 loc) · 1.4 KB
/
vox_run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
from datetime import date
from pathlib import Path
from typing import Optional
import typer
from voxcharta_my_voting_record.logger import LogClass
from voxcharta_my_voting_record import extract, __version__
today = date.today()
help1 = "Full path of VoxCharta My Voting Record HTML"
help2 = "Full path and prefix of output JSON/CSV files"
def main(
filename: str = typer.Argument(..., help=help1, metavar="filename"),
out_prefix: Optional[str] = typer.Argument(
None, help=help2, metavar="out_prefix"
),
):
"""
Process VoxCharta voting records that are provided in HTML
If ``out_prefix`` is not provided, prefix will be based on input file
"""
p = Path(filename)
log_outfile = p.parent / f"vox_run.{today.strftime('%Y-%m-%d')}.log"
log = LogClass(log_outfile).get_logger()
log.info("[italic yellow]Starting vox_run ...")
log.info(f"Version: {__version__}")
log.info(f"Logs are stored in : {log_outfile}")
if not out_prefix:
out_prefix = p.with_suffix("")
vox_extract = extract.Extract(filename, out_prefix, log=log)
# BeautifulSoup it
soup = vox_extract.soup_it()
# Get records
records_dict = vox_extract.get_records(soup)
# Write files
vox_extract.export_data(records_dict)
log.info("[bold dark_green]:heavy_check_mark: Finished vox_run!")
if __name__ == "__main__":
typer.run(main)