def index_actor(procedure, db, solr): entry = {'_collection': 'actor', 'key': actor.get('key')} entry['_id'] = str(actor['_id']) entry['title'] = actor.get('name') if actor.get('department'): entry['department'] = actor.get('department') if actor.get('group'): entry['group'] = actor.get('group') if actor.get('function'): entry['function'] = actor.get('function') if actor.get('party'): entry['party'] = actor.get('party') if actor.get('state'): entry['state'] = actor.get('state') if actor.get('constituency'): entry['constituency'] = actor.get('constituency', {}).get('name') if 'bio' in actor: entry['description'] = actor['bio'] solr.add(**entry) solr.commit() def index_actors(db, solr): for actor in db.actor.find(): index_actor(actor, db, solr) if __name__ == '__main__': index_actors(connect_db(), connect_solr())
from pprint import pprint from parltrack.environment import connect_db, connect_solr def index_procedure(procedure, db, solr): pprint(procedure) entry = {'_id': procedure['_id'], '_collection': 'procedure'} entry['finished'] = procedure.get('finished') entry['state'] = procedure.get('state') entry['reference'] = procedure.get('reference') entry['title'] = procedure.get('title') entry['parliament'] = procedure.get('parliament') entry['session'] = procedure.get('session') entry['session'] = procedure.get('session') entry['subject'] = procedure.get('subjects') entry['tag'] = procedure.get('tags') entry['initiative'] = procedure.get('initiative') entry['description'] = procedure.get('description') solr.add(**entry) solr.commit() def index_procedures(db, solr): for procedure in db.procedure.find(): index_procedure(procedure, db, solr) if __name__ == '__main__': index_procedures(connect_db(), connect_solr())
def index_actor(procedure, db, solr): entry = {"_collection": "actor", "key": actor.get("key")} entry["_id"] = str(actor["_id"]) entry["title"] = actor.get("name") if actor.get("department"): entry["department"] = actor.get("department") if actor.get("group"): entry["group"] = actor.get("group") if actor.get("function"): entry["function"] = actor.get("function") if actor.get("party"): entry["party"] = actor.get("party") if actor.get("state"): entry["state"] = actor.get("state") if actor.get("constituency"): entry["constituency"] = actor.get("constituency", {}).get("name") if "bio" in actor: entry["description"] = actor["bio"] solr.add(**entry) solr.commit() def index_actors(db, solr): for actor in db.actor.find(): index_actor(actor, db, solr) if __name__ == "__main__": index_actors(connect_db(), connect_solr())