Hi all. I am very new to using Python Notebooks in ArcGIS Pro. I am trying to fill one row of a table in ArcGIS Pro with data that I extracted from the USGS website (using their Web Service URL Generation tool). I have been able to request the data from the url, but am running into issues when it comes to adding it into the table within my geodatabase. The current field type I have for the field "date_time" is "DATE", so I am not sure what is going wrong.
The error I get after running the last line of code is: "RuntimeError: The value type is incompatible with the field type [date_time]."
Any advice or suggestions would be appreciated!
#create a new table
#set arcpy workspace to your geodatabase
arcpy.env.workspace="C:\\My GIS Projects\\Lake Levels USGS\\Lake Levels USGS.gdb"
#set variable outpath
outpath=arcpy.env.workspace
#create new, empty table
arcpy.CreateTable_management(outpath, "Riffe_Lake_Level")
#create fields in empty table
arcpy.AddField_management("Riffe_Lake_Level", "site_name", "STRING")
arcpy.AddField_management("Riffe_Lake_Level", "date_time", "DATE")
arcpy.AddField_management("Riffe_Lake_Level", "station_id", "LONG")
arcpy.AddField_management("Riffe_Lake_Level", "agency_code", "STRING")
arcpy.AddField_management("Riffe_Lake_Level", "waterelev", "DOUBLE")
#use first table as a template for a second table
arcpy.CreateTable_management(outpath, "Alder_Lake_Level", "Riffe_Lake_Level")
#edit table to allow editing of field values
editrows = arcpy.da.InsertCursor("Riffe_Lake_Level", ["site_name", "date_time", "station_id", "agency_code", "waterelev"])
editrows.fields
#import USGS water elevation data
import urllib.parse
import urllib.request
import json
import requests
usgs_water_api = "https://waterservices.usgs.gov/nwis/dv/?format=json&sites=14234800&siteStatus=all"
api_response = requests.get(usgs_water_api)
water_data = api_response.json()
#define values for fields
for i in data:
site_name = water_data["value"]["timeSeries"][0]["sourceInfo"]["siteName"]
date_time = water_data["value"]["timeSeries"][0]["values"][0]["value"][0]["dateTime"]
station_id = water_data["value"]["timeSeries"][0]["sourceInfo"]["siteCode"][0]["value"]
agency_code = water_data["value"]["timeSeries"][0]["sourceInfo"]["siteCode"][0]["agencyCode"]
waterelev = water_data["value"]["timeSeries"][0]["values"][0]["value"][0]["value"]
row = [site_name, date_time, station_id, agency_code, waterelev]
print(row)
#populate row in data table
editrows.insertRow(row)