Award
Congratulations WBS00001, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Reading Through An Rss File To Get Specific Data

Assistance Requested

Help dbeard with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

dbeard claims to have checked these sources:
 
#61

Do you mean the code? Via email?

#62

nea.zip

Dj. There are 3 files. 1 is the script. the 2 other files must be placed in the directory public documents and folder test on the c drive.

This script runs with the older version of Ezbuilder but not the new. Something with either FileWrite or HTTPGet might be affecting it.

Run this on a pc with the older version and then try on a pc with the newer version.

Please let me know if you need more info.

#63

And any suggestions for script improvement would be appreciated. Grin

#64

I see what happened - i'll post an update today for you

#65

Use the latest EZ-Builder and your code will work without needing to strip any characters. I modified your EZ-Script a little...

Code:


clearvariables()

$VZFile ="C:\temp\test.txt"

FileReadClose($VZFile)

$todaydate=($year + "-" + $month + "-" + $day)
$ready=0
$thenumber=1
$sortcounter=0
$arraycounter=0
$hazard=0

definearray($aname,20,"")
definearray($amag,20,"")
definearray($adiamin,20,"")
definearray($adiamax,20,"")
definearray($ahaz,20,"")
definearray($aclosedate,20,"")
definearray($aMPH,20,"")
definearray($amiles,20,"")
definearray($abad,20,"")

$url1 = "https://api.nasa.gov/neo/rest/v1/feed?start_date="; + $todaydate + "&end_date=" + $todaydate + "&api_key=3jMUBZIcgvFXVAMouSZqlWnbjg5N1sPmgsHiEyCD"

if (FileExists($VZFile))
FileDelete($VZFile) #Clears the file and prevents adding to it needlessly
endif

FileWrite($VZFile,HTTPGet($url1))

$endOfFile = FileReadEnd($VZFile)

repeatuntil($endOfFile)

$line = FileReadLine($VZFile)

$field1 = Indexof($line,"name:")
$field2 = Indexof($line,"absolute_magnitude_h: ")
$field3 = IndexOf($line,"feet:")
$field4 = indexof($line,"is_potentially_hazardous_asteroid: ")
$field5 = indexof($line,"close_approach_date:")
$field6 = Indexof($line,"miles_per_hour:")
$field7 = indexof($line," miss_distance:")

if ($field1 > -1)
$field1a = Length($line)
$name = (substring($line,$field1+5,$field1a-7))
endif

if ($field2 > -1)
$field2a = Length($line)
$mag = (substring($line,$field2+22,$field2a-24))
endif

if ($field3 > -1)
$line = FileReadLine($VZFile)
$field3a = IndexOf($line,"estimated_diameter_min: ")
$diamin=(substring($line,$field3a+24,6))

$line = FileReadLine($VZFile)
$field3b = IndexOf($line,"estimated_diameter_max: ")
$diamax=(substring($line,$field3b+24,6))

endif

if ($field4 > -1)
$haz = substring($line,$field4+35,3)
endif

if ($field5 > -1)
$field5a = indexof($line," ,")
$closedate = substring($line,$field5+20,$field5a-21)

endif

if ($field6 > -1)

$MPH = substring($line,$field6+15,7)

endif

if ($field7 > -1)
$line = FileReadLine($VZFile)
$line = FileReadLine($VZFile)
$line = FileReadLine($VZFile)
$line = FileReadLine($VZFile)
$field7a = Length($line)
$miles = (substring($line,7,$field7a-8))
$ready = 1
$field7 = -1

# print($name)
# print($mag)
# print($diamin)
# print($diamax)
# print($haz)
# print($Closedate)
# print($MPH)
# print($miles)
# sleep(3000)
endif

if ($ready = 1 )

$arraycounter=$arraycounter+1
$aname[$arraycounter]=$name
$amag[$arraycounter]=$mag
$adiamin[$arraycounter]=$diamin
$adiamax[$arraycounter]=$diamax
$ahaz[$arraycounter]=$haz
if ($ahaz[$arraycounter] = "fal")
$hazard = $hazard
ELSE
$hazard = $hazard + 1
$abad[$arraycounter]=$name
endif
$aclosedate[$arraycounter]=$closedate
$aMPH[$arraycounter]=$MPH
$amiles[$arraycounter]=$miles

$ready=0

endif

$endOfFile = FileReadEnd($VZFile)

endrepeatuntil


filereadclose($VZFile)

repeatuntil($sortcounter = $arraycounter)

if ($amiles[$thenumber]< $amiles[$sortcounter+1])
$thenumber=$thenumber

ELSE
$thenumber=$sortcounter+1
endif
$sortcounter=$sortcounter+1
endrepeatuntil


if ($hazard = 0)
$hazardstatement =(" None of these encounters are rated as potentially hazardous.")
ELSE
$hazardstatement = ("with " + $hazard + " rated as potentially hazardou.")
endif

saywait(" There are " + $arraycounter + " Near Earth Asteroid Fly buys " + $hazardstatement)

if ($arrayCounter > 0)
saywait(" The asteroid designated" + $aname[$thenumber] + " will safely pass by earth at a distance of " + round($amiles[$thenumber]) + " Miles.")
saywait("It is estimated to be between " + round($adiamin[$thenumber]) + " feet and " + round($adiamax[$thenumber])+ " feet in diameter and, is traveling At a speed of " + (round($aMPH[$thenumber])) + " MPH.")
endif

#66

DJ. Did you actually get the script to work? I downloaded and installed the latest version of EzBuilder. Used your script and it downloads and writes the file, but cant find any info for today and I know there is. Am I doing something wrong?

#67

Ok, I see. I need to reparse through the data to find my values. Much work. I have probably 5 others I need to redo. I did get this one working though. Thanks.

#68

I'm a bit late to this party. Yea! the left paren issue has been resolved! Unfortunately there are other things commonly found in the strings which make up a web page which will cause problems and crashes so filtering will still be needed in other cases. For example quote marks, or LF and CR in cases in which the user wishes to take in the entire web page contents at once into a single variable.

If you look at the output file you will see that the search terms like name: and Absolute_magnitude_h: are now (without filtering) name : and absolute_magnitude_h : with a space before the colon which the filter program must have previously taken out. So you would need to change those search words, as well as the others, to include the space for it to work properly. That's why they are not being found currently.

EDIT: Ah, I see dbeard, you have found the problem while I was checking things out and creating this reply.

#69

WBS00001, are there other things your program was clearing out that is going to cause a problem? With the update your Scrub program no longer works.

I have got the script working after fixing a lot of the parsing. Smile

#70

@dbeard
In what way is the Scrub program not working?

The Scrub program does some pre-emptive character replacement in addition to the left paren removal. It also deletes double quotes and changes E to e. It gets rid of quotes because strings in the Scripts are bounded by them. So any in a string read from a web page will cause a crash or truncated string. This isn't a bug though, just a fact of life. Lower casing E prevents the problem when an uppercase E is followed directly by a number. The script interpreter will try to treat it as an E-notation value and crash in so doing. Also a backslash can sometimes cause problems so they are removed, as well as the semi-colon.

As your project currently stands it seems to be free from any of those problems, given the web page you are using.

I have a new version of the scrub program which is more versatile than what you are currently using should you be interested. It is used pretty much like you are using what you have now. Switching to it would not be too difficult. If you post your project to the cloud I could download it and modify it to use the new stuff, then upload it back.