python-feedgen/feedgen/__main__.py

81 lines
2.8 KiB
Python
Raw Normal View History

2013-04-26 14:59:44 +02:00
# -*- coding: utf-8 -*-
'''
2013-05-04 22:54:43 +02:00
feedgen
~~~~~~~
2013-04-26 14:59:44 +02:00
:copyright: 2013, Lars Kiesow <lkiesow@uos.de>
2013-05-03 17:13:08 +02:00
:license: FreeBSD and LGPL, see license.* for more details.
2013-04-26 14:59:44 +02:00
'''
2013-05-04 22:54:43 +02:00
from feedgen.feed import FeedGenerator
from feedgen.podcast import PodcastGenerator
2013-04-26 14:59:44 +02:00
import sys
if __name__ == '__main__':
if len(sys.argv) != 2 or not (
sys.argv[1].endswith('rss') \
or sys.argv[1].endswith('atom') \
or sys.argv[1].endswith('podcast') ):
2013-05-03 17:05:39 +02:00
print 'Usage: %s ( <file>.atom | atom | <file>.rss | rss | podcast )' % \
2013-05-04 22:54:43 +02:00
'pythom -m feedgen'
2013-04-26 14:59:44 +02:00
print ''
print ' atom -- Generate ATOM test output and print it to stdout.'
print ' rss -- Generate RSS test output and print it to stdout.'
print ' <file>.atom -- Generate ATOM test feed and write it to file.atom.'
print ' <file>.rss -- Generate RSS test teed and write it to file.rss.'
2013-05-03 17:05:39 +02:00
print ' podcast -- Generator Podcast test output and print it to stdout.'
2013-04-26 14:59:44 +02:00
print ''
exit()
arg = sys.argv[1]
fg = PodcastGenerator() if arg.endswith('podcast') else FeedGenerator()
2013-04-26 14:59:44 +02:00
fg.id('http://lernfunk.de/_MEDIAID_123')
fg.title('Testfeed')
fg.author( {'name':'Lars Kiesow','email':'lkiesow@uos.de'} )
fg.link( href='http://example.com', rel='alternate' )
fg.category(term='test')
fg.contributor( name='Lars Kiesow', email='lkiesow@uos.de' )
fg.contributor( name='John Doe', email='jdoe@example.com' )
fg.icon('http://ex.com/icon.jpg')
fg.logo('http://ex.com/logo.jpg')
fg.rights('cc-by')
fg.subtitle('This is a cool feed!')
fg.link( href='http://larskiesow.de/test.atom', rel='self' )
fg.language('de')
fe = fg.add_entry()
fe.id('http://lernfunk.de/_MEDIAID_123#1')
fe.title('First Element')
fe.content('''Lorem ipsum dolor sit amet, consectetur adipiscing elit. Tamen
aberramus a proposito, et, ne longius, prorsus, inquam, Piso, si ista
mala sunt, placet. Aut etiam, ut vestitum, sic sententiam habeas aliam
domesticam, aliam forensem, ut in fronte ostentatio sit, intus veritas
occultetur? Cum id fugiunt, re eadem defendunt, quae Peripatetici,
verba.''')
fe.summary('Lorem ipsum dolor sit amet, consectetur adipiscing elit...')
fe.link( href='http://example.com', rel='alternate' )
fe.author( name='Lars Kiesow', email='lkiesow@uos.de' )
if arg == 'atom':
print fg.atom_str(pretty=True)
elif arg == 'rss':
print fg.rss_str(pretty=True)
elif arg == 'podcast':
fg.itunes_author('Lars Kiesow')
fg.itunes_category('Technology', 'Podcasting')
2013-04-30 17:54:38 +02:00
fg.itunes_explicit('no')
fg.itunes_complete('no')
fg.itunes_new_feed_url('http://example.com/new-feed.rss')
fg.itunes_owner('John Doe', 'john@example.com')
fg.itunes_summary('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Verba tu fingas et ea dicas, quae non sentias?')
2013-05-03 14:19:04 +02:00
fe.itunes_author('Lars Kiesow')
print fg.podcast_str(pretty=True)
2013-04-26 14:59:44 +02:00
elif arg.endswith('atom'):
fg.atom_file(arg)
elif arg.endswith('rss'):
fg.rss_file(arg)