aboutsummaryrefslogtreecommitdiff
path: root/example.py
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-08-11 01:37:11 +0200
committerPacien TRAN-GIRARD2015-08-11 12:35:27 +0200
commit45b8d0637a0669c3281fc0449b08a93ea0b7a809 (patch)
tree654cdd9948c176ec7259acb4b90b8d44b6b76274 /example.py
downloadafeedprocessor-45b8d0637a0669c3281fc0449b08a93ea0b7a809.tar.gz
First (working) version
Diffstat (limited to 'example.py')
-rw-r--r--example.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/example.py b/example.py
new file mode 100644
index 0000000..7b9bd83
--- /dev/null
+++ b/example.py
@@ -0,0 +1,32 @@
1#!/usr/bin/env python3
2
3from afeedprocessor.anitemprocessor import ItemProcessor
4from afeedprocessor.afeedprocessor import FeedProcessor
5from afeedprocessor.afeedparser import FeedParser
6
7
8class HackerNewsItemProcessor(ItemProcessor):
9 def get_title(self, title, item):
10 return title.replace('Alphabet', 'Evil Corp')
11
12 def get_description(self, description, item):
13 return description # actually fetching and modifying the description is left as an exercise for the reader.
14
15
16class HackerNewsFeedProcessor(FeedProcessor):
17 def get_title(self, title, feed):
18 return 'Hacked News'
19
20 def get_description(self, description, feed):
21 return description.replace('readers', 'hackers')
22
23
24if __name__ == '__main__':
25 feed_url = 'http://news.ycombinator.com/rss'
26 feed = FeedParser().parse(feed_url)
27
28 processor = HackerNewsFeedProcessor(HackerNewsItemProcessor())
29 processed_feed = processor.process(feed)
30
31 feed_string = processed_feed.to_xml()
32 print(feed_string)