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 return parser.parse_args()
19 print("downloading webpage")
20 return BeautifulSoup(requests.get(url).content, "html.parser")
23 print("prepping database")
24 c.execute("DROP TABLE IF EXISTS phrases")
25 c.execute("""CREATE TABLE phrases(
32 def fill_database(list_table, c, conn):
34 print("iterating through tables")
35 for table in list_table:
36 for row in table.tbody.find_all("tr", recursive=False):
37 cell = row.find_all("td", recursive=False)
41 latin = (cell[0].get_text(" ", strip=True)).rstrip()
42 english = (cell[1].get_text(" ", strip=True)).rstrip()
43 notes = (cell[2].get_text(" ", strip=True)).rstrip()
45 c.execute("""INSERT INTO phrases
46 (id, latin, english, notes, length)
47 VALUES(?, ?, ?, ?, ?)""",
48 (i, latin, english, notes, len(latin)))
53 url = ("""https://en.wikipedia.org/w/index.php?title=List_of_Latin_phrases_(
54 full)&oldid=986793908""")
55 return get_html(url).find_all("table", attrs={"class":"wikitable"})
58 conn = sqlite3.connect(args.output)
61 fill_database(get_tables(), c, conn)
63 if __name__ == "__main__":