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 977B

1234567891011121314151617181920212223242526272829
  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. FEED_LINK = 'https://linux.die.net/man/6/fortune'
  7. FEED_TITLE = 'Fortune'
  8. FEED_DESCRIPTION = 'Random, hopefully interesting, adages'
  9. NUM_ITEMS = 1 # Kodi would choke on more :(
  10. MAX_LENGTH = 69
  11. rss_items = []
  12. for i in range(NUM_ITEMS):
  13. with Popen(['fortune', '-s', '-n', str(MAX_LENGTH)], encoding='utf-8', stdout=PIPE) as fortune:
  14. rss_items.append(gen_item(
  15. title=fortune.stdout.read().strip().replace('\n',' ').replace('\t',' '),
  16. link=FEED_LINK,
  17. pubDate=(datetime.now()-timedelta(minutes=i)).isoformat()))
  18. rss_xml_element = start_rss(
  19. title=FEED_TITLE, link=FEED_LINK,
  20. description=FEED_DESCRIPTION, items=rss_items)
  21. sys.stdout.write(str(
  22. xml.etree.ElementTree.tostring(
  23. rss_xml_element, encoding='utf-8', method='xml'),
  24. 'utf-8'))