Script to generate an RSS feed containing a few `fortune -s` items. Use it as a cron job to generate something you can see in a ticker (e.g. on Kodi)
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

fortunefeed.py 1.0KB

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