Skip to content

Commit

Permalink
[blogger] Post type not always be the first tag
Browse files Browse the repository at this point in the history
  • Loading branch information
punchagan committed Jul 22, 2016
1 parent b1fcefb commit 769a1f3
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions v7/import_blogger/import_blogger.py
Expand Up @@ -201,27 +201,28 @@ def import_item(self, item, out_folder=None):
LOGGER.warn('Not going to import "{0}" because it seems to contain'
' no content.'.format(title))

POST_TYPE_SCHEMAS = {
'http://schemas.google.com/blogger/2008/kind#post': 'posts',
'http://schemas.google.com/blogger/2008/kind#page': 'stories',
'http://schemas.google.com/blogger/2008/kind#settings': '',
'http://schemas.google.com/blogger/2008/kind#template': '',
'http://schemas.google.com/blogger/2008/kind#comment': '',
}

def process_item(self, item):
post_type = item.tags[0].term

if post_type == 'http://schemas.google.com/blogger/2008/kind#post':
self.import_item(item, 'posts')
elif post_type == 'http://schemas.google.com/blogger/2008/kind#page':
self.import_item(item, 'stories')
elif post_type == ('http://schemas.google.com/blogger/2008/kind'
'#settings'):
# Ignore settings
pass
elif post_type == ('http://schemas.google.com/blogger/2008/kind'
'#template'):
# Ignore template
pass
elif post_type == ('http://schemas.google.com/blogger/2008/kind'
'#comment'):
# FIXME: not importing comments. Does blogger support "pages"?
pass
terms = set([tag.term for tag in item.tags])
post_types = terms & set(self.POST_TYPE_SCHEMAS.keys())

if not post_types:
LOGGER.warn("Unknown post_type for {0}".format(item.title))

elif len(post_types) == 1:
out_folder = self.POST_TYPE_SCHEMAS[post_types.pop()]
if out_folder:
self.import_item(item, out_folder)

else:
LOGGER.warn("Unknown post_type:", post_type)
LOGGER.warn("Too many post_types for {0}".format(item.title))

def import_posts(self, channel):
for item in channel.entries:
Expand Down

0 comments on commit 769a1f3

Please sign in to comment.