From cb650c1c992a92c25040387d77ecc774e6f5a4ac Mon Sep 17 00:00:00 2001 From: Benjamin Port Date: Thu, 9 May 2013 05:06:12 +0200 Subject: [PATCH] Add filter-author option to importer Allow to import post from only one author when importing data --- docs/importer.rst | 1 + pelican/tools/pelican_import.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/importer.rst b/docs/importer.rst index 9a0c513e..228471da 100644 --- a/docs/importer.rst +++ b/docs/importer.rst @@ -69,6 +69,7 @@ Optional arguments (default: False) --dir-page Put files recognised as pages in "pages/" sub- directory (wordpress import only) (default: False) + --filter-author Import only post from the specified author. --strip-raw Strip raw HTML code that can't be converted to markup such as flash embeds or iframes (wordpress import only) (default: False) diff --git a/pelican/tools/pelican_import.py b/pelican/tools/pelican_import.py index 630142e7..59b767f9 100755 --- a/pelican/tools/pelican_import.py +++ b/pelican/tools/pelican_import.py @@ -376,9 +376,11 @@ def build_markdown_header(title, date, author, categories, tags, slug): def fields2pelican(fields, out_markup, output_path, dircat=False, strip_raw=False, disable_slugs=False, - dirpage=False, filename_template=None): + dirpage=False, filename_template=None, filter_author=None): for (title, content, filename, date, author, categories, tags, kind, in_markup) in fields: + if filter_author and filter_author != author: + continue slug = not disable_slugs and filename or None if (in_markup == "markdown") or (out_markup == "markdown") : ext = '.md' @@ -487,6 +489,8 @@ def main(): parser.add_argument('--dir-page', action='store_true', dest='dirpage', help=('Put files recognised as pages in "pages/" sub-directory' ' (wordpress import only)')) + parser.add_argument('--filter-author', dest='author', + help='Import only post from the specified author') parser.add_argument('--strip-raw', action='store_true', dest='strip_raw', help="Strip raw HTML code that can't be converted to " "markup such as flash embeds or iframes (wordpress import only)") @@ -537,4 +541,5 @@ def main(): dircat=args.dircat or False, dirpage=args.dirpage or False, strip_raw=args.strip_raw or False, - disable_slugs=args.disable_slugs or False) + disable_slugs=args.disable_slugs or False, + filter_author=args.author)