]> git.armaanb.net Git - phrases.git/commitdiff
Add --version argument to extract.py
authorArmaan Bhojwani <me@armaanb.net>
Tue, 5 Jan 2021 19:20:53 +0000 (14:20 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Tue, 5 Jan 2021 19:20:53 +0000 (14:20 -0500)
extract.py

index 833594da483748f0608acaa5c143e88249d007e9..c83755fd1caf2f655299112cb37bb86e05caf9dd 100755 (executable)
@@ -13,13 +13,16 @@ def parse_args():
     parser.add_argument("-o", "--output",
                        default="phrases.db",
                        help="set custom output file location")
     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")
 
     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(
     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)""")
 
               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:
     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"})
 
           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__":
 
 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()