def export_solr_dump(core=''): """ Export the wtf_json field of every doc in the index to a new document in the users core and to the user's local file system. Uses the current user's ID and a timestamp as the document ID and file name. :param core: """ dow = days_of_week[datetime.datetime.today().weekday()] if core != 'hb2_users': filename = '%s/%s/%s_%s.json' % ( secrets.BACKUP_DIR, dow, datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), core) export_solr = Solr(host=secrets.SOLR_HOST, port=secrets.SOLR_PORT, application=secrets.SOLR_APP, export_field='wtf_json', core=core) export_docs = export_solr.export() fo = open(filename, 'w') fo.write(json.dumps(export_docs, indent=4)) fo.close() filename = '%s/%s/%s_%s.not_imported.json' % ( secrets.BACKUP_DIR, dow, datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), core) export_solr = Solr(host=secrets.SOLR_HOST, port=secrets.SOLR_PORT, application=secrets.SOLR_APP, query='-editorial_status:imported', export_field='wtf_json', core=core) export_docs = export_solr.export() fo = open(filename, 'w') fo.write(json.dumps(export_docs, indent=4)) fo.close() else: filename = '%s/%s/%s_%s.json' % ( secrets.BACKUP_DIR, dow, datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), core) export_solr = Solr(host=secrets.SOLR_HOST, port=secrets.SOLR_PORT, application=secrets.SOLR_APP, core=core) export_docs = export_solr.export() fo = open(filename, 'w') fo.write(json.dumps(export_docs, indent=4)) fo.close()
def export_solr_dump(): dow = days_of_week[datetime.datetime.today().weekday()] filename = '%s/%s/%s_%s.dead_ends.json' % (secrets.BACKUP_DIR, dow, datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), 'hb2') export_solr = Solr(host=secrets.SOLR_HOST, port=secrets.SOLR_PORT, application=secrets.SOLR_APP, query='is_part_of:[\'\' TO *]', export_field='wtf_json', core='hb2') export_docs = export_solr.export() # TODO get id of the host and check if it exists dead_ends = [] for doc in export_docs: for part in doc.get('is_part_of'): try: query = 'id:%s' % part.get('is_part_of') get_record_solr = Solr(host=secrets.SOLR_HOST, port=secrets.SOLR_PORT, application=secrets.SOLR_APP, core='hb2', query=query, facet='false', fields=['wtf_json']) get_record_solr.request() if len(get_record_solr.results) == 0: print('%s is a dead end' % part.get('is_part_of')) if part.get('is_part_of') not in dead_ends: dead_ends.append(part.get('is_part_of')) except AttributeError as e: print(e) fo = open(filename, 'w') fo.write(json.dumps(dead_ends, indent=4)) fo.close()
def export_solr_query(core='', query='*:*', filename=''): if core != 'hb2_users': if filename != '': dow = days_of_week[datetime.datetime.today().weekday()] filename = '%s/%s/%s_%s.%s' % ( secrets.BACKUP_DIR, dow, datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), core, filename) export_solr = Solr(host=secrets.SOLR_HOST, port=secrets.SOLR_PORT, application=secrets.SOLR_APP, query=query, export_field='wtf_json', core=core) export_docs = export_solr.export() fo = open(filename, 'w') fo.write(json.dumps(export_docs, indent=4)) fo.close()