<commit_before>#This code focuses on parsing the code from CSV to JSON objects

import json
import csv

#Steps for the parser
#open CSV file
#Scan through characters

inputFile = raw_input("Input file path to CSV file:\n")

#open csv file as read in
csvInput = open(inputFile, "rU")
#open json output file as write only
jsonOutput = open("tmp.json", "w")
#column titles to pull information in with
columnNames = ("Document Title", "Saved File Name", "Tags")
#open CSV parser with the input file, searcing the columnNames, and 
#configure it for the excel CSV format
csvReader = csv.DictReader(csvInput, columnNames, dialect = "excel")

#for each row, convert column data into json object and write to file
for row in csvReader:
	json.dump(row, jsonOutput)
	jsonOutput.write("\n")<commit_msg>Parser now creates mongodb database file based on the schema<commit_after>#This code focuses on parsing the code from CSV to JSON objects

import json
import csv

#prompt for data to parse
inputFile = raw_input("Input file path to CSV file: (default: Workbook1.csv)\n")
#default file path
if(inputFile == ''):
	inputFile = "Workbook1.csv"

#open csv file as read in
csvInput = open(inputFile, "rU")
#open json output file as write only
jsonOutput = open("seed.js", "w")
#column titles to pull information in with
columnNames = ("Title", "Filename", "Subject", "Keywords", "Coverage", "Audience", "Language", "Source", "License", "Creation_Date", "Contributor", "Added_Date")
#open CSV parser with the input file, searcing the columnNames, and 
#configure it for the excel CSV format
csvReader = csv.DictReader(csvInput, columnNames, dialect = "excel")

#create head of database seed file
jsonOutput.write("'use strict';\n")
jsonOutput.write("var library_object = require('../models/library_object.js');\n")
jsonOutput.write("library_object.find({}).remove(function() {\n    library_object.create(\n")

#ignore title bar
csvReader.next()
#cycle through each entry and format for JSON
out = "\n\t" + ",\n\t".join([json.dumps(row, indent=8) for row in csvReader])

#ouptput to JSON file
jsonOutput.write(out)
#write tail end of file
jsonOutput.write("\n    );\n});")

#close files
csvInput.close()
jsonOutput.close()
{'fraction_non_alphanumeric': 0.11887477313974591, 'fraction_numerical': 0.0013611615245009074, 'mean_word_length': 5.391304347826087, 'pattern_counts': {'":': 0, '<': 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': '4518526', 'n_tokens_mistral': 683, 'n_tokens_neox': 656, 'n_words': 265}