123456789101112131415161718192021222324252627282930 |
- import sys
- from subprocess import Popen, PIPE
- from datetime import datetime, timedelta
- from min_rss_gen.generator import start_rss, gen_item
- import xml.etree.ElementTree
-
- FORTUNE_CMD = '/usr/games/fortune'
- FEED_LINK = 'https://linux.die.net/man/6/fortune'
- FEED_TITLE = 'Fortune'
- FEED_DESCRIPTION = 'Random, hopefully interesting, adages'
- NUM_ITEMS = 1 # Kodi would choke on more :(
- MAX_LENGTH = 42 # This much Kodi seems to handle
-
- rss_items = []
-
- for i in range(NUM_ITEMS):
- with Popen([FORTUNE_CMD, '-s', '-n', str(MAX_LENGTH)], encoding='utf-8', stdout=PIPE) as fortune:
- rss_items.append(gen_item(
- title=fortune.stdout.read().strip().replace('\n',' ').replace('\t',' '),
- link=FEED_LINK,
- pubDate=(datetime.now()-timedelta(minutes=i)).isoformat()))
-
- rss_xml_element = start_rss(
- title=FEED_TITLE, link=FEED_LINK,
- description=FEED_DESCRIPTION, items=rss_items)
-
- sys.stdout.write(str(
- xml.etree.ElementTree.tostring(
- rss_xml_element, encoding='utf-8', method='xml'),
- 'utf-8'))
|