2 # Extract Latin famous phrases from wikipedia
9 from bs4 import BeautifulSoup
11 def main(args=sys.argv[1:]):
13 parser = argparse.ArgumentParser(
14 description="Generate SQLite db of Latin famous phrases from Wikipedia.")
15 parser.add_argument("-o", "--output",
17 help="set custom output file location")
18 args = parser.parse_args()
20 url = ("""https://en.wikipedia.org/w/index.php?title=List_of_Latin_phrases_(
21 full)&oldid=986793908""")
22 print("downloading webpage")
23 soup = BeautifulSoup(requests.get(url).content, "html.parser")
25 print("prepping database")
26 conn = sqlite3.connect(args.output)
28 c.execute("DROP TABLE IF EXISTS phrases")
29 c.execute("""CREATE TABLE phrases(
36 i = 0 # For the phrase id
38 # iterate through the tables in the page
39 list_table = soup.find_all("table", attrs={"class":"wikitable"})
40 print("iterating through tables")
41 for table in list_table:
42 for row in table.tbody.find_all("tr", recursive=False):
43 cell = row.find_all("td", recursive=False)
46 latin = (cell[0].get_text(" ", strip=True)).rstrip()
47 english = (cell[1].get_text(" ", strip=True)).rstrip()
48 notes = (cell[2].get_text(" ", strip=True)).rstrip()
50 c.execute("""INSERT INTO phrases (id, latin, english, notes, length)
51 VALUES(?, ?, ?, ?, ?)""", (i, latin, english, notes, len(latin)))
56 print("closing database")
60 if __name__ == "__main__":