Script investigating, extra eyes needed

Wednesday, April 11, 2012 by LizMarr | Discussion: DesktopX

I'm exploring the scripts for my favorite Windows gadget wondering if I can port it to DesktopX (plus I really want to change some variables) I've found a select call for the drop-down box where you choose what magnitude you want, but I be darned I cannot find the actual bit where it pulls the data from the web using the selected data. I've looked through 15 files for hours. XML, HTML, JS, CSS. I cannot figure out what I am looking for nor finding it. Here is the starting call, I can link the rest of the files if anyone wants to practice their code analysis.

    <select id="data" style="width:196;font-size:12px;">
    <option value="1">Magnitude 0+ (Past Day)</option>
    <option value="2">Magnitude 2+ (Past 7 Day)</option>
    <option value="3">Magnitude 3+ (Past 7 Day)</option>
    <option value="4">Magnitude 5+ (Past 7 Day)</option>
    <option value="5">Magnitude 7+ (Past 7 Day)</option>
    </select>

The original numbers were 0+,1+(Past Day),2.5+,5+,7+ There has to be some place that is feeding two variables into the gadget (magnitude and number of days). It has become more a learning experience than simply changing 2.5+ to 3+.

I don't intend to use the code for anything but my own. I want to figure out how it draws information from USGS and then make my own code. Probably some available variables that I would use besides what he has. I just want to understand how this is used to set the size and period. Right now I have it populating the drop down, but that is no good.

I know that USGS probably publishes a SDK. I find that trying to understand those things just makes me frustrated and I quit. For me it is easier to see how it is used then investigate how it works from there.

 

First Previous Page 1 of 2 Next Last
Skarny
Reply #1 Thursday, April 12, 2012 4:03 AM

Which gadget? What is USGS? What does the gadget do?

If it's a Microsoft gadget I believe they have functions built into a dll which are called to retrieve information.

LizMarr
Reply #2 Thursday, April 12, 2012 4:32 AM

It displays earthquake data from the USGS. Just a little column whose data rolls down as it is updated. Twice now I have learned about earthquakes before the news agencies have (like today) They need one of these. It is a Microsoft Sidebar gadget that is still supported by its creator (who has several gadgets) I'd like simply to chage the variables. I already know how to change the width and font and such. I'd really like to learn the API so I can make my own - using DesktopX.  I can't see the API call either in this thing.

http://addgadget.com/earthquakes_meter/

 

Skarny
Reply #3 Thursday, April 12, 2012 4:49 AM

I'd hazard a guess that he's tapping into the RSS Atom feeds listed on this page: http://earthquake.usgs.gov/earthquakes/catalogs/

It looks like the feeds are already grouped into the days and magnitude categories.

I assume that the list 'expands' if there are earthquakes in each magnitude category e.g. right now there are only 0, 1, and 2.5 groups for the 'past day', but if a 7 occurs suddenly there would be a new 7+ listing for 'past hour' and eventually 'past day'.

Because the atom feeds are 'filename based' - you could poll for each possible xml file, each hour, and update a gadget or whatever accordingly. There is no way to know what files (and therefore what magnitudes and periods) exist until you ask the server for them.

 

*edit* Actually http://earthquake.usgs.gov/earthquakes/feed/ seems a better choice as it just has a 'All earthquakes' feed for each period.

You could then filter the data according to your desired magnitude.

*edit* I might also say that the gadget maker says it provides alerts within a minute - I think that might not always be correct as the feed source website states that for international alerts it can be up to 30 minutes.

LizMarr
Reply #4 Thursday, April 12, 2012 5:42 AM

I didn't think of that when I was looking. I saw there was daily, weekly, and thirty day groupings and some variety of strengths. I wonder if the 1,2,3 etc match up to those feeds. I was looking a bit at that Atom feed that they replaced RSS with. I was just getting used to RSS...

So I guess at first I'm going to be limited by the existing sets and create a format I like better. The interface on the current one is too narrow, too scrunched up, and I would like the ability to scroll back.  I wonder if a person could add some more of those data sets? Like have 8 of them rather than just five. I think I shall change 1-5 to mix it up a little and see what I get. I still don't see where it is using that call to get the data. More looking I guess.

 

Uvah
Reply #5 Thursday, April 12, 2012 5:51 AM

Now this is a gadget worth having. I usually resort to hitting up the USGS and get an image that shows the location and magnitude of earthquakes but the red dots are all over the place. It lists all of the quakes, major and minor, for a given period. An RSS feed is just what I need.

LizMarr
Reply #6 Thursday, April 12, 2012 5:56 AM

I have the gadget that is just the map too, but I like my IRIS bookmark better. With it you can gently click the little ring you want and have the data show up, and then use the "last thirty days" option to get some good data to play with. If I ever teach an Excel class again I'm going to give them weather or earthquake data to learn with. The hardest part about teaching Excel is to get enough interesting data to really play with the features with.

 

Uvah
Reply #7 Thursday, April 12, 2012 6:28 AM

So many toys.....so little time. Oh well

mystifeid
Reply #8 Thursday, April 12, 2012 6:28 AM

It seems he has gone to some trouble to prevent exactly what you are trying to do (but I could be wrong and you could try emailing him).

If you cannot find what you are looking for then modifying this gadget's scripts may involve a steep learning curve.

I would encourage you to make your own gadget. Use search to find examples from which to learn.

But if you really must look at his scripts then you will have to use something like the Web Developer extension in Firefox.

Open the relevant html file in Firefox and then from the Web Developer toolbar select "Information" and then from the drop down list click on "View Javascript" and all scripts loaded by the html file will be displayed in a new tab/page. Copy everything and paste into your editor. There will be quite a lot of white space...

mystifeid
Reply #9 Thursday, April 12, 2012 9:18 AM

Oh, btw, I would like to change the Windowblinds UI...perhaps you could be of assistance in decompiling the exe for me and sending me the source...

LizMarr
Reply #10 Thursday, April 12, 2012 1:12 PM

I am trying to wean from Windows Sidebar. The thing is a memory hog and this is the only gadget I really care about. The rest I use are weather ones and I can survive with the available ones even though they do not have all the data I like to have at my fingertips (and use less than my favorite provider) I will investigate eventually to see if I can get the data and provider I want with the weather gadget because it does have good documentation.  As for the earthquake gadget, I really want to learn how those calls work. The color and window size are easy to figure out, but the key one is not. At first I thought that it refers to data on his web site, but I can't find that call either. The USGS site doesn't seem to have anything resembling a SDK and I'm not knowledgeable enough to translate web pages to desktop use.  It's OK, I'll figure something out.

Skarny
Reply #11 Thursday, April 12, 2012 10:00 PM

You don't need a "SDK". Just set a timer to load the ATOM files (which are XML) feeds every so many minutes and then parse them into a display.

Look into MSXML vbscript examples on the web - you'll learn how to create an 'in memory' XML object - load in an external xml file (like the ATOM files) and then read information from them.

I can probably give you a hand if noone else wants to jump in - but I'm a bit busy with a house move at the moment.

First step is to set up an object which retrieves the atom file, and then set a DX Text object to display the contents - it'll all be xml code, but you have a basic proof of concept - then work on manipulating the atom file to only put the information you want into the DX Text object.

Parsing is where you face the most programming - pulling the information out that you want without all the XML code tags - this is where learning about MSXML object in vbscript will come into play.

RedneckDude
Reply #12 Thursday, April 12, 2012 10:17 PM

ok....

LizMarr
Reply #13 Thursday, April 12, 2012 10:28 PM

I'm glad I am not hurrying. But it sure sounds like fun. I should have something I like by fall I think

Don't worry about helping me until I've messed myself up thoroughly. I estimate that to be about May as it will be a side line of a couple other projects.

mystifeid
Reply #14 Friday, April 13, 2012 3:56 AM

You can look at an example of how to download and parse an xml file with jscript here :

http://social.msdn.microsoft.com/Forums/en/sidebargadfetdevelopment/thread/5c313c0e-0a3e-4cf6-9e4e-e0d701a834d6

Uvah
Reply #15 Friday, April 13, 2012 5:45 AM

That looks very complicated.

mystifeid
Reply #16 Friday, April 13, 2012 6:50 AM

Well, it's about as basic as I know how to make it - and apart from the gadget.xml file (which is fairly generic) it is a complete working gadget. Still if anyone can provide that OP with an easier or less complicated working solution it would make me very happy. Him too, I suppose.

LizMarr
Reply #17 Friday, April 13, 2012 7:12 AM

I gotta find my pencil and print that out. My mind is running in circles trying to keep track of all the small things. Sure looks like fun! Thanks. Funny how you were listening to two very similar threads in two forums.

 

mystifeid
Reply #18 Friday, April 13, 2012 9:19 AM

It is fun but if you have never made a gadget before, please consider following the advice in this thread

Gadget Newbie

and start by making a "Hello World" gadget. The thread also contains a few other useful links but please note that these do not cover the properties and methods of the IXMLDOMDocument and IXMLHTTPRequest objects (which besides script examples also contain code examples.)

There are also many other links possible to give for jscript. Think of it as a superset of javascript. A very big one. Also, if you can write jscript you will have little trouble learning how to write vbscript (and vice-versa).

LizMarr
Reply #19 Friday, April 13, 2012 2:07 PM

Any suggestions on something to read about using that select command for outside data? I have used similar before as it has for colors and such. I still want to learn the one above.

mystifeid
Reply #20 Friday, April 13, 2012 7:06 PM

What you have above is just an HTML element or object - a way of adding a drop down list to the page.

There are no commands.

But a select object can be manipulated through script via it's properties, methods and events.

You can change or read it's displayed value for example with the value property.

The "Gadget Newbie thread" mentioned above contains this link :

HTML and DHTML reference

which in turn includes these links :

DHTML Objects

(you will find the select link on this page)

DHTML Properties

DHTML Methods

DHTML Events

I assumed that you already knew how to write HTML/CSS (ie can make a web page) which is a necessary skill for making gadgets but if this is not the case then you should perhaps start elsewhere - for example :

Search for How to write HTML

bearing in mind that with gadgets you are writing your pages for one client/browser only.

There is a lot you can learn about this stuff and not too many shortcuts which is why I would suggest starting at the beginning.

Knowing how to make a gadget that downloads and parses an xml file with a script I would put more towards the advanced side of things.

(Likewise the first gadget I tried to make was a network gadget which was a very bad choice - I ended up rewriting it five times from scratch over five months before I published it. And I was pretty handy with HTML/CSS before I started.)

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01