• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

news4 - RSS aggrigation system


Commit MetaInfo

修订版d6001badc277c83a67e29255429130c140289dc5 (tree)
时间2012-10-31 20:06:14
作者hylom <hylom@user...>
Commiterhylom

Log Message

Merge branch 'master' of hylom.net:~/gitroot/gnews into live

更改概述

差异

--- /dev/null
+++ b/config2ini.py
@@ -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+
--- a/fetcher.py
+++ b/fetcher.py
@@ -5,7 +5,7 @@ import re
55
66 import feedparser
77 import dateutil.parser
8-from config import config as config, target_rss as target_rss
8+from config import config as config
99 from logger import log
1010
1111 class FeedFetcher(object):
@@ -15,7 +15,7 @@ class FeedFetcher(object):
1515
1616 def _fetch(self):
1717 'do fetch'
18- f = feedparser.parse(self._feed["url"])
18+ f = feedparser.parse(self._feed["source"])
1919 entries = []
2020 for e in f['entries']:
2121 entry = {
@@ -58,8 +58,8 @@ class FeedFetcher(object):
5858 entries = self._fetch()
5959 entries = self._apply_pre_filters(entries)
6060
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)
6363 entries = self._apply_filters(filters, entries)
6464
6565 entries = self._apply_post_filters(entries)
--- a/gnews.py
+++ b/gnews.py
@@ -1,20 +1,24 @@
11 #!/usr/bin/python
22 'gnews.py - google news clone'
33
4-from config import config as config, target_rss as target_rss
4+from config import config as config
55 import renderer
66 import fetcher
77 import os.path
88 import urllib
99 from logger import log
10+import configloader
11+
12+sources = configloader.load()
1013
1114 def main():
1215 "gnews's main function"
13- # TODO: argv check
16+# TODO: argv check
17+
1418
1519 # fetch RSS feed
1620 entries = []
17- for feed in target_rss:
21+ for feed in sources:
1822 f = fetcher.FeedFetcher(feed)
1923 e = f.get_entries()
2024 entries.extend(e)
@@ -61,7 +65,7 @@ def main():
6165 def do_rendering(page_type, filename, entries, params):
6266 "rendering page"
6367
64- r = renderer.Renderer()
68+ r = renderer.Renderer(sources)
6569 tmpl = config[page_type]['template']
6670 output_dir = config[page_type]['output_directory']
6771
--- a/logger.py
+++ b/logger.py
@@ -1,6 +1,6 @@
11 'logger.py - log output utility'
22
3-from config import config, target_rss
3+from config import config
44
55 def log(*args):
66 "log helper function"
--- a/renderer.py
+++ b/renderer.py
@@ -7,7 +7,7 @@ from mako.lookup import TemplateLookup
77 from mako.exceptions import RichTraceback
88 import dateutil.parser
99
10-from config import config, target_rss
10+from config import config
1111 from propertizer import propertize
1212 from logger import log
1313
@@ -16,8 +16,9 @@ def date_format(date):
1616 return date.strftime('%Y/%m/%d %H:%M')
1717
1818 class Renderer(object):
19- def __init__(self):
19+ def __init__(self, sources):
2020 self.template_dir = config['template_directory']
21+ self._sources = sources
2122
2223 def _get_template(self, template_name):
2324 'read template file'
@@ -38,7 +39,7 @@ class Renderer(object):
3839 'entries': entries,
3940 'params': params,
4041 'site': config['site_parameter'],
41- 'targets': target_rss,
42+ 'sources': self._sources,
4243 }
4344 for key in kwargs:
4445 d = propertize(kwargs[key])
--- /dev/null
+++ b/sources.ini.sample
@@ -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+
--- a/templates/index.tmpl.html
+++ b/templates/index.tmpl.html
@@ -79,7 +79,7 @@ s.parentNode.insertBefore(ga, s);
7979 <a href='${entry.link}'>[続きを読む]</a>
8080 </div>
8181 <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>
8383 <span>(${date_format(entry.date)})</span>
8484 <span>タグ:</span>
8585 % for tag in entry.tags:
@@ -114,8 +114,8 @@ s.parentNode.insertBefore(ga, s);
114114 <div class="feed-provider">
115115 <h3>情報提供サイト:</h3>
116116 <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>
119119 % endfor
120120 </ul>
121121 </div>