def main(): mb = LocalClient('datacommons') sys.stdout.write("""<?xml version="1.0" encoding="utf-8"?>\n<sphinx:docset>\n""") for doc in mb.search(**{'_type': 'politician'}): data = { 'id': doc['_suid'], 'name': xmlclean(doc['name']), 'type': doc['_type'], } if 'aliases' in doc: data['aliases'] = ', '.join((xmlclean(a) for a in doc['aliases'])) else: data['aliases'] = '' content = """\t<sphinx:document id="%(id)s">\n\t\t<entity>%(name)s</entity>\n\t\t<aliases>%(aliases)s</aliases>\n\t\t<type>%(type)s</type>\n\t</sphinx:document>\n""" % data sys.stdout.write(content) sys.stdout.write("""</sphinx:docset>""")
import datetime try: import json except ImportError: import simplejson as json from django.http import HttpResponse, HttpResponseBadRequest from django.views.decorators.http import require_POST from matchbox.api import LocalClient client = LocalClient('datacommons') def _querydict_to_dict(qd): d = {} for k,l in qd.iterlists(): if len(l) == 1: l = l[0] d[str(k)] = l return d def _jsonize(data): if isinstance(data, list): return [_jsonize(i) for i in data] for k,v in data.iteritems(): if isinstance(v, datetime.datetime): data[k] = str(v) return data def entity(request, uid=None): data = None if request.method == 'POST':