<commit_before># ---------------------------------------------------------------------------
# esri2open.py
# Created on: March 11, 2013
# Created by: <NAME>
# Federal Communications Commission
# exports the feature classes for any feature class to
# a csv file, JSON file or geoJSON file 
# also adding edits from sgillies and <NAME>
# updates include using the python json.dumps method and indentation issues
# edits made 3/19/2013
# ---------------------------------------------------------------------------

# Import system modules
import arcpy
from arcpy import env
import json
import sys, string, os, math


##set up arguments
#acquire arguments
theIF = sys.argv[1]  #the input Feature Class
theOF = sys.argv[2]  #the output folder (output file will have same prefix
                     #as the input feature class w/ extension for the 
                     #output file type
theOType = sys.argv[3]  #the output file type CSV or JSON or GeoJSON
theDelim = sys.argv[4] #the delimiter for the csv output selection

#global variables

##Function wrtiteCSV - for each row, writes out each field w/ a delimiter
##right now does not deal w/ geometry, blob, or rasters
##has one argument; the name of the output file
def wrtiteCSV(myOF):
    #go open up and read this table
    myFile = open(myOF, 'a')  #open the output file and append to it
    for row in arcpy.SearchCursor(theIF):  #use a search cursor for each row
        myStr = ""
        for myF in arcpy.ListFields(theIF):
             #if it is a string type field, then make sure it is utf-8 and has
             #no spaces before or after it
             if myF.type == "String":
                 myStr = myStr + \
                       str(row.getValue(myF.name).encode('utf-8')).strip()\
                          + theDelim
             #if it is a number type field, no need to quote it; keep it as a number
             if (myF.type == "Float") or (myF.type == "Double") or \
                      (myF.type == "Short") or (myF.type == "Integer") or \
                      (myF.type == "OID"):
                 myStr = myStr + str(row.getValue(myF.name)) + theDelim 
             #if it is a date field, make sure there are no spaces before/after
             #and quote it
             if (myF.type == "Date"):
                 myStr = myStr + str(row.getValue(myF.name)).strip() + theDelim
             #need to deal , blob, and raster
        myLen = len(myStr) - 1
        myStr = myStr[:myLen]
        myFile.write(myStr +  "\n")
    myFile.close()
    del myLen, myStr, myF, myFile, myOF
    del row
    return()


##Function wrtiteJSON - for each row, writes out a JSON Object
##right now does not deal w/ multi-part points
##has one argument;  the name of the output file 
def wrtiteJSON(myOF):
    #go open up and read this table
    myFile = open(myOF, 'a')
    cnt = 1 #used to determine the end of the rows
    #for each row in the feature class input
    for row in arcpy.SearchCursor(theIF):
        myFcnt = 1
        #the next line initializes the variable myGeomStr so that it is available
        #this code sets the geometry object for geoJson at the end of the line 
        #the attributes or properties
        myGeomStr = ""  
        myStr = '{"type": "Feature", "id": ' + str(cnt) + ', "properties": '
        
        # for each field in the feature class input
        properties = {}
        for myF in arcpy.ListFields(theIF):
            fCnt = int(len(arcpy.ListFields(theIF)))    
            #if you are a shape field, so something special w/ it
            if myF.name == "Shape": 
                if theOType == "GeoJSON": # avoid globals!
                    myField = "geometry"
                    myGeomStr = myGeomStr + writeGeom(row.getValue(myF.name)) + "}"
            
            else: #otherwise, just write up the attribues as "properties"<commit_msg>Fix issue with GeoJSON serialization not finding Shape field<commit_after># ---------------------------------------------------------------------------
# esri2open.py
# Created on: March 11, 2013
# Created by: <NAME>
# Federal Communications Commission
# exports the feature classes for any feature class to
# a csv file, JSON file or geoJSON file 
# also adding edits from sgillies and <NAME>
# updates include using the python json.dumps method and indentation issues
# edits made 3/19/2013
# ---------------------------------------------------------------------------

# Import system modules
import arcpy
from arcpy import env
import json
import sys, string, os, math


##set up arguments
#acquire arguments
theIF = sys.argv[1]  #the input Feature Class
theOF = sys.argv[2]  #the output folder (output file will have same prefix
                     #as the input feature class w/ extension for the 
                     #output file type
theOType = sys.argv[3]  #the output file type CSV or JSON or GeoJSON
theDelim = sys.argv[4] #the delimiter for the csv output selection

#global variables

##Function wrtiteCSV - for each row, writes out each field w/ a delimiter
##right now does not deal w/ geometry, blob, or rasters
##has one argument; the name of the output file
def wrtiteCSV(myOF):
    #go open up and read this table
    myFile = open(myOF, 'a')  #open the output file and append to it
    for row in arcpy.SearchCursor(theIF):  #use a search cursor for each row
        myStr = ""
        for myF in arcpy.ListFields(theIF):
             #if it is a string type field, then make sure it is utf-8 and has
             #no spaces before or after it
             if myF.type == "String":
                 myStr = myStr + \
                       str(row.getValue(myF.name).encode('utf-8')).strip()\
                          + theDelim
             #if it is a number type field, no need to quote it; keep it as a number
             if (myF.type == "Float") or (myF.type == "Double") or \
                      (myF.type == "Short") or (myF.type == "Integer") or \
                      (myF.type == "OID"):
                 myStr = myStr + str(row.getValue(myF.name)) + theDelim 
             #if it is a date field, make sure there are no spaces before/after
             #and quote it
             if (myF.type == "Date"):
                 myStr = myStr + str(row.getValue(myF.name)).strip() + theDelim
             #need to deal , blob, and raster
        myLen = len(myStr) - 1
        myStr = myStr[:myLen]
        myFile.write(myStr +  "\n")
    myFile.close()
    del myLen, myStr, myF, myFile, myOF
    del row
    return()


##Function wrtiteJSON - for each row, writes out a JSON Object
##right now does not deal w/ multi-part points
##has one argument;  the name of the output file 
def wrtiteJSON(myOF):
    #go open up and read this table
    myFile = open(myOF, 'a')
    cnt = 1 #used to determine the end of the rows
    #for each row in the feature class input
    for row in arcpy.SearchCursor(theIF):
        myFcnt = 1
        #the next line initializes the variable myGeomStr so that it is available
        #this code sets the geometry object for geoJson at the end of the line 
        #the attributes or properties
        myGeomStr = ""  
        myStr = '{"type": "Feature", "id": ' + str(cnt) + ', "properties": '
        
        # for each field in the feature class input
        properties = {}
        for myF in arcpy.ListFields(theIF):
            fCnt = int(len(arcpy.ListFields(theIF)))    
            #if you are a shape field, so something special w/ it
            if myF.name.lower() == "shape": 
                if theOType == "GeoJSON": # avoid globals!
                    myField = "geometry"
                    myGeomStr = myGeomStr + writeGeom(row.getValue(myF.name)) + "}"
            
            else: #otherwise, just write up the attribues as "properties"
{'fraction_non_alphanumeric': 0.12485563967663288, 'fraction_numerical': 0.005902733222122418, 'mean_word_length': 1.9169161676646707, 'pattern_counts': {'":': 12, '<': 7, '<?xml version=': 0, '>': 7, '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': '6456774', 'n_tokens_mistral': 2234, 'n_tokens_neox': 2155, 'n_words': 901}