AMPTools-Gen is basically a Python script that you can use to instantly generate AMP code from any HTML.
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
#!/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