-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
30 lines (24 loc) · 949 Bytes
/
controller.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
30
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import converter
import parser
def controller(args):
"""
Loop over the data folder to start parsing and conversion of each file
"""
folder_path = os.path.abspath(args.folder)
# Get all posts from articles folder
articles_folder_path = folder_path + '/articles/'
for filename in os.listdir(articles_folder_path):
# Check if its a XML file
if os.path.splitext(filename)[-1] == '.xml':
full_path = articles_folder_path + '/' + filename
with open(full_path, 'r') as post:
# First parse the PluXml content
parsed_post = parser.parser(post)
# Then give the parsed_post to one of the converters
if args.converter == 'grav':
converter.toGrav(parsed_post, folder_path)
else:
converter.toSimpleMarkdown(parsed_post, folder_path)