File size: 893 Bytes
a431caa |
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 |
from OnetWebService import OnetWebService
import sys
import json
# read JSON input
input = json.load(sys.stdin)
# initialize Web Services and results objects
onet_ws = OnetWebService(input['config']['username'], input['config']['password'])
max_results = max(500, input['config']['max_results'])
output = { 'output': [] }
# call keyword search for each input query
for q in input['queries']:
res = []
kwresults = onet_ws.call('online/search',
('keyword', q),
('end', max_results))
if ('occupation' in kwresults) and (0 < len(kwresults['occupation'])):
for occ in kwresults['occupation']:
res.append({ 'code': occ['code'], 'title': occ['title'] })
output['output'].append({ 'query': q, 'results': res })
json.dump(output, sys.stdout, indent=2, sort_keys=True) |