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(
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:
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()