Data searching challenge.
- json data is valid
- Each json data is an array
- Open and closing bracket is on its own line. No open or closing bracket inside each object
- key-value or array's item is on its own line
- No character needs to be escaped inside each key/value
- Stream file content line by line
- On open bracket, begin storing values in temporary object store in memory
- On closing of bracket yield the corresponding model object
- Check for value matching with search term when iterating each object
- Matched object will be populated with additional metadata from relation with other data
- Print the populated objects and skip the unmatched ones
- On closing square bracket, stop processing
TODO: Setup python logger to report logs to file and also on stdout
Install the project with poetry and start a shell
pip install --user poetry
poetry install
poetry shell
Then just start development inside the virtual environment that poetry created
Usage follow the principle of normal *NIX commandline tools
❯ poetry run search -h
Successfully set up prettification!
> All function returns will now be pretty-printed,
'[245 italic]Including [/italic 210]Markup!'
usage: search [-h] -m {user,ticket,organization} -s TERM [-f FIELD]
optional arguments:
-h, --help show this help message and exit
-m {user,ticket,organization}, --mode {user,ticket,organization}
Search mode
-s TERM, --term TERM Search term
-f FIELD, --field FIELD
Field to search for
If you just provide the mode, the command will suggest searchable fields for you to choose
❯ poetry run search -m user
Successfully set up prettification!
> All function returns will now be pretty-printed,
'[245 italic]Including [/italic 210]Markup!'
'Please provide search term!'
'For fine grained, you can filter by the specific fields below:'
[
'_id',
'url',
'external_id',
'name',
'alias',
'created_at',
'active',
'verified',
'shared',
'locale',
'timezone',
'last_login_at',
'email',
'phone',
'signature',
'organization_id',
'tags',
'suspended',
'role',
]
If you omit the specific field, the command will do fuzzy search over all the fields
❯ poetry run search -m user -s 'Sri Lanka'
Successfully set up prettification!
> All function returns will now be pretty-printed,
'[245 italic]Including [/italic 210]Markup!'
'Searching users with (term: Sri Lanka, field: None)...'
{ '_id': 1,
'active': True,
'alias': 'Miss Coffey',
'assigned_tickets': [ 'A Problem in Russian Federation',
'A Problem in Malawi'],
'created_at': '2016-04-15T05:19:46 -10:00',
'email': '[email protected]',
'external_id': '74341f74-9c79-49d5-9611-87ef9b6eb75f',
'last_login_at': '2013-08-04T01:03:27 -10:00',
'locale': 'en-AU',
'name': 'Francisca Rasmussen',
'organization_id': 119,
'organization_name': 'Multron',
'phone': '8335-422-718',
'role': 'admin',
'shared': False,
'signature': "Don't Worry Be Happy!",
'submitted_tickets': [ 'A Nuisance in Kiribati',
'A Nuisance in Saint Lucia'],
'suspended': True,
'tags': ['Springville', 'Sutton', 'Hartsville/Hartley', 'Diaperville'],
'timezone': 'Sri Lanka',
'url': 'http://initech.tokoin.io.com/api/v2/users/1.json',
'verified': True}
- For fantastic TUI, pytermgui is chosen.
TODO: make a TUI so that user can have master-detail view layout (to load metadata to show on demand)
poetry install
poetry run pytest -s -v
With poetry
, building python package is simple
poetry build
- Using pyrser to parse json file iteratively into AST and doing the search string matcher on the hooks.