-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (24 loc) · 1.13 KB
/
main.py
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
import argparse
import json
from os import listdir
from os.path import abspath, join
from classes import jekyll_parser as jp
from classes import wordpress_handler as wph
# Load configuration file
with open("config.json") as json_data_file:
config = json.load(json_data_file)
# Set up command line arguments
parser = argparse.ArgumentParser(description='Process a Jekyll Markdown file or directory of Jekyll Markdown posts and create them in a WordPress instance')
parser.add_argument('--file', help='The absolute path of a single post file')
parser.add_argument('--directory', help='The absolute path of the directory with all the posts')
parser.add_argument('--post_type', help='The post type to be created')
args = parser.parse_args()
# Global Wordpress Handler
handler = wph.WordpressHandler(jp.JekyllParser(), config)
if (args.file):
handler.post_to_wordpress_from_file(args.file, args.post_type)
elif (args.directory):
# Post file content to wordpress
files = [abspath(join(args.directory, f)) for f in listdir(args.directory)]
for i, file in enumerate(files):
handler.post_to_wordpress_from_file(file, args.post_type)