|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import argparse |
| 4 | +import inspect |
| 5 | +import json |
| 6 | +import os |
| 7 | + |
| 8 | +from .analyzer import analyze |
| 9 | + |
| 10 | + |
| 11 | +def main(): |
| 12 | + module_path = os.path.dirname(inspect.getfile(analyze)) |
| 13 | + |
| 14 | + arg_parser = argparse.ArgumentParser() |
| 15 | + |
| 16 | + arg_parser.add_argument("site", help="URL of the site you are wanting to analyze.") |
| 17 | + arg_parser.add_argument( |
| 18 | + "-s", "--sitemap", help="URL of the sitemap to seed the crawler with." |
| 19 | + ) |
| 20 | + arg_parser.add_argument( |
| 21 | + "-f", |
| 22 | + "--output-format", |
| 23 | + help="Output format.", |
| 24 | + choices=[ |
| 25 | + "json", |
| 26 | + "html", |
| 27 | + ], |
| 28 | + default="json", |
| 29 | + ) |
| 30 | + |
| 31 | + arg_parser.add_argument( |
| 32 | + "--analyze-headings", |
| 33 | + default=False, |
| 34 | + action="store_true", |
| 35 | + help="Analyze heading tags (h1-h6).", |
| 36 | + ) |
| 37 | + arg_parser.add_argument( |
| 38 | + "--analyze-extra-tags", |
| 39 | + default=False, |
| 40 | + action="store_true", |
| 41 | + help="Analyze other extra additional tags.", |
| 42 | + ) |
| 43 | + arg_parser.add_argument( |
| 44 | + "--no-follow-links", |
| 45 | + default=True, |
| 46 | + action="store_false", |
| 47 | + help="Analyze all the existing inner links as well (might be time consuming).", |
| 48 | + ) |
| 49 | + |
| 50 | + args = arg_parser.parse_args() |
| 51 | + |
| 52 | + output = analyze( |
| 53 | + args.site, |
| 54 | + args.sitemap, |
| 55 | + analyze_headings=args.analyze_headings, |
| 56 | + analyze_extra_tags=args.analyze_extra_tags, |
| 57 | + follow_links=args.no_follow_links, |
| 58 | + ) |
| 59 | + |
| 60 | + if args.output_format == "html": |
| 61 | + from jinja2 import Environment |
| 62 | + from jinja2 import FileSystemLoader |
| 63 | + |
| 64 | + env = Environment( |
| 65 | + loader=FileSystemLoader(os.path.join(module_path, "templates")) |
| 66 | + ) |
| 67 | + template = env.get_template("index.html") |
| 68 | + output_from_parsed_template = template.render(result=output) |
| 69 | + print(output_from_parsed_template) |
| 70 | + elif args.output_format == "json": |
| 71 | + print(json.dumps(output, indent=4, separators=(",", ": "))) |
| 72 | + |
| 73 | + |
| 74 | +if __name__ == "__main__": |
| 75 | + main() |
0 commit comments