Browse Source

Make feed machine-friendly (e.g. pubDate)

master
The Dod 4 years ago
parent
commit
a4d21d8213
1 changed files with 6 additions and 2 deletions
  1. 6
    2
      fortunefeed.py

+ 6
- 2
fortunefeed.py View File

1
 import sys
1
 import sys
2
 from subprocess import Popen, PIPE
2
 from subprocess import Popen, PIPE
3
+from datetime import datetime, timedelta
3
 from min_rss_gen.generator import start_rss, gen_item
4
 from min_rss_gen.generator import start_rss, gen_item
4
 import xml.etree.ElementTree
5
 import xml.etree.ElementTree
5
 
6
 
7
 FEED_TITLE = 'Fortune'
8
 FEED_TITLE = 'Fortune'
8
 FEED_DESCRIPTION = 'Random, hopefully interesting, adages'
9
 FEED_DESCRIPTION = 'Random, hopefully interesting, adages'
9
 NUM_ITEMS = 3
10
 NUM_ITEMS = 3
10
-MAX_LENGTH = 42
11
+MAX_LENGTH = 69
11
 
12
 
12
 rss_items = []
13
 rss_items = []
13
 
14
 
14
 for i in range(NUM_ITEMS):
15
 for i in range(NUM_ITEMS):
15
     with Popen(['fortune', '-s', '-n', str(MAX_LENGTH)], encoding='utf-8', stdout=PIPE) as fortune:
16
     with Popen(['fortune', '-s', '-n', str(MAX_LENGTH)], encoding='utf-8', stdout=PIPE) as fortune:
16
-        rss_items.append(gen_item(title=fortune.stdout.read().strip().replace('\n',' ').replace('\t',' ')))
17
+        rss_items.append(gen_item(
18
+            title=fortune.stdout.read().strip().replace('\n',' ').replace('\t',' '),
19
+            link=FEED_LINK,
20
+            pubDate=(datetime.now()-timedelta(minutes=i)).isoformat()))
17
 
21
 
18
 rss_xml_element = start_rss(
22
 rss_xml_element = start_rss(
19
     title=FEED_TITLE, link=FEED_LINK,
23
     title=FEED_TITLE, link=FEED_LINK,

Loading…
Cancel
Save