def cmd_q(fb, qstr): """run a freebase query. if the query string starts with "{" it is treated as json. otherwise it is treated as o-rison. dump the result as json. %prog q """ if qstr.startswith('{'): q = simplejson.loads(qstr) else: q = rison.loads('(' + qstr + ')') # done this way for streaming first = True for result in fb.mss.mqlreaditer(q): if first: first = False print '[', else: print ',', print simplejson.dumps(result, indent=2), print ']'
def cmd_q(fb, qstr): """run a freebase query. if the query string starts with "{" it is treated as json. otherwise it is treated as o-rison. dump the result as json. %prog q """ if qstr.startswith('{'): q = simplejson.loads(qstr) else: q = rison.loads('(' + qstr + ')') # results could be streamed with a little more work results = fb.mss.mqlreaditer(q) print simplejson.dumps(list(results), indent=2)
def cmd_find(fb, qstr): """print all ids matching a given constraint. if the query string starts with "{" it is treated as json. otherwise it is treated as o-rison. %prog find """ if qstr.startswith('{'): q = simplejson.loads(qstr) else: q = rison.loads('(' + qstr + ')') if 'id' not in q: q['id'] = None results = fb.mss.mqlreaditer(q) for r in results: out(r.id)