Skip to content

Instantly share code, notes, and snippets.

@ilovefreesw
Created August 8, 2022 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilovefreesw/48b13bf7c2376d7259a9c2a237987a5a to your computer and use it in GitHub Desktop.
Save ilovefreesw/48b13bf7c2376d7259a9c2a237987a5a to your computer and use it in GitHub Desktop.
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