2 # Extract Latin famous phrases from Wikipedia
8 from bs4 import BeautifulSoup
12 parser = argparse.ArgumentParser(
13 description="Generate database of Latin famous phrases from Wikipedia")
14 parser.add_argument("-o", "--output",
16 help="set custom output file location")
17 parser.add_argument("-v", "--version",
19 version="phrases-extract 1.0.3")
20 return parser.parse_args()
24 print("downloading webpage")
25 return BeautifulSoup(requests.get(url).content, "html.parser")
29 print("prepping database")
30 c.execute("DROP TABLE IF EXISTS phrases")
31 c.execute("""CREATE TABLE phrases(
39 def fill_database(list_table):
41 print("iterating through tables")
42 for table in list_table:
43 for row in table.tbody.find_all("tr", recursive=False):
44 cell = row.find_all("td", recursive=False)
48 latin = (cell[0].get_text(" ", strip=True)).rstrip()
49 english = (cell[1].get_text(" ", strip=True)).rstrip()
50 notes = (cell[2].get_text(" ", strip=True)).rstrip()
52 c.execute("""INSERT INTO phrases
53 (id, latin, english, notes, length)
54 VALUES(?, ?, ?, ?, ?)""",
55 (i, latin, english, notes, len(latin)))
61 url = ("""https://en.wikipedia.org/w/index.php?title=List_of_Latin_phrases_(
62 full)&oldid=986793908""")
63 return get_html(url).find_all("table", attrs={"class": "wikitable"})
68 fill_database(get_tables())
71 if __name__ == "__main__":
73 conn = sqlite3.connect(args.output)