Skip to content

Commit

Permalink
search.py and content.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy Bogdanov committed Jan 28, 2016
1 parent c468f25 commit bb23355
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
24 changes: 24 additions & 0 deletions content.md
@@ -0,0 +1,24 @@
# Content management guide

This doc is in progress. I'm dumping the stuff here right now, will organize it later.

```
$ cat data/wiki.json | scripts/search.py -n "Akbar"
{
"to": 1605,
"from": 1542,
"name": "Akbar",
"type": ""
}
```

```
$ cat data/intermediate/pantheon.json | scripts/search.py -n "Akbar"
{
"rating": 0.784730416875,
"country": "Pakistan",
"from": 1542,
"name": "Akbar",
"type": "politics"
}
```
22 changes: 22 additions & 0 deletions scripts/search.py
@@ -0,0 +1,22 @@
#!/usr/bin/python

import sys
import json
import argparse
from bisect import bisect_left

parser = argparse.ArgumentParser(description='Searches a person in a dataset, case insensitive.')
parser.add_argument('-n', '--name', help='search by person name')
args = parser.parse_args()

data = json.load(sys.stdin)
keys = [item['name'].lower() for item in data]

k = args.name.lower()
i = bisect_left(keys, k)
if i < len(data) and data[i]['name'].lower() == k:
print json.dumps(data[i], indent=4, separators=(',', ': '))
else:
print "{}"
sys.exit(1)

0 comments on commit bb23355

Please sign in to comment.