Skip to content

Commit

Permalink
Replace hierarchical DB lookup with a single key/value.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Nofi committed Sep 2, 2012
1 parent fb7c823 commit d013b8b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
9 changes: 2 additions & 7 deletions fetch_data/wikiparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class WikiParse(object):
def __init__(self, wiki_username=None, wiki_password=None, verbose=False):
self.site = mwclient.Site(WIKIPEDIA_URL)
self.site.login(wiki_username, wiki_password)
self.births = rdict()
self.births = collections.defaultdict(list)
if verbose:
logger.setLevel(logging.INFO)

Expand All @@ -57,7 +57,7 @@ def fetch_data(self):
logger.warning("Skipping entry with bad year: " + birth_line)
continue
if year > MIN_YEAR:
self.births[year][day.month][day.day] = person
self.births["%d%s%s" % (year, day.month, day.day)].append(person)
else:
logger.debug("Skipping old entry: " + birth_line)
logger.info("Finished Wikipedia parse")
Expand Down Expand Up @@ -104,11 +104,6 @@ def parse_births(contents):
return [b for b in birth_text.split("\n") if b.startswith("*")]


def rdict(*args, **kw):
"""Recursive Default Dictionary"""
return collections.defaultdict(rdict, *args, **kw)


def parse_command_line_options():
"""Parse and return command line options."""
parser = OptionParser()
Expand Down
3 changes: 2 additions & 1 deletion server/requestHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ function lookup(query, response) {
var year = querystring.parse(query)["year"];
var month = querystring.parse(query)["month"];
var day = querystring.parse(query)["day"];
var content = birthdayDB[year][month][day];
var key = year + month + day;
var content = birthdayDB[key];

response.writeHead(200, {"Content-Type": "text/html"});
response.write(content);
Expand Down

0 comments on commit d013b8b

Please sign in to comment.