news4 - RSS aggrigation system
Revisão | 1f38193e599003353169196f3064e99ed0f3e4be (tree) |
---|---|
Hora | 2012-10-19 22:43:22 |
Autor | hylom <hylom@hylo...> |
Commiter | hylom |
add logging utils
@@ -6,6 +6,7 @@ import re | ||
6 | 6 | import feedparser |
7 | 7 | import dateutil.parser |
8 | 8 | from config import config as config, target_rss as target_rss |
9 | +from logger import log | |
9 | 10 | |
10 | 11 | class FeedFetcher(object): |
11 | 12 | 'Feed fetching and parsing' |
@@ -34,7 +35,7 @@ class FeedFetcher(object): | ||
34 | 35 | def _embeded_filter(self, entry): |
35 | 36 | # remove PR entry |
36 | 37 | if re.search(u'^(PR|AD)(:|:)', entry['title']): |
37 | - print 'delete PR entry - %s' % entry['title'] | |
38 | + log('delete PR entry - %s' % entry['title']) | |
38 | 39 | return None |
39 | 40 | return entry |
40 | 41 |
@@ -5,7 +5,7 @@ import re | ||
5 | 5 | |
6 | 6 | def entry_filter(entry): |
7 | 7 | if re.search(u'^(PR|AD)(:|:)', entry['title']): |
8 | - print 'delete PR entry - %s' % entry['title'] | |
8 | + #print 'delete PR entry - %s' % entry['title'] | |
9 | 9 | return None |
10 | 10 | return entry |
11 | 11 |
@@ -6,10 +6,7 @@ import renderer | ||
6 | 6 | import fetcher |
7 | 7 | import os.path |
8 | 8 | import urllib |
9 | - | |
10 | -def _log(*args): | |
11 | - "log helper function" | |
12 | - print ' '.join(args) | |
9 | +from logger import log | |
13 | 10 | |
14 | 11 | def main(): |
15 | 12 | "gnews's main function" |
@@ -46,7 +43,7 @@ def main(): | ||
46 | 43 | entries.sort(cmp_entries) |
47 | 44 | |
48 | 45 | for e in entries: |
49 | - print e["date"] | |
46 | + log(e["date"]) | |
50 | 47 | |
51 | 48 | # do rendering |
52 | 49 | params = {'tags':tags, 'page':{}, 'sorted_tags':sorted_tags} |
@@ -84,7 +81,7 @@ def do_rendering(page_type, filename, entries, params): | ||
84 | 81 | else: |
85 | 82 | output_fullpath = os.path.join(output_dir, filename % page) |
86 | 83 | |
87 | - _log('generate ' + output_fullpath + '...') | |
84 | + log('generate ' + output_fullpath + '...') | |
88 | 85 | f = open(output_fullpath, "w") |
89 | 86 | html = r.render(tmpl, entries[start:end], params) |
90 | 87 | f.write(html) |
@@ -9,6 +9,7 @@ import dateutil.parser | ||
9 | 9 | |
10 | 10 | from config import config, target_rss |
11 | 11 | from propertizer import propertize |
12 | +from logger import log | |
12 | 13 | |
13 | 14 | def date_format(date): |
14 | 15 | #dt = dateutil.parser.parse(date) |
@@ -47,9 +48,9 @@ class Renderer(object): | ||
47 | 48 | except: |
48 | 49 | traceback = RichTraceback() |
49 | 50 | for (filename, lineno, function, line) in traceback.traceback: |
50 | - print "File %s, line %s, in %s" % (filename, lineno, function) | |
51 | - print line, "\n" | |
52 | - print "%s: %s" % (str(traceback.error.__class__.__name__), traceback.error) | |
51 | + log("File %s, line %s, in %s" % (filename, lineno, function)) | |
52 | + log(line, "\n") | |
53 | + log("%s: %s" % (str(traceback.error.__class__.__name__), traceback.error)) | |
53 | 54 | sys.exit(-1) |
54 | 55 | return result |
55 | 56 |