mirror of
https://github.com/getpelican/pelican.git
synced 2026-06-07 07:16:56 +02:00
Merge 9c0e077801 into 2fc442fe2d
This commit is contained in:
commit
71edc21ae8
1 changed files with 50 additions and 4 deletions
|
|
@ -447,6 +447,46 @@ def feed2fields(file):
|
||||||
yield (entry.title, entry.description, slug, date, author, [], tags,
|
yield (entry.title, entry.description, slug, date, author, [], tags,
|
||||||
kind, "html")
|
kind, "html")
|
||||||
|
|
||||||
|
|
||||||
|
def blogger2fields(file):
|
||||||
|
"""Read a feed and yield pelican fields"""
|
||||||
|
KIND_SCHEME = "http://schemas.google.com/g/2005#kind"
|
||||||
|
KINDS = {
|
||||||
|
'http://schemas.google.com/blogger/2008/kind#post': 'article',
|
||||||
|
'http://schemas.google.com/blogger/2008/kind#page': 'page',
|
||||||
|
'http://schemas.google.com/blogger/2008/kind#settings': 'settings',
|
||||||
|
'http://schemas.google.com/blogger/2008/kind#template': 'template',
|
||||||
|
'http://schemas.google.com/blogger/2008/kind#comment': 'comment',
|
||||||
|
}
|
||||||
|
|
||||||
|
import feedparser
|
||||||
|
d = feedparser.parse(file)
|
||||||
|
for entry in d.entries:
|
||||||
|
date = (time.strftime("%Y-%m-%d %H:%M", entry.updated_parsed)
|
||||||
|
if hasattr(entry, "updated_parsed") else None)
|
||||||
|
author = entry.author if hasattr(entry, "author") else None
|
||||||
|
|
||||||
|
if hasattr(entry, "tags"):
|
||||||
|
tags = []
|
||||||
|
for e in entry.tags:
|
||||||
|
# Assume there's only one tag with the 'kind' schema.
|
||||||
|
if e['scheme'] == KIND_SCHEME:
|
||||||
|
kind = KINDS.get(e['term'])
|
||||||
|
else:
|
||||||
|
tags.append(e['term'])
|
||||||
|
else:
|
||||||
|
tags = None
|
||||||
|
kind = 'article'
|
||||||
|
|
||||||
|
if kind == 'article':
|
||||||
|
slug = os.path.splitext(os.path.split(entry.link)[1])[0]
|
||||||
|
else:
|
||||||
|
slug = slugify(entry.title)
|
||||||
|
|
||||||
|
yield (entry.title, entry.description, slug, date, author, [], tags,
|
||||||
|
kind, "html")
|
||||||
|
|
||||||
|
|
||||||
def build_header(title, date, author, categories, tags, slug, attachments=None):
|
def build_header(title, date, author, categories, tags, slug, attachments=None):
|
||||||
from docutils.utils import column_width
|
from docutils.utils import column_width
|
||||||
|
|
||||||
|
|
@ -686,9 +726,9 @@ def fields2pelican(fields, out_markup, output_path,
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Transform feed, WordPress, Tumblr, Dotclear, or Posterous "
|
description="Transform feed, WordPress, Tumblr, Dotclear, Posterous, "
|
||||||
"files into reST (rst) or Markdown (md) files. Be sure to "
|
"or Blogger files into reST (rst) or Markdown (md) files. "
|
||||||
"have pandoc installed.",
|
"Be sure to have pandoc installed.",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
|
|
||||||
parser.add_argument(dest='input', help='The input file to read')
|
parser.add_argument(dest='input', help='The input file to read')
|
||||||
|
|
@ -702,6 +742,8 @@ def main():
|
||||||
help='Tumblr export')
|
help='Tumblr export')
|
||||||
parser.add_argument('--feed', action='store_true', dest='feed',
|
parser.add_argument('--feed', action='store_true', dest='feed',
|
||||||
help='Feed to parse')
|
help='Feed to parse')
|
||||||
|
parser.add_argument('--blogger', action='store_true', dest='blogger',
|
||||||
|
help='Blogger export')
|
||||||
parser.add_argument('-o', '--output', dest='output', default='output',
|
parser.add_argument('-o', '--output', dest='output', default='output',
|
||||||
help='Output path')
|
help='Output path')
|
||||||
parser.add_argument('-m', '--markup', dest='markup', default='rst',
|
parser.add_argument('-m', '--markup', dest='markup', default='rst',
|
||||||
|
|
@ -754,8 +796,10 @@ def main():
|
||||||
input_type = 'tumblr'
|
input_type = 'tumblr'
|
||||||
elif args.feed:
|
elif args.feed:
|
||||||
input_type = 'feed'
|
input_type = 'feed'
|
||||||
|
elif args.blogger:
|
||||||
|
input_type = 'blogger'
|
||||||
else:
|
else:
|
||||||
error = "You must provide either --wpfile, --dotclear, --posterous, --tumblr or --feed options"
|
error = "You must provide either --wpfile, --dotclear, --posterous, --tumblr, --feed or --blogger options"
|
||||||
exit(error)
|
exit(error)
|
||||||
|
|
||||||
if not os.path.exists(args.output):
|
if not os.path.exists(args.output):
|
||||||
|
|
@ -779,6 +823,8 @@ def main():
|
||||||
fields = tumblr2fields(args.input, args.blogname)
|
fields = tumblr2fields(args.input, args.blogname)
|
||||||
elif input_type == 'feed':
|
elif input_type == 'feed':
|
||||||
fields = feed2fields(args.input)
|
fields = feed2fields(args.input)
|
||||||
|
elif input_type == 'blogger':
|
||||||
|
fields = blogger2fields(args.input)
|
||||||
|
|
||||||
if args.wp_attach:
|
if args.wp_attach:
|
||||||
attachments = get_attachments(args.input)
|
attachments = get_attachments(args.input)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue