Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

Help with widget.system and curl

Author Message
draino



Joined: 26 Apr 2005
Posts: 11

Posted: Tue Apr 26, 2005 - 5:58 pm    Post subject: Help with widget.system and curl Reply with quote

I've done a couple of very very very basic Konfabulator widgets and now I'm trying to reproduce my work with Dashboard.. I'm still learning javascript, so bear with me.. this is probably a stupid mistake, but I can't figure it out. =)

Basicly, I have two text fields.. one for input, one for output. I think the HTML is fine, I'm just not sure about the javascript..basicly, it's not working.. nothing is showing up in the output text field. The widget is supposed to take a stock symbol like "rhat", feed it in with the url to curl ( curl grabs webpages ). the collected variable should hold the entire webpage. Then the current.value updates the HTML with the matched pattern. I want it to run right on startup.

The Javascript
Code:


function setup()
{
   var url = "http://finance.yahoo.com/q?s=" + document.getElementById("tickersymbol").value;
   var price = /<td class="yfnc_tabledata1"><big><b>([0-9]{0,4}[.][0-9]{0,2})<\/b>/;
   var collected = widget.system("curl -A \"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\" \"" + url + "\"", null).outputString;
   document.getElementById("current").value = "$" + collected.match(price)[1];
}


The HTML
Code:

<body onload='setup();'>

   <!-- the widget background -->
   <img src="Default.png">        
   <span class="input">Symbol:</span>
   <input type="text" value="intl" id="stockticker"></textarea>
   <span class="output">Price:</span>
   <input class="output" type="text" id="current" value=""></textarea>
</body>


Any idea's?
View user's profile Send private message Send e-mail Widgets
avnit



Joined: 25 Apr 2005
Posts: 23

Posted: Tue Apr 26, 2005 - 11:11 pm    Post subject: Reply with quote

Yeah, you need to use document.getElementById('id').innerHTML

not .value

.value is only for form input objects.

Hope this helps.
View user's profile Send private message Send e-mail Visit poster's website Widgets
draino



Joined: 26 Apr 2005
Posts: 11

Posted: Tue Apr 26, 2005 - 11:29 pm    Post subject: Reply with quote

avnit wrote:
Yeah, you need to use document.getElementById('id').innerHTML

not .value

.value is only for form input objects.

Hope this helps.


These are form input objects for now.. So I believe I had that part correct. I tried it your way anyways and it still didn't work. In my Safari javascript console I am getting "Null Value: undefined" line 0.. unfortunately, as far as I know there is no logging ( yet ).. for the real dashboards, so I can't tell if my widget.system call is working or not.
View user's profile Send private message Send e-mail Widgets
avnit



Joined: 25 Apr 2005
Posts: 23

Posted: Tue Apr 26, 2005 - 11:44 pm    Post subject: Reply with quote

Ah... you can just try some random terminal command to see of widget.system is working.....
View user's profile Send private message Send e-mail Visit poster's website Widgets
sean



Joined: 22 Apr 2005
Posts: 67
Location: Duluth, MN

Posted: Wed Apr 27, 2005 - 10:21 am    Post subject: Reply with quote

What about using an XMLHttpRequest() from javascript, rather than curl? I haven't tried using system calls yet, but I think I remember someone mentioning that there was a bit of lag involved with them anyway... not sure.

Code:

req = new XMLHttpRequest();
var url = "http://finance.yahoo.com/q?s=" + document.getElementById("tickersymbol").value;
req.open("GET", url ,false);
req.send(null);
var string = req.responseText;
View user's profile Send private message Send e-mail Visit poster's website Widgets
draino



Joined: 26 Apr 2005
Posts: 11

Posted: Wed Apr 27, 2005 - 10:51 am    Post subject: Reply with quote

sean wrote:
What about using an XMLHttpRequest() from javascript, rather than curl? I haven't tried using system calls yet, but I think I remember someone mentioning that there was a bit of lag involved with them anyway... not sure.

Code:

req = new XMLHttpRequest();
var url = "http://finance.yahoo.com/q?s=" + document.getElementById("tickersymbol").value;
req.open("GET", url ,false);
req.send(null);
var string = req.responseText;


I'm going to give that a shot when I get home later today.. I was looking through some other peoples code and noticed everyone doing this instead of using curl.. I guess it's the best way, but not the easiest. I wasn't familiar with how to use XMLHttpRequest, but after seeing your example it doesn't look *too* hard. Thanks.
View user's profile Send private message Send e-mail Widgets
avnit



Joined: 25 Apr 2005
Posts: 23

Posted: Wed Apr 27, 2005 - 5:33 pm    Post subject: Reply with quote

Dosn't xmlhttpresponse only work to request a page from a local machine? I've tried xmlhttpresponse many times with normal HTML (not dashboard) and it always says I don't have permission to access the external server I am requesting. Furthermore, on the safari faq page it says that you cannot access external servers with xmlhttpresponse.

Did apple somehow allow xmlhttpresponse on external servers with dashboard, but still not allow it with normal safari?

Confused. Sad
View user's profile Send private message Send e-mail Visit poster's website Widgets
draino



Joined: 26 Apr 2005
Posts: 11

Posted: Wed Apr 27, 2005 - 11:25 pm    Post subject: Reply with quote

hrmm.. must still be something wrong. Not working with the XMLhttpRequest either..

Code:

function setup()
{
var req = new XMLHttpRequest();
var url = "http://finance.yahoo.com/q?s=" + document.getElementById("tickersymbol").value;
var price = '/<td class="yfnc_tabledata1"><big><b>([0-9]{0,4}[.][0-9]{0,2})<\/b>/';
req.open("GET", url ,false);
req.send(null);
var collected = req.responseText;
document.getElementById("current").value = collected.match(price)[1];


I even tried it without the pattern matching, hoping that it would atleast display the first line of the HTML it picked up in the textbox, but thats not happening either. Any other idea's?
View user's profile Send private message Send e-mail Widgets
sean



Joined: 22 Apr 2005
Posts: 67
Location: Duluth, MN

Posted: Thu Apr 28, 2005 - 11:59 am    Post subject: Reply with quote

avnit wrote:
Dosn't xmlhttpresponse only work to request a page from a local machine? I've tried xmlhttpresponse many times with normal HTML (not dashboard) and it always says I don't have permission to access the external server I am requesting. Furthermore, on the safari faq page it says that you cannot access external servers with xmlhttpresponse.

Did apple somehow allow xmlhttpresponse on external servers with dashboard, but still not allow it with normal safari?

Confused. Sad


I'm using it quite successfully with my wikipedia widget pulling pages from wikipedia.org in both the dashboard and in Safari. Apple's phone book widget (and probably others) also use it to pull results from the web.
View user's profile Send private message Send e-mail Visit poster's website Widgets
sean



Joined: 22 Apr 2005
Posts: 67
Location: Duluth, MN

Posted: Thu Apr 28, 2005 - 12:32 pm    Post subject: Reply with quote

draino wrote:
I even tried it without the pattern matching, hoping that it would atleast display the first line of the HTML it picked up in the textbox, but thats not happening either. Any other idea's?


Pulling the page from yahoo works fine for me, here's what I did:
Code:
req = new XMLHttpRequest();
url = "http://finance.yahoo.com/q?s=AAPL";
req.open("GET", url ,false);
req.send(null);

response = req.responseText;
document.getElementById('content').innerHTML = response;

and in the HTML, there's: <div id="content"></div>[/code]
View user's profile Send private message Send e-mail Visit poster's website Widgets
afunsten



Joined: 02 May 2005
Posts: 1
Location: sunnyvale

Posted: Mon May 02, 2005 - 10:21 pm    Post subject: Might have your answer Reply with quote

I'm a newbie but my widget.system is finally working for me after of about 12 hours of searching.

I think it's all because I didn't put one little / at the end when calling my js, weird the js alerts worked anyway Safari.

example:
<script type='text/javascript' src='Adams.js' />
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group