-
Notifications
You must be signed in to change notification settings - Fork 1
/
article-stats.py
34 lines (26 loc) · 968 Bytes
/
article-stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# When rawdog shuts down, print some simple statistics about articles.
# Copyright 2005 Adam Sampson <[email protected]>
import rawdoglib.plugins
class Stats:
"""Track counts of articles."""
def __init__(self):
self.added = 0
self.updated = 0
self.expired = 0
def article_added(self, rawdog, config, article, now):
self.added += 1
return True
def article_updated(self, rawdog, config, article, now):
self.updated += 1
return True
def article_expired(self, rawdog, config, article, now):
self.expired += 1
return True
def shutdown(self, rawdog, config):
print "%d %d %d %d" % (self.added, self.updated, self.expired, len(rawdog.articles))
return True
stats = Stats()
rawdoglib.plugins.attach_hook("article_added", stats.article_added)
rawdoglib.plugins.attach_hook("article_updated", stats.article_updated)
rawdoglib.plugins.attach_hook("article_expired", stats.article_expired)
rawdoglib.plugins.attach_hook("shutdown", stats.shutdown)