# implementation of yahoo pipes createrss operator,
# see http://pipes.yahoo.com/pipes/docs?doc=operators#CreateRSS

# Copyright (C) 2011  Nick Savchenko <nsavch@gmail.com>

# Kindly sponsored by Oberst BV, see http://oberst.com/

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

import sys
from pipe2py import util

RSS_FIELDS = [
    u'mediaContentHeight',
    u'description',
    u'pubdate',
    u'mediaThumbHeight',
    u'link',
    u'guid',
    u'mediaThumbURL',
    u'mediaContentType',
    u'author',
    u'title',
    u'mediaContentWidth',
    u'mediaContentURL',
    u'mediaThumbWidth']

def transform_to_rss(item, conf):
    new = dict()
    for i in RSS_FIELDS:
        try:
            field_conf = conf[i]
            if field_conf['value']:
                new[i] = util.get_subkey(field_conf['value'], item)
        except KeyError:
            continue
    return new

def pipe_createrss(context, _INPUT, conf, **kwargs):
    for item in _INPUT:
        yield transform_to_rss(item, conf)
        

@@ -510,16 +510,99 @@
 t util%0A%0A
+#note: for some reason the config needs to match pubdate but should output pubDate%0A
 RSS_FIEL
@@ -610,14 +610,36 @@
 S = 
-%5B
+%7B
 %0A    
+u'mediaContentHeight':
 u'me
@@ -661,16 +661,31 @@
 t',%0A    
+u'description':
 u'descri
@@ -706,22 +706,53 @@
 pubdate'
+:u'pubDate'
 ,%0A    
+u'mediaThumbHeight':
 u'mediaT
@@ -768,16 +768,24 @@
 t',%0A    
+u'link':
 u'link',
@@ -789,16 +789,24 @@
 k',%0A    
+u'guid':
 u'guid',
@@ -806,24 +806,41 @@
 'guid',%0A    
+u'mediaThumbURL':
 u'mediaThumb
@@ -872,43 +872,103 @@
 ype'
-,%0A    u'author',%0A    u'title',%0A    
+:u'mediaContentType',%0A    u'author':u'author',%0A    u'title':u'title',%0A    u'mediaContentWidth':
 u'me
@@ -985,24 +985,43 @@
 Width',%0A    
+u'mediaContentURL':
 u'mediaConte
@@ -1050,17 +1050,38 @@
 mbWidth'
-%5D
+:u'mediaThumbWidth',%0A%7D
 %0A%0Adef tr
@@ -1252,17 +1252,29 @@
     new%5B
-i
+RSS_FIELDS%5Bi%5D
 %5D = util

Match pubdate but output pubDate