import os def make_file(directory, name, out): out.write('\n'.format(name)) for f in os.listdir(directory): with open(os.path.join(directory, f), 'r') as fp: name = os.path.splitext(f)[0] data = fp.read() start = data.find(''.format(name) + data[start:-6] + '\n') out.write('') # Run this in Font-Awesome/advanced-options/raw-svg/ # with open("hass-fontawesome-brands.html", 'w') as out: # make_file('brands', 'fab', out) # with open("hass-fontawesome-regular.html", 'w') as out: # make_file('regular', 'far', out) # with open("hass-fontawesome-solid.html", 'w') as out: # make_file('solid', 'fas', out)