]> git.armaanb.net Git - phrases.git/commitdiff
Fix style according to Flake8
authorArmaan Bhojwani <me@armaanb.net>
Sun, 24 Jan 2021 18:29:46 +0000 (13:29 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Sun, 24 Jan 2021 18:29:46 +0000 (13:29 -0500)
extract.py
phrases.py

index c83755fd1caf2f655299112cb37bb86e05caf9dd..f33807645faf2cf50fd2c7ce4c2b3db222cb958c 100755 (executable)
@@ -7,21 +7,24 @@ import sqlite3
 import requests
 from bs4 import BeautifulSoup
 
+
 def parse_args():
     parser = argparse.ArgumentParser(
-        description="Generate SQLite db of Latin famous phrases from Wikipedia.")
+        description="Generate database of Latin famous phrases from Wikipedia")
     parser.add_argument("-o", "--output",
-                       default="phrases.db",
-                       help="set custom output file location")
+                        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():
     print("prepping database")
     c.execute("DROP TABLE IF EXISTS phrases")
@@ -32,8 +35,9 @@ def prep_database():
               notes TEXT,
               length INTEGER)""")
 
+
 def fill_database(list_table):
-    i = 0 # phrase id
+    i = 0  # phrase id
     print("iterating through tables")
     for table in list_table:
         for row in table.tbody.find_all("tr", recursive=False):
@@ -44,18 +48,20 @@ def fill_database(list_table):
                 latin = (cell[0].get_text(" ", strip=True)).rstrip()
                 english = (cell[1].get_text(" ", strip=True)).rstrip()
                 notes = (cell[2].get_text(" ", strip=True)).rstrip()
-    
+
                 c.execute("""INSERT INTO phrases
                          (id, latin, english, notes, length)
                          VALUES(?, ?, ?, ?, ?)""",
-                         (i, latin, english, notes, len(latin)))
+                          (i, latin, english, notes, len(latin)))
                 conn.commit()
             i = i + 1
 
+
 def get_tables():
     url = ("""https://en.wikipedia.org/w/index.php?title=List_of_Latin_phrases_(
           full)&oldid=986793908""")
-    return get_html(url).find_all("table", attrs={"class":"wikitable"})
+    return get_html(url).find_all("table", attrs={"class": "wikitable"})
+
 
 def main():
     if args.version:
@@ -64,8 +70,9 @@ def main():
         prep_database()
         fill_database(get_tables())
 
+
 if __name__ == "__main__":
-    version = "phrases extract.py 1.0.1"
+    version = "phrases extract.py 1.0.2"
     args = parse_args()
     conn = sqlite3.connect(args.output)
     c = conn.cursor()
index 3b41b80719e32f460ac84a0b4469d1882643db4c..e9875e16228eafc457ef1834ab578d2437498d7c 100755 (executable)
@@ -8,6 +8,7 @@ import sqlite3
 from sys import exit
 from os import path
 
+
 def parse_args():
     parser = argparse.ArgumentParser(
         description="Latin famous phrases in the terminal.")
@@ -41,6 +42,7 @@ def parse_args():
                         help="set the location of the phrase database.")
     return parser.parse_args()
 
+
 def output():
     data = c.fetchall()
     row = list(data[randint(0, len(data) - 1)])
@@ -68,6 +70,7 @@ def output():
             print(len(data))
         exit(0)
 
+
 def find_file():
     if args.file:
         return args.file
@@ -78,16 +81,19 @@ def find_file():
     else:
         exit("cannot find the phrase database!")
 
+
 def get_rand():
     c.execute("SELECT * FROM phrases WHERE length <= (?) AND length >= (?)",
               (args.max, args.min))
 
+
 def main():
     get_rand()
     output()
 
+
 if __name__ == "__main__":
-    version = "phrases 1.0.1"
+    version = "phrases 1.0.2"
     args = parse_args()
     c = sqlite3.connect(find_file()).cursor()
     main()