-
Notifications
You must be signed in to change notification settings - Fork 7
/
smapper
executable file
·43 lines (34 loc) · 1.25 KB
/
smapper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
import logging
import sys
from sitemapparser import SiteMapParser
from sitemapparser.smapper_utils import (uri_modifier, get_args, get_exporters,
get_logging_config)
from logging.config import fileConfig
def main():
try:
log_config, log_file = get_logging_config()
fileConfig(log_config, defaults={'logfilename': log_file})
except KeyError:
print("An error occurred reading logging_config.ini")
uri, logging_level, exporter = get_args(sys.argv[1:])
logging.getLogger().setLevel(logging_level)
logger = logging.getLogger(__name__)
uri = uri_modifier(uri)
logger.info("Uri: {}. Exporter: {}".format(uri, exporter))
try:
sm = SiteMapParser(uri)
except SyntaxError as e:
logger.critical("Parsing error: {}".format(e))
print("An error occurred. Please check sitemap_parser_run.log")
sys.exit(1)
exporters = get_exporters()
selected_exporter = exporters[exporter]
logger.debug("selected_exporter: {}".format(selected_exporter))
e = selected_exporter(sm)
if sm.has_sitemaps():
print(e.export_sitemaps())
elif sm.has_urls():
print(e.export_urls())
if __name__ == '__main__':
main()