You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just leaving this here in case we ever decide we need REST functionality in Python. The requests module is pretty straight forward and user-friendly, working example below using our standard rest user account:
importrequestsfromrequests.authimportHTTPBasicAuthimportcsvimportpandasaspd# authentication using rest un and pwbasic=HTTPBasicAuth('usernameXXX', 'passwordXXX')
# alternate method, retrieve a token# response = requests.get('http://deq1.bse.vt.edu:81/d.dh/restws/session/token/', auth=basic)# print('status code:', response.status_code)# token = response.content# print('token:', token) # note: b' at the start of output means it is a reference to a bytes object# get a remote csv using authentication, and convert to pandas dataframe:csv_url='http://deq1.bse.vt.edu:81/d.dh/precipitation-drought-timeseries-export'download=requests.get(csv_url, auth=basic)
decoded_content=download.content.decode('utf-8')
cr=csv.reader(decoded_content.splitlines(), delimiter=',')
cr_list=list(cr)
df=pd.DataFrame(cr_list[1:], columns=cr_list[0], dtype=int)
# retrieve varidpropdef_table=pd.read_csv('http://deq1.bse.vt.edu:81/d.dh/?q=vardefs.tsv/all/drought',sep='\t')
variable_row=propdef_table[propdef_table['varkey'].str.contains('drought_status_precip')]
varid=int(variable_row['varid'])
# setup paramsfeatureid=int(df['hydroid'][0])
pid=int(df['pid'][0])
PARAMS= {'featureid':featureid,
'varid':varid,
'pid':pid,
'entity_type':'dh_feature'}
# get a propertyprop=requests.get(url='http://deq1.bse.vt.edu:81/d.dh/dh_properties.json', params=PARAMS, auth=basic)
prop=prop.json() # return json objectprop=prop["list"][0] # access dict within listprint(prop)
print("propcode =", prop['propcode']) # access value using dict key
Just leaving this here in case we ever decide we need REST functionality in Python. The requests module is pretty straight forward and user-friendly, working example below using our standard rest user account:
@rburghol
The text was updated successfully, but these errors were encountered: