news4 - RSS aggrigation system
Révision | d6001badc277c83a67e29255429130c140289dc5 (tree) |
---|---|
l'heure | 2012-10-31 20:06:14 |
Auteur | hylom <hylom@user...> |
Commiter | hylom |
Merge branch 'master' of hylom.net:~/gitroot/gnews into live
@@ -0,0 +1,21 @@ | ||
1 | +#!/usr/bin/python | |
2 | + | |
3 | +from config import config as config, target_rss as target_rss | |
4 | +import ConfigParser | |
5 | +import sys | |
6 | + | |
7 | +def main(): | |
8 | + config = ConfigParser.SafeConfigParser() | |
9 | + for item in target_rss: | |
10 | + config.add_section(item["name"]) | |
11 | + config.set(item["name"], 'source', item["url"]) | |
12 | + config.set(item["name"], 'url', item["source_url"]) | |
13 | + if 'filter' in item: | |
14 | + filters = ",".join(item["filter"]) | |
15 | + config.set(item["name"], 'filters', filters) | |
16 | + config.write(sys.stdout) | |
17 | + | |
18 | +if __name__ == '__main__': | |
19 | + main() | |
20 | + | |
21 | + |
@@ -5,7 +5,7 @@ import re | ||
5 | 5 | |
6 | 6 | import feedparser |
7 | 7 | import dateutil.parser |
8 | -from config import config as config, target_rss as target_rss | |
8 | +from config import config as config | |
9 | 9 | from logger import log |
10 | 10 | |
11 | 11 | class FeedFetcher(object): |
@@ -15,7 +15,7 @@ class FeedFetcher(object): | ||
15 | 15 | |
16 | 16 | def _fetch(self): |
17 | 17 | 'do fetch' |
18 | - f = feedparser.parse(self._feed["url"]) | |
18 | + f = feedparser.parse(self._feed["source"]) | |
19 | 19 | entries = [] |
20 | 20 | for e in f['entries']: |
21 | 21 | entry = { |
@@ -58,8 +58,8 @@ class FeedFetcher(object): | ||
58 | 58 | entries = self._fetch() |
59 | 59 | entries = self._apply_pre_filters(entries) |
60 | 60 | |
61 | - if 'filter' in self._feed: | |
62 | - filters = self._feed.get('filter', None) | |
61 | + if 'filters' in self._feed: | |
62 | + filters = self._feed.get('filters', None) | |
63 | 63 | entries = self._apply_filters(filters, entries) |
64 | 64 | |
65 | 65 | entries = self._apply_post_filters(entries) |
@@ -1,20 +1,24 @@ | ||
1 | 1 | #!/usr/bin/python |
2 | 2 | 'gnews.py - google news clone' |
3 | 3 | |
4 | -from config import config as config, target_rss as target_rss | |
4 | +from config import config as config | |
5 | 5 | import renderer |
6 | 6 | import fetcher |
7 | 7 | import os.path |
8 | 8 | import urllib |
9 | 9 | from logger import log |
10 | +import configloader | |
11 | + | |
12 | +sources = configloader.load() | |
10 | 13 | |
11 | 14 | def main(): |
12 | 15 | "gnews's main function" |
13 | - # TODO: argv check | |
16 | +# TODO: argv check | |
17 | + | |
14 | 18 | |
15 | 19 | # fetch RSS feed |
16 | 20 | entries = [] |
17 | - for feed in target_rss: | |
21 | + for feed in sources: | |
18 | 22 | f = fetcher.FeedFetcher(feed) |
19 | 23 | e = f.get_entries() |
20 | 24 | entries.extend(e) |
@@ -61,7 +65,7 @@ def main(): | ||
61 | 65 | def do_rendering(page_type, filename, entries, params): |
62 | 66 | "rendering page" |
63 | 67 | |
64 | - r = renderer.Renderer() | |
68 | + r = renderer.Renderer(sources) | |
65 | 69 | tmpl = config[page_type]['template'] |
66 | 70 | output_dir = config[page_type]['output_directory'] |
67 | 71 |
@@ -1,6 +1,6 @@ | ||
1 | 1 | 'logger.py - log output utility' |
2 | 2 | |
3 | -from config import config, target_rss | |
3 | +from config import config | |
4 | 4 | |
5 | 5 | def log(*args): |
6 | 6 | "log helper function" |
@@ -7,7 +7,7 @@ from mako.lookup import TemplateLookup | ||
7 | 7 | from mako.exceptions import RichTraceback |
8 | 8 | import dateutil.parser |
9 | 9 | |
10 | -from config import config, target_rss | |
10 | +from config import config | |
11 | 11 | from propertizer import propertize |
12 | 12 | from logger import log |
13 | 13 |
@@ -16,8 +16,9 @@ def date_format(date): | ||
16 | 16 | return date.strftime('%Y/%m/%d %H:%M') |
17 | 17 | |
18 | 18 | class Renderer(object): |
19 | - def __init__(self): | |
19 | + def __init__(self, sources): | |
20 | 20 | self.template_dir = config['template_directory'] |
21 | + self._sources = sources | |
21 | 22 | |
22 | 23 | def _get_template(self, template_name): |
23 | 24 | 'read template file' |
@@ -38,7 +39,7 @@ class Renderer(object): | ||
38 | 39 | 'entries': entries, |
39 | 40 | 'params': params, |
40 | 41 | 'site': config['site_parameter'], |
41 | - 'targets': target_rss, | |
42 | + 'sources': self._sources, | |
42 | 43 | } |
43 | 44 | for key in kwargs: |
44 | 45 | d = propertize(kwargs[key]) |
@@ -0,0 +1,54 @@ | ||
1 | +[So-netセキュリティ通信] | |
2 | +url = http://security-t.blog.so-net.ne.jp/ | |
3 | +source = http://security-t.blog.so-net.ne.jp/index.rdf | |
4 | +filters = tagging | |
5 | + | |
6 | +[Impress Watch] | |
7 | +url = http://www.watch.impress.co.jp/ | |
8 | +source = http://rss.rssad.jp/rss/headline/headline.rdf | |
9 | +filters = tagging | |
10 | + | |
11 | +[japan.internet.com] | |
12 | +url = http://japan.internet.com/ | |
13 | +source = http://rss.internetcom.jp/rss/japaninternetcom/index.rdf | |
14 | +filters = tagging | |
15 | + | |
16 | +[SourceForge.JP Magazine] | |
17 | +url = http://sourceforge.jp/magazine/ | |
18 | +source = http://rss.rssad.jp/rss/sourceforge/magazine/rss | |
19 | + | |
20 | +[WIRED.jp] | |
21 | +url = http://wired.jp/ | |
22 | +source = http://rss.rssad.jp/rss/h/wired/feed.rdf | |
23 | +filters = tagging | |
24 | + | |
25 | +[CNET Japan] | |
26 | +url = http://japan.cnet.com/ | |
27 | +source = http://feeds.japan.cnet.com/rss/cnet/all.rdf | |
28 | +filters = tagging | |
29 | + | |
30 | +[TechCrunch Japan] | |
31 | +url = http://jp.techcrunch.com/ | |
32 | +source = http://jp.techcrunch.com/feed/ | |
33 | +filters = tagging | |
34 | + | |
35 | +[ギズモード・ジャパン] | |
36 | +url = http://www.gizmodo.jp/ | |
37 | +source = http://feeds.gizmodo.jp/rss/gizmodo/index.xml | |
38 | +filters = tagging | |
39 | + | |
40 | +[Slashdot Japan] | |
41 | +url = http://slashdot.jp/ | |
42 | +source = http://rss.rssad.jp/rss/slashdot/slashdot.rss | |
43 | +filters = slashdotjp | |
44 | + | |
45 | +[Engadget Japanese] | |
46 | +url = http://japanese.engadget.com/ | |
47 | +source = http://japanese.engadget.com/rss.xml | |
48 | +filters = tagging | |
49 | + | |
50 | +[ITmedia] | |
51 | +url = http://www.itmedia.co.jp/ | |
52 | +source = http://rss.rssad.jp/rss/itmtop/2.0/itmedia_all.xml | |
53 | +filters = tagging,itmedia | |
54 | + |
@@ -79,7 +79,7 @@ s.parentNode.insertBefore(ga, s); | ||
79 | 79 | <a href='${entry.link}'>[続きを読む]</a> |
80 | 80 | </div> |
81 | 81 | <div class="information"> |
82 | - <span>情報元:<a href='${entry.feed.source_url}'>${entry.feed.name}</a></span> | |
82 | + <span>情報元:<a href='${entry.feed.url}'>${entry.feed.name}</a></span> | |
83 | 83 | <span>(${date_format(entry.date)})</span> |
84 | 84 | <span>タグ:</span> |
85 | 85 | % for tag in entry.tags: |
@@ -114,8 +114,8 @@ s.parentNode.insertBefore(ga, s); | ||
114 | 114 | <div class="feed-provider"> |
115 | 115 | <h3>情報提供サイト:</h3> |
116 | 116 | <ul class="nav nav-pills nav-stacked"> |
117 | - % for item in targets: | |
118 | - <li><a href="${item.source_url}">${item.name}</a></li> | |
117 | + % for item in sources: | |
118 | + <li><a href="${item.source}">${item.name}</a></li> | |
119 | 119 | % endfor |
120 | 120 | </ul> |
121 | 121 | </div> |