def getDatafromWebService(self, region, station, start_date, end_date): """ This function is used to collect the data from National Oceanic and Atmospheric Administration :param stationcode: :param startdate: :param enddate: :return: """ #construct filename in the format "region_station_startdate_enddate.json" with no spaces and "-" filename = region + "_" + station + "_" + start_date + "_" + end_date + ".json" filename = filename.replace(" ", "") filename = filename.replace("-", "") print filename obj = RegionData() stationcode = obj.getStaionCode(region, station) server = SOAPpy.SOAPProxy( "http://cdmo.baruch.sc.edu/webservices2/requests.cfc?wsdl") stationcode = "pdbjewq" responsedata = server.exportAllParamsDateRangeXMLNew( stationcode, start_date, end_date, '*') # print responsedata pythonObject = SOAPpy.Types.simplify(responsedata) #jsonObject = json.dumps(pythonObject) #assert type(jsonObject) == str dataArray = pythonObject["returnData"][ "data"] # returns { [{...},{....},.....]} #print dataArray self.dataToJson(dataArray, filename) # store the data into a json file #store data into rawdata collection rawObj = RawData() rawObj.insertRawStationData(region, station, start_date, end_date, dataArray) return filename # return the json filename where data is stored
def getDatafromWebService(self,region, station, start_date, end_date): """ This function is used to collect the data from National Oceanic and Atmospheric Administration :param stationcode: :param startdate: :param enddate: :return: """ #construct filename in the format "region_station_startdate_enddate.json" with no spaces and "-" """ filename = region + "_" + station+ "_" + start_date + "_" + end_date + ".json" filename = filename.replace(" ","") filename = filename.replace("-","") print ("filename: "+filename) """ #date format for getting data from web service = yy/mm/dd obj = RegionData() stationcode = obj.getStaionCode(region, station) newStart_Date = datetime.datetime.strptime(start_date, "%m/%d/%Y").strftime("%Y-%m-%d") newEnd_Date = datetime.datetime.strptime(end_date, "%m/%d/%Y").strftime("%Y-%m-%d") server = SOAPpy.SOAPProxy("http://cdmo.baruch.sc.edu/webservices2/requests.cfc?wsdl") #stationcode="pdbjewq" responsedata = server.exportAllParamsDateRangeXMLNew(stationcode, newStart_Date, newEnd_Date,'*') #responsedata = server.exportAllParamsDateRangeXMLNew('pdbjewq','2014-12-30', '2014-12-31', '*') # print responsedata pythonObject = SOAPpy.Types.simplify(responsedata) #jsonObject = json.dumps(pythonObject) #assert type(jsonObject) == str dataArray = pythonObject["returnData"]["data"] # returns { [{...},{....},.....]} #data from webservice has date format mm/dd/yy = 12/31/2014 #print(dataArray) return json.dumps(dataArray) """