Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yuriy Bogdanov
committed
Jan 28, 2016
1 parent
c468f25
commit bb23355
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|