Created
June 29, 2016 13:58
-
-
Save graham-thomson/f91d109270c221fa4130eca1871497b5 to your computer and use it in GitHub Desktop.
Quick script to create DDL statements for DoubleClick Matchtables based on the html tables in their documentation
This file contains 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
import bs4 | |
import requests | |
soup = bs4.BeautifulSoup(requests.get("https://support.google.com/dcm/partner/answer/6005910?hl=en").content, "html.parser") | |
table_names = [] | |
for a in soup.find_all("a"): | |
try: | |
if a.get('class')[0] == 'zippy': | |
table_names.append(a.get('id')) | |
except TypeError: | |
continue | |
matchtables = pd.read_html("https://support.google.com/dcm/partner/answer/6005910?hl=en", header=0) | |
matchtables.pop(17) | |
def make_ddl(html_table, table_name): | |
pk = str(html_table.iloc[0,0]).lower().replace("-", "_") | |
clean = lambda x: str(x).lower().replace("-", "_") | |
print "CREATE TABLE metadata.{} (".format(table_name) | |
for i in range(len(html_table)): | |
print clean(html_table.iloc[i,0]) + "\t" + clean(html_table.iloc[i,1]) + " encode lzo," | |
print ")\nDISTKEY ({})\nSORTKEY ({});\n".format(pk, pk) | |
for table_index in range(len(matchtables)): | |
make_ddl(matchtables[table_index], table_names[table_index]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment