Created
September 19, 2021 02:57
-
-
Save dhruvilp/e1d666767b743771689f626d538eae1e to your computer and use it in GitHub Desktop.
HTML Parser for DB2 Responses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from html.parser import HTMLParser | |
from html.entities import name2codepoint | |
keys = [] | |
values = [] | |
dataTypes = ["CHAR","VARCHAR","BOOL","BOOLEAN","SMALLINT","INT","INTEGER","DOUBLE","DECIMAL","DATE","DATETIME","TIMESTAMP"] | |
class MyHTMLParser(HTMLParser): | |
def handle_starttag(self, tag, attrs): | |
for attr in attrs: | |
if "Tip(" in "".join(attr): | |
fm1 = "".join(attr).replace("Tip(","") | |
fm2 = fm1.replace(")", "") | |
MyHTMLParser().feed(fm2) | |
def handle_data(self, data): | |
if data[0] == " " and ":" not in data: | |
if data.replace(" ", "") not in dataTypes: | |
keys.append(data.replace(" ", "")) | |
elif data.replace(" ", "") in dataTypes: | |
if data.replace(" ", "") == "DECIMAL": | |
values.append("BigDecimal") | |
elif data.replace(" ", "") == "VARCHAR": | |
values.append("String") | |
elif data.replace(" ", "") == "INTEGER": | |
values.append("int") | |
else: | |
values.append(data.replace(" ", "").capitalize()) | |
parser = MyHTMLParser() | |
parser.feed("""<body><table><tr><td onmouseover="Tip('<b>Label: </b> FPS_PRICE_IND<br/><b>Type: </b> INTEGER<br/><b>Size: </b>1<br/><b>IsNullable: </b>non nullable<br/><b>Precision: </b>1<br/><b>Table: </b>SCHEMA.TABLE_NAME', TITLE, 'FPS_PRICE_IND')" onmouseout="UnTip()">FPS_PRICE_IND</td></tr><tr><td onmouseover="Tip('<b>Label: </b> GOVT_ID<br/><b>Type: </b> DECIMAL<br/><b>Size: </b>1<br/><b>IsNullable: </b>non nullable<br/><b>Precision: </b>1<br/><b>Table: </b>SCHEMA.TABLE_NAME', TITLE, 'FPS_PRICE_IND')" onmouseout="UnTip()">FPS_PRICE_IND</td></tr></table></body>""") | |
print("\nkeys: ", keys) | |
print("values: ", values) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment