Create Python Functions.md

import re
import urllib.request as ur
import time
t0 = time.clock()
url = r'http://www.mathworks.com/help/matlab/functionlist.html'
html = ur.urlopen(url).readlines()
with open('new.txt', 'w') as f, open('outline.txt', 'w') as outline:
    ph = re.compile(r'^(.*?)</h([1-8])>$')
    pf = re.compile(r'^<td class="description">(.*?)</td></tr><tr><td class="term"><a href="(.*?)">(.*?)</a></td>$')    
    for lineb in html:
        line = lineb.decode('utf-8')
        lin = re.findall(pf, line) or re.findall(ph, line) ###hahha
        if lin:
            x = lin[0]  # [('Language Fundamentals', '2')]
            if len(x) == 3:
                linx = '* [' + x[2] + ']() - ' + x[0] + '\n'
            elif len(x) == 2:
                linx = '\n'+'#'*int(x[1]) + x[0] + '\n'                
                y = '\t'*(int(x[1])-2) + '- [' + x[0] + '](#' + '-'.join(x[0].lower().split()) + ')\n' # lower() & Getting Started with Python](#Getting-Started-with-Python)
                outline.write(y)
            else:
                linx = '---'
            f.write(linx)
        else:
            continue
        
with open('new.txt') as f, open('outline.txt') as outline, open('markdown.txt', 'w') as md:
    md.write(outline.read())
    md.write('\n\n')
    md.write(f.read())
  

##with open('mat.txt') as mat, open('md.txt','w') as md:
##    for line in mat.readlines():
##        if '\t' in line:
##            line = '* ['+line.split('\t')[0] + ']() - ' + line.split('\t')[1]
##        elif line != '\n':
##            line = '\n## ' + line            
##        md.write(line)
t1 = time.clock()
print('Finished in', t1-t0, 's')
print('Check out the markdown.txt file, Rememeber to uncheck autowrap if you copy it from notepad')