generated from gma/python-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
escape-wordpress
executable file
·51 lines (39 loc) · 1.12 KB
/
escape-wordpress
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
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import argparse
import logging
import pathlib
import sys
import wpsite
def main(xml_file: pathlib.Path, content_dir: pathlib.Path) -> None:
wpsite.convert_to_markdown(xml_file, content_dir)
def existing_path(arg: str) -> pathlib.Path:
path = pathlib.Path(arg)
if not path.exists():
raise argparse.ArgumentTypeError(f'{path} not found')
return path
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Converts WordPress site for use with Astro'
)
parser.add_argument(
'xml_file',
metavar='xml-file',
type=existing_path,
help='path to XML file exported from WordPress',
)
parser.add_argument(
'content_path',
metavar='content-path',
type=pathlib.Path,
help='path to directory containing converted Markdown',
)
args = parser.parse_args()
logging.basicConfig(
format='%(levelname)s: %(message)s',
level=logging.INFO,
stream=sys.stdout,
)
try:
main(args.xml_file, args.content_path)
except KeyboardInterrupt:
pass