<commit_before>#!/usr/bin/env python

import json
import rethinkdb as r
import sys
import optparse

if __name__ == "__main__":
    parser = optparse.OptionParser()
    parser.add_option("-p", "--port", dest="port",
                      help="rethinkdb port", default=30815)
    parser.add_option("-f", "--file", dest="filename",
                      help="json file", type="string")
    (options, args) = parser.parse_args()
    if options.filename is None:
        print "You must specify json file"
        sys.exit(1)
    conn = r.connect('localhost', int(options.port), db='materialscommons')
    json_data = open(options.filename)
    data = json.load(json_data)
    existing = r.table('templates').get(data['id']).run(conn)
    if existing:
        r.table('templates').get(data['id']).delete().run(conn)
        r.table('templates').insert(data).run(conn)
        print 'template deleted and re-inserted into the database'
    else:
        r.table('templates').insert(data).run(conn)
        print 'template inserted into the database'<commit_msg>Update script to show which file it is loading.<commit_after>#!/usr/bin/env python

import json
import rethinkdb as r
import sys
import optparse

if __name__ == "__main__":
    parser = optparse.OptionParser()
    parser.add_option("-p", "--port", dest="port",
                      help="rethinkdb port", default=30815)
    parser.add_option("-f", "--file", dest="filename",
                      help="json file", type="string")
    (options, args) = parser.parse_args()
    if options.filename is None:
        print "You must specify json file"
        sys.exit(1)
    conn = r.connect('localhost', int(options.port), db='materialscommons')
    json_data = open(options.filename)
    print "Loading template file: %s" % (options.filename)
    data = json.load(json_data)
    existing = r.table('templates').get(data['id']).run(conn)
    if existing:
        r.table('templates').get(data['id']).delete().run(conn)
        r.table('templates').insert(data).run(conn)
        print 'template deleted and re-inserted into the database'
    else:
        r.table('templates').insert(data).run(conn)
        print 'template inserted into the database'
{'fraction_non_alphanumeric': 0.1490711372904395, 'fraction_numerical': 0.005437245129134572, 'mean_word_length': 3.104089219330855, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7531085', 'n_tokens_mistral': 656, 'n_tokens_neox': 647, 'n_words': 159}