X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=extract.py;h=c83755fd1caf2f655299112cb37bb86e05caf9dd;hb=5d6d1f218d5ef88042daaeb6c4ef397b7a233be3;hp=833594da483748f0608acaa5c143e88249d007e9;hpb=58ad575e75427a13fdca64a17ced4ae2f3f986ad;p=phrases.git diff --git a/extract.py b/extract.py index 833594d..c83755f 100755 --- a/extract.py +++ b/extract.py @@ -13,13 +13,16 @@ def parse_args(): parser.add_argument("-o", "--output", default="phrases.db", help="set custom output file location") + parser.add_argument("-v", "--version", + action="store_true", + help="print script version") return parser.parse_args() def get_html(url): print("downloading webpage") return BeautifulSoup(requests.get(url).content, "html.parser") -def prep_database(c): +def prep_database(): print("prepping database") c.execute("DROP TABLE IF EXISTS phrases") c.execute("""CREATE TABLE phrases( @@ -29,7 +32,7 @@ def prep_database(c): notes TEXT, length INTEGER)""") -def fill_database(list_table, c, conn): +def fill_database(list_table): i = 0 # phrase id print("iterating through tables") for table in list_table: @@ -54,11 +57,16 @@ def get_tables(): full)&oldid=986793908""") return get_html(url).find_all("table", attrs={"class":"wikitable"}) -def main(args): - conn = sqlite3.connect(args.output) - c = conn.cursor() - prep_database(c) - fill_database(get_tables(), c, conn) +def main(): + if args.version: + print(version) + else: + prep_database() + fill_database(get_tables()) if __name__ == "__main__": - main(parse_args()) + version = "phrases extract.py 1.0.1" + args = parse_args() + conn = sqlite3.connect(args.output) + c = conn.cursor() + main()