|
| 1 | +import argparse |
| 2 | +import inspect |
| 3 | +import json |
| 4 | +import os |
| 5 | + |
| 6 | +from jinja2 import Environment |
| 7 | +from jinja2 import FileSystemLoader |
| 8 | +from seoanalyzer import analyze |
| 9 | + |
| 10 | + |
| 11 | +module_path = os.path.dirname(inspect.getfile(analyze)) |
| 12 | + |
| 13 | +arg_parser = argparse.ArgumentParser() |
| 14 | + |
| 15 | +arg_parser.add_argument('site', help='URL of the site you are wanting to analyze.') |
| 16 | +arg_parser.add_argument('-s', '--sitemap', help='URL of the sitemap to seed the crawler with.') |
| 17 | +arg_parser.add_argument('-f', '--output-format', help='Output format.', choices=['json', 'html', ], |
| 18 | + default='json') |
| 19 | +arg_parser.add_argument('-d', '--disk', help='save to disk', choices=['y', 'n', ], default='y') |
| 20 | + |
| 21 | +args = arg_parser.parse_args() |
| 22 | + |
| 23 | +output = analyze(args.site, args.sitemap) |
| 24 | + |
| 25 | +if args.output_format == 'html': |
| 26 | + from jinja2 import Environment |
| 27 | + from jinja2 import FileSystemLoader |
| 28 | + |
| 29 | + env = Environment(loader=FileSystemLoader(os.path.join(module_path, 'templates'))) |
| 30 | + template = env.get_template('index.html') |
| 31 | + output_from_parsed_template = template.render(result=output) |
| 32 | + if args.disk == 'y': |
| 33 | + with open("test.html", "w", encoding='utf-8') as text_file: |
| 34 | + text_file.write(output_from_parsed_template) |
| 35 | + else: |
| 36 | + print(output_from_parsed_template) |
| 37 | +elif args.output_format == 'json': |
| 38 | + if args.disk == 'y': |
| 39 | + with open("test.json", "w", encoding='utf-8') as text_file: |
| 40 | + text_file.write(json.dumps(output, indent=4, separators=(',', ': '))) |
| 41 | + else: |
| 42 | + print(json.dumps(output, indent=4, separators=(',', ': '))) |
0 commit comments