예제 #1
0
def parse_d3(lexemes):

	try:
		#JSON Return String
		return_json=""

		#Retrieve Downloaded Time
		download_time=assemble_dict_current_time();

		#Default Predicted Time
		found_date=False
		found_data=False

		#Parse Lexemes
		for ii in range(0,len(lexemes)):

			#Ignore Comments
			if(len(lexemes[ii])>0 and lexemes[ii][0].startswith("#")==False and lexemes[ii][0].startswith(":")==False):

				#Valid MD Row
				if(len(lexemes[ii])==6 and date_util.month_to_int(lexemes[ii][0])>0 and string_util.is_int(lexemes[ii][1])):

					#Found a Date
					found_date=True
					date=lexemes[ii]

				#Valid Time Row
				elif(len(lexemes[ii])==4 and found_date==True):

					#Convert Hours
					hours=date_util.hhdashhhut_to_hours(lexemes[ii][0])

					#Extract Data
					if(hours[0]>=0 and hours[1]>=0):

						#3 Days Per Row
						for jj in range(0,3):

							#Extract Predicted Time, Minute is -1
							predicted_time={};
							predicted_time["year"]=download_time["year"]
							predicted_time["month"]=date_util.month_to_int(date[jj*2])
							predicted_time["day"]=int(date[jj*2+1])
							predicted_time["hour"]=hours[0]
							predicted_time["minute"]=-1

							#Extract Predicted Kp
							kp=float(lexemes[ii][1+jj])

							#Test Predicted Date
							date_test=date_util.valid_date(predicted_time,ii+1)

							if(date_test[0]==False):
								return date_test

							#Invalid Kp
							kp_test=kp_util.valid_kp(kp,ii+1)

							if(kp_test[0]==False):
								return kp_test

							#Only Add Good Data
							if(kp>=0):
								return_json+=assemble_json_forecast(predicted_time,download_time,"d3",kp);
								return_json+="\t,\n"
								found_data=True

		#No Data Means Error
		if(found_data==False):
			return (False,"Did not find any data.")

		#Return Passed and the JSON Object
		return (True,return_json[:-2]+"\n")

	except Exception as e:
		return (False,str(e)[0:].capitalize()+".")
예제 #2
0
def parse_h1(lexemes):

	try:
		#JSON Return String
		return_json=""

		#Retrieve Downloaded Time
		download_time=assemble_dict_current_time();

		#Default Predicted Time
		found_date=False
		found_data=False

		#Parse Lexemes
		for ii in range(0,len(lexemes)):

			#Ignore Comments
			if(len(lexemes[ii])>0 and lexemes[ii][0].startswith("#")==False and lexemes[ii][0].startswith(":")==False):

				#Valid YMD Row
				if(len(lexemes[ii])==3 and string_util.is_int(lexemes[ii][0])):
					#Found a Date
					found_date=True

					#Extract Predicted YMD
					predicted_time={};
					predicted_time["year"]=int(lexemes[ii][0])
					predicted_time["month"]=date_util.month_to_int(lexemes[ii][1])
					predicted_time["day"]=int(lexemes[ii][2])
					predicted_time["hour"]=0;
					predicted_time["minute"]=0;

				#Valid Planetary Estimated Ap Row
				elif(found_date==True and len(lexemes[ii])==11 and lexemes[ii][0].startswith("Planetary")):

					#Go Through The 8 Three Hour Segments
					for jj in range(0,8):

						#Create 3 Entries Per Three Hour Segment
						for kk in range(0,3):

							#Extract Predicted Hour, Minute is -1
							predicted_time["hour"]=jj*3+kk
							predicted_time["minute"]=0

							#Extract Predicted Kp
							kp=float(lexemes[ii][3+jj])

							#Test Predicted Date
							date_test=date_util.valid_date(predicted_time,ii+1)

							if(date_test[0]==False):
								return date_test

							#Invalid Kp
							kp_test=kp_util.valid_kp(kp,ii+1)

							if(kp_test[0]==False):
								return kp_test

							#Only Add Good Data
							if(kp>=0):
								return_json+=assemble_json_forecast(predicted_time,download_time,"h1",kp);
								return_json+="\t,\n"
								found_data=True

		#No Data Means Error
		if(found_data==False):
			return (False,"Did not find any data.")

		#Return Passed and the JSON Object
		return (True,return_json[:-2]+"\n")

	except Exception as e:
		return (False,str(e)[0:].capitalize()+".")