def insert_lines(line_fc, list_lines, fields_for_lines, is_del, writer):
    counter = 0
    with arcpy.da.InsertCursor(line_fc, tuple(fields_for_lines)) as iCursor:
        for line in list_lines:
            corrected_company = cobb_common.extract_vendor(line[1][0][3], line[1][0][2])
            array = arcpy.Array()
            array.add(arcpy.Point(line[0][0][0], line[0][0][1], line[0][0][2]))
            array.add(arcpy.Point(line[0][1][0], line[0][1][1], line[0][1][2]))
            row = (line[3],  # Footage
                   None,  # OID
                   corrected_company,  # Vendor
                   line[1][0][-3],  # Facility Type
                   'PyGin',  # Algo version
                   None,  # Equipment
                   line[1][0][5] if is_del else line[1][0][6],  # Report Date
                   line[1][0][7],  # Job File Name
                   line[1][0][8],  # Job Order Number
                   line[1][0][9],  # Operator Name
                   line[1][0][10],  # Collection Type
                   line[1][0][11],  # Collection Date
                   line[0][2],  # Aban Indic
                   arcpy.Polyline(array, None, True)
                   )
            iCursor.insertRow(row)
            writer.writerow((line[1][0][8],
                             corrected_company,
                             line[1][0][7],
                             line[1][0][11],
                             line[1][0][-3],
                             line[3])
                            )
            counter += 1
    return counter
line_fcs = ['GPS_GasMain_Line_Delivered',
            'GPS_ServiceLine_G_Line_Delivered',
            'GPS_GasMain_Line_Approved',
            'GPS_ServiceLine_G_Line_Approved',
            ]
c_file = open('{}_Cobb0_Footages.csv'.format(datetime.datetime.now().strftime("%m%d")), 'wb')
c_writer = csv.writer(c_file, quoting=csv.QUOTE_NONNUMERIC, dialect='excel')

heading = ('State', 'Vendor', 'Main Del', 'Service Del',
           'Main App', 'Service App', 'End Date')
c_writer.writerow(heading)

for current_state in states:
    dest_env_folder = 'E:/Cobbler/GDB/'
    dest_env_db = "{}_Cobbler_Dot1.gdb".format(current_state[0])
    # dest_env_db = "{}_Cobbler_0815.gdb".format(current_state)
    arcpy.env.workspace = dest_env_folder + dest_env_db

    vendors = cobb_common.build_vendor_list(line_fcs)

    start, end, boy, bot = cobb_common.satandsun(datetime.date.today())

    calc_feet(current_state, bot, end, line_fcs, vendors, c_writer)

    # for day in cobb_common.datespan(datetime.date(2016, 1, 2), datetime.date.today(), delta=datetime.timedelta(days=7)):
    #     # start = day - datetime.timedelta(days=6)
    #     # print current_state, start.isoformat(), day.isoformat()
    #     calc_feet(current_state, bot, day.isoformat(), line_fcs, vendors, c_writer)

c_file.close()
def make(state_name, spatial_reference):
    dest_env_folder = 'E:/Cobbler/GDB/'
    dest_env_db = "{}_Cobbler_Dot1.gdb".format(state_name)
    dest_env = dest_env_folder + dest_env_db

    fcs = [
        ('GPS_GasMain_Line_Delivered', 'GPS Gas Main Line Delivered'),
        ('GPS_ServiceLine_G_Line_Delivered', 'GPS Gas Service Line Delivered'),
        ('GPS_GasMain_Line_Approved', 'GPS Gas Main Line Approved'),
        ('GPS_ServiceLine_G_Line_Approved', 'GPS Gas Service Line Approved')
    ]

    arcpy.CreateFileGDB_management(dest_env_folder, dest_env_db)
    arcpy.env.workspace = dest_env

    # create feature class
    for fc_pair in fcs:
        fc = fc_pair[0]
        safe_add_feature_class(dest_env, fc, 'POLYLINE', None, 'DISABLED', 'ENABLED', spatial_reference)
        arcpy.AlterAliasName(fc, fc_pair[1])

        # add global id
        arcpy.AddGlobalIDs_management(fc)

        # add fields
        field_names = [f.name for f in arcpy.ListFields(fc)]
        safe_add_field(fc, "FOOTAGE3D", "DOUBLE", 32, 2, "", "3D Footage", None, None, None, field_names)
        safe_add_field(fc, "GPS_POINTCOLLECTIONDATE", "DATE", "", "", "", "GPS Point Collection Date", None, None, None,
                       field_names)
        safe_add_field(fc, "COLLECTIONTYPE", "LONG", 10, 0, "", "Collection Type Category", None, None,
                       'GPS_Collection_Type',
                       field_names)
        safe_add_field(fc, "FACILITYTYPE", "TEXT", "", "", 50, "Facility Type", None, None, None,
                       field_names)
        safe_add_field(fc, "GPS_OPERATORCOMPANY", "TEXT", "", "", 30, "GPS Collector Company", None, None, None,
                       field_names)
        safe_add_field(fc, "GPS_OPERATORNAME", "TEXT", "", "", 20, "GPS Operator Name", None, None, None, field_names)
        safe_add_field(fc, "GPS_JOBORDERNUMBER", "TEXT", "", "", 9, "GPS Job Order Number", None, None, None,
                       field_names)
        safe_add_field(fc, "JOB_FILENAME", "TEXT", "", "", 50, "Job File Name", None, None, None, field_names)
        safe_add_field(fc, "REPORT_DATE", "DATE", "", "", "", "Date Used for Reporting", None, None, None, field_names)
        safe_add_field(fc, "CREATIONUSER", "TEXT", "", "", 20, "Creation User", None, None, None, field_names)
        safe_add_field(fc, "DATECREATED", "DATE", "", "", "", "Date Created", None, None, None, field_names)
        safe_add_field(fc, "DATEMODIFIED", "DATE", "", "", "", "Date Modified", None, None, None, field_names)
        safe_add_field(fc, "LASTUSER", "TEXT", "", "", 20, "Last User", None, None, None, field_names)
        safe_add_field(fc, "ALGORITHM_VERSION", "TEXT", "", "", 15, "Algorithm Version", None, None, None, field_names)
        safe_add_field(fc, "GISID", "LONG", 10, 0, "", "GISID", None, None, None, field_names)
        safe_add_field(fc, "EQUIPMENT", "TEXT", "", "", 20, "Equipment", None, None, None, field_names)
        safe_add_field(fc, "ABANDON_INDICATOR", "TEXT", "", "", 5, "Abandoned Indicator", None, None,
                       'Yes_No Indicator_G',
                       field_names)
        safe_add_field(fc, "MXASSETUID", "DOUBLE", 12, 0, "", "Maximo Asset Unique ID", None, None, None, field_names)
        safe_add_field(fc, "MXASSETNUM", "TEXT", "", "", 20, "Maximo Asset Number", None, None, None, field_names)
        safe_add_field(fc, "MXCREATIONSTATE", "SHORT", 5, 0, "", "Maximo Creation State", None, None, None, field_names)
        safe_add_field(fc, "WORKREQUESTID", "TEXT", "", "", 20, "Work Request ID", None, None, None, field_names)
        safe_add_field(fc, "DESIGNID", "TEXT", "", "", 20, "Design ID", None, None, None, field_names)
        safe_add_field(fc, "WORKLOCATIONID", "TEXT", "", "", 20, "Work Location ID", None, None, None, field_names)
        safe_add_field(fc, "WORKFLOWSTATUS", "SHORT", 10, 0, "", "Work Flow Status", None, None, 'MM Work Flow Status',
                       field_names)
        safe_add_field(fc, "WORKFUNCTION", "SHORT", 10, 0, "", "Work Function", None, None, None, field_names)

        cobb_common.add_index(fc, ["JOB_FILENAME"])

        arcpy.EnableEditorTracking_management(fc, "CREATIONUSER", "DATECREATED", "LASTUSER", "DATEMODIFIED",
                                              "ADD_FIELDS",
                                              "UTC")