2 # Extract Latin famous phrases from wikipedia
8 from bs4 import BeautifulSoup
11 parser = argparse.ArgumentParser(
12 description="Generate SQLite db of Latin famous phrases from Wikipedia.")
13 parser.add_argument("-o", "--output",
15 help="set custom output file location")
16 parser.add_argument("-v", "--version",
18 help="print script version")
19 return parser.parse_args()
22 print("downloading webpage")
23 return BeautifulSoup(requests.get(url).content, "html.parser")
26 print("prepping database")
27 c.execute("DROP TABLE IF EXISTS phrases")
28 c.execute("""CREATE TABLE phrases(
35 def fill_database(list_table):
37 print("iterating through tables")
38 for table in list_table:
39 for row in table.tbody.find_all("tr", recursive=False):
40 cell = row.find_all("td", recursive=False)
44 latin = (cell[0].get_text(" ", strip=True)).rstrip()
45 english = (cell[1].get_text(" ", strip=True)).rstrip()
46 notes = (cell[2].get_text(" ", strip=True)).rstrip()
48 c.execute("""INSERT INTO phrases
49 (id, latin, english, notes, length)
50 VALUES(?, ?, ?, ?, ?)""",
51 (i, latin, english, notes, len(latin)))
56 url = ("""https://en.wikipedia.org/w/index.php?title=List_of_Latin_phrases_(
57 full)&oldid=986793908""")
58 return get_html(url).find_all("table", attrs={"class":"wikitable"})
65 fill_database(get_tables())
67 if __name__ == "__main__":
68 version = "phrases extract.py 1.0.1"
70 conn = sqlite3.connect(args.output)