]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/parse.py
Change Card() from extending list to independent
[lightcards.git] / lightcards / parse.py
index a447485e4b046f4ab16bc67b251c8b140a41cba5..ea3468d66bfdca5f898431ce3a8d6743712b405f 100644 (file)
@@ -25,11 +25,18 @@ def parse_html(html):
     soup = BeautifulSoup(html, "html.parser").find("table")
     outp = []
 
-    for x in soup.find_all("tr"):
-        outp.append(Card([clean_text(y) for y in x.find_all("td")[:2]]))
+    try:
+        for x in soup.find_all("tr"):
+            outp.append(Card(tuple([clean_text(y) for y in x.find_all("td")])))
+    except AttributeError:
+        sys.exit("lightcards: No table found")
+
+    ths = soup.find_all("th")
+    if not len(ths) in [1, 2]:
+        sys.exit("lightcards: Headings malformed")
 
     # Return a tuple of nested lists
-    return ([clean_text(x) for x in soup.find_all("th")][:2], outp[1:])
+    return ([clean_text(x) for x in ths], outp[1:])
 
 
 def main(file):