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
|
2013-04-26 14:59:44 +02:00
|
|
|
import sys
|
|
|
|
|
2014-05-11 19:53:29 +02:00
|
|
|
def print_enc(s):
|
|
|
|
'''Print function compatible with both python2 and python3 accepting strings
|
|
|
|
and byte arrays.
|
|
|
|
'''
|
2016-01-01 19:31:00 +01:00
|
|
|
if sys.version_info[0] >= 3:
|
|
|
|
print(s.decode('utf-8') if type(s) == type(b'') else s)
|
|
|
|
else:
|
|
|
|
print(s)
|
2014-05-07 21:22:55 +02:00
|
|
|
|
2013-04-26 14:59:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2014-05-11 20:24:48 +02:00
|
|
|
if len(sys.argv) != 2 or not (
|
2013-04-29 19:34:51 +02:00
|
|
|
sys.argv[1].endswith('rss') \
|
|
|
|
or sys.argv[1].endswith('atom') \
|
2016-05-24 23:56:32 +02:00
|
|
|
or sys.argv[1].endswith('torrent') \
|
2013-04-29 19:34:51 +02:00
|
|
|
or sys.argv[1].endswith('podcast') ):
|
2016-05-24 23:56:32 +02:00
|
|
|
print_enc ('Usage: %s ( <file>.atom | atom | <file>.rss | rss | podcast | torrent )' % \
|
2014-05-11 20:24:48 +02:00
|
|
|
'python -m feedgen')
|
2014-05-07 21:22:55 +02:00
|
|
|
print_enc ('')
|
2015-10-28 22:03:22 +01:00
|
|
|
print_enc (' atom -- Generate ATOM test output and print it to stdout.')
|
|
|
|
print_enc (' rss -- Generate RSS test output and print it to stdout.')
|
|
|
|
print_enc (' <file>.atom -- Generate ATOM test feed and write it to file.atom.')
|
|
|
|
print_enc (' <file>.rss -- Generate RSS test teed and write it to file.rss.')
|
|
|
|
print_enc (' podcast -- Generate Podcast test output and print it to stdout.')
|
|
|
|
print_enc (' dc.atom -- Generate DC extension test output (atom format) and print it to stdout.')
|
|
|
|
print_enc (' dc.rss -- Generate DC extension test output (rss format) and print it to stdout.')
|
|
|
|
print_enc (' syndication.atom -- Generate DC extension test output (atom format) and print it to stdout.')
|
|
|
|
print_enc (' syndication.rss -- Generate DC extension test output (rss format) and print it to stdout.')
|
2016-05-24 23:56:32 +02:00
|
|
|
print_enc (' torrent -- Generate Torrent test output and print it to stdout.')
|
2014-05-07 21:22:55 +02:00
|
|
|
print_enc ('')
|
2013-04-26 14:59:44 +02:00
|
|
|
exit()
|
|
|
|
|
|
|
|
arg = sys.argv[1]
|
|
|
|
|
2013-05-05 18:17:44 +02:00
|
|
|
fg = 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.''')
|
2014-07-06 19:38:34 +02:00
|
|
|
fe.summary(u'Lorem ipsum dolor sit amet, consectetur adipiscing elit…')
|
2013-04-26 14:59:44 +02:00
|
|
|
fe.link( href='http://example.com', rel='alternate' )
|
|
|
|
fe.author( name='Lars Kiesow', email='lkiesow@uos.de' )
|
|
|
|
|
|
|
|
if arg == 'atom':
|
2014-05-07 21:22:55 +02:00
|
|
|
print_enc (fg.atom_str(pretty=True))
|
2013-04-26 14:59:44 +02:00
|
|
|
elif arg == 'rss':
|
2014-05-07 21:22:55 +02:00
|
|
|
print_enc (fg.rss_str(pretty=True))
|
2013-04-29 19:34:51 +02:00
|
|
|
elif arg == 'podcast':
|
2013-05-05 18:17:44 +02:00
|
|
|
# Load the podcast extension. It will automatically be loaded for all
|
|
|
|
# entries in the feed, too. Thus also for our “fe”.
|
|
|
|
fg.load_extension('podcast')
|
|
|
|
fg.podcast.itunes_author('Lars Kiesow')
|
|
|
|
fg.podcast.itunes_category('Technology', 'Podcasting')
|
|
|
|
fg.podcast.itunes_explicit('no')
|
|
|
|
fg.podcast.itunes_complete('no')
|
|
|
|
fg.podcast.itunes_new_feed_url('http://example.com/new-feed.rss')
|
|
|
|
fg.podcast.itunes_owner('John Doe', 'john@example.com')
|
|
|
|
fg.podcast.itunes_summary('Lorem ipsum dolor sit amet, ' + \
|
|
|
|
'consectetur adipiscing elit. ' + \
|
|
|
|
'Verba tu fingas et ea dicas, quae non sentias?')
|
|
|
|
fe.podcast.itunes_author('Lars Kiesow')
|
2014-05-07 21:22:55 +02:00
|
|
|
print_enc (fg.rss_str(pretty=True))
|
2016-05-24 23:56:32 +02:00
|
|
|
|
|
|
|
elif arg == 'torrent':
|
|
|
|
fg.load_extension('torrent')
|
|
|
|
fe.link( href='http://somewhere.behind.the.sea/torrent/debian-8.4.0-i386-netint.iso.torrent', rel='alternate', type='application/x-bittorrent, length=1000' )
|
|
|
|
fe.torrent.filename('debian-8.4.0-i386-netint.iso.torrent')
|
|
|
|
fe.torrent.infohash('7661229811ef32014879ceedcdf4a48f256c88ba')
|
|
|
|
fe.torrent.contentlength('331350016')
|
|
|
|
fe.torrent.seeds('789')
|
|
|
|
fe.torrent.peers('456')
|
|
|
|
fe.torrent.verified('123')
|
|
|
|
print_enc (fg.rss_str(pretty=True))
|
2013-05-29 20:40:43 +02:00
|
|
|
|
2015-10-28 22:03:22 +01:00
|
|
|
elif arg.startswith('dc.'):
|
2013-05-29 20:40:43 +02:00
|
|
|
fg.load_extension('dc')
|
|
|
|
fg.dc.dc_contributor('Lars Kiesow')
|
2015-10-28 22:03:22 +01:00
|
|
|
if arg.endswith('.atom'):
|
|
|
|
print_enc (fg.atom_str(pretty=True))
|
|
|
|
else:
|
|
|
|
print_enc (fg.rss_str(pretty=True))
|
2013-05-02 14:21:46 +02:00
|
|
|
|
2015-10-28 22:03:22 +01:00
|
|
|
elif arg.startswith('syndication'):
|
|
|
|
fg.load_extension('syndication')
|
|
|
|
fg.syndication.update_period('daily')
|
|
|
|
fg.syndication.update_frequency(2)
|
|
|
|
fg.syndication.update_base('2000-01-01T12:00+00:00')
|
|
|
|
if arg.endswith('.rss'):
|
|
|
|
print_enc (fg.rss_str(pretty=True))
|
|
|
|
else:
|
|
|
|
print_enc (fg.atom_str(pretty=True))
|
2013-05-29 20:40:43 +02:00
|
|
|
|
2013-04-26 14:59:44 +02:00
|
|
|
elif arg.endswith('atom'):
|
|
|
|
fg.atom_file(arg)
|
2013-05-29 20:40:43 +02:00
|
|
|
|
2013-04-26 14:59:44 +02:00
|
|
|
elif arg.endswith('rss'):
|
|
|
|
fg.rss_file(arg)
|