Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AMPTools-Gen is basically a Python script that you can use to instantly generate AMP code from any HTML.
#!/usr/bin/python3
import argparse
from amp_tools import TransformHtmlToAmp
import codecs
arg_parser = argparse.ArgumentParser( description = "Copy source_file as target_file." )
arg_parser.add_argument( "source_file" )
arg_parser.add_argument( "target_file" )
arguments = arg_parser.parse_args()
source = arguments.source_file
target = arguments.target_file
html = ""
with codecs.open(source, encoding='utf-8', mode='r+') as f:
for line in f:
html = html + line.rstrip()
valid_amp = TransformHtmlToAmp(html)().decode("utf-8")
with codecs.open(target, encoding='utf-8', mode='w+') as f:
f.write(valid_amp.rstrip())
f.seek(0)
#print(str(valid_amp))
print( target, "successfully created !!" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment