Door Games Unlimited

Welcome, Guest.


Subject: Re: Synchronet Javascript and reading XML Date: Fri Jul 29 2016 16:49:55
From: KenDB3 To: echicken

 > There's already some code for dealing with this exact feed, but it's
 > embedded in an IRC bot.  You might be able to find something useful in:
 > '/exec/ircbots/ham/ham.js', however this should work:

 > load('http.js');
 > try {
 >   var solardata = new XML(
 >     (new HTTPRequest()).Get(
 >       'http://www.hamqsl.com/solarxml.php'
 >     ).replace(
 >       /<\?[^?]*\?>/g, ''
 >     )
 >   ).solardata;
 > } catch (err) {
 >   log('Shit done borked! ' + err);
 > }

 > (See https://bbs.electronicchicken.com/temp/solar.txt if that didn't come
 > through okay.)

 > You should then be able to get at the values from the feed like so:

 > print(solardata.sunspots);
 > print(solardata.solarwind);

 > And so on.

 > The IRC bot code mentioned above has examples of how to deal with the nested
 > 'calculated(vhf)conditions' values, which gets deeper into E4X than I care
 > to do right now.


EC, I have another question (or anyone that feels they can answer).

I notice in the IRC bot code that you can get banned for hitting the web page
too often. 

Would there be a way to bring in the XML data without an HTTPRequest from a
local file? Say something I saved from the last successful pull from the live
file and defined as:
var localfile = js.exec_dir + "solar.php";
where solar.php was saved from a previous lookup less than an hour ago?

My awful attempt to do this currently looks like this:

if((time() - last_solar_update) > 60*60) {
        try {
          var solardata = new XML(
                (new HTTPRequest()).Get(
                  'http://bbs.kd3.us/sol/solarxml.php.xml'
                ).replace(
                  /<\?[^?]*\?>/g, ''
                )
          ).solardata;
        } catch (err) {
          log('Shit done borked! ' + err);
        }
} else {
        try {
        var localfile = js.exec_dir + "solar.php";
        var localPHPfile = new File(localfile);
        localPHPfile.open("r");             // open file with read access
        var localXMLfile = localPHPfile.readAll();
        var fixedXMLfile = localXMLfile.replace(
                  /<\?[^?]*\?>/g, ''
                  );
        var solardata = new XML(
                fixedXMLfile.solardata);
        } catch (err) {
          log('Shit done borked! ' + err);
        }
        localPHPfile.close();
}

Also, if this is simply a crazy thing to try and do, feel free to let me know.
localXMLfile keeps coming back as null and I'm not sure where I've gone wrong
anymore. 

~KenDB3

---
 ■ Synchronet ■ KD3net-Rhode Island's only BBS about nothing. http://bbs.kd3.us

Previous Message       Next Message
In Reply To: Synchronet Javascript and reading XML (echicken)
Replies: Re: Synchronet Javascript and reading XML (echicken)