I'm now pretty close on an OS X XP monitoring widget (hey, it was a great excuse to learn Javascript). It's working pretty well except for votes: when I check the XP ticker for myself in Safari, I see I have 9 votes, as expected. But when the widget fetches it, I get -1.

Any thoughts? Do I need to set the user agent?

Edit:
I had assumed that there might be a quick answer here - I see from all the downvotes that apparently I was wrong. Code later in the day after we've had Thanksgiving dinner.

Edit 2:
It's done (bar the voting -- see the rest of this thread for why). http://ibiblio.org/mcmahon/widgets/PerlmonksXP.wdgt.zip

Enjoy.

Replies are listed 'Best First'.
Re: PM XP OS X Widget
by chargrill (Parson) on Nov 25, 2006 at 22:46 UTC

    So, I was a little curious myself, so I did some poking around. In order to retrieve the 'private' information of how many votes a given user has left, you need to be logged in as that user. I was able to recreate the behavior described above using curl, a command line web user agent. All my testing uses the -v flag to generate verbose information.

    Before logging in:

    $ curl -v "http://perlmonks.org/?node_id=16046&for_user=chargrill" OUTPUT: * About to connect() to perlmonks.org port 80 * Trying 66.39.54.27... * connected * Connected to perlmonks.org (66.39.54.27) port 80 > GET /?node_id=16046&for_user=chargrill HTTP/1.1 User-Agent: curl/7.13.1 (powerpc-apple-darwin8.0) libcurl/7.13.1 OpenS +SL/0.9.7i zlib/1.2.3 Host: perlmonks.org Pragma: no-cache Accept: */* < HTTP/1.1 200 OK < Date: Sat, 25 Nov 2006 22:40:46 GMT < Server: Apache/1.3.29 < Transfer-Encoding: chunked < Content-Type: text/xml; charset=ISO-8859-1 <?xml version="1.0" encoding="ISO-8859-1"?> <XPINFO> <INFO site="http://perlmonks.org/" sitename="PerlMonks" style="" genti +meGMT="2006-11-25 22:40:46" min_poll_seconds="30" foruser="chargrill" + id="474411"> Rendered by the XP XML Ticker</INFO> <XP xp="4051" level="14" leveltitle="Priest" xp2nextlevel="1349" votes +left="-1"> </XP> </XPINFO> * Connection #0 to host perlmonks.org left intact * Closing connection #0

    Notice, the "votesleft="-1"". To get a cookie:

    $ curl -v -c ./curl.cookie "http://perlmonks.org/?" -d user=chargrill +-d \ passwd=MYPASSWORD -d expires=+10yrs -d login=Login -d op=login (OUTPUT TRIMMED)

    Using the cookie to check the ticker:

    $ curl -v -b curl.cookie "http://perlmonks.org/?node_id=16046&for_user +=chargrill" OUTPUT: * About to connect() to perlmonks.org port 80 * Trying 66.39.54.27... * connected * Connected to perlmonks.org (66.39.54.27) port 80 > GET /?node_id=16046&for_user=chargrill HTTP/1.1 User-Agent: curl/7.13.1 (powerpc-apple-darwin8.0) libcurl/7.13.1 OpenS +SL/0.9.7i zlib/1.2.3 Host: perlmonks.org Pragma: no-cache Accept: */* Cookie: userpass=HASHED_INFO_REMOVED < HTTP/1.1 200 OK < Date: Sat, 25 Nov 2006 22:44:38 GMT < Server: Apache/1.3.29 < Transfer-Encoding: chunked < Content-Type: text/xml; charset=ISO-8859-1 <?xml version="1.0" encoding="ISO-8859-1"?> <XPINFO> <INFO site="http://perlmonks.org/" sitename="PerlMonks" style="" genti +meGMT="2006-11-25 22:44:38" min_poll_seconds="30" foruser="chargrill" + id="474411"> Rendered by the XP XML Ticker</INFO> <XP xp="4051" level="14" leveltitle="Priest" xp2nextlevel="1349" votes +left="0"> </XP> </XPINFO> * Connection #0 to host perlmonks.org left intact * Closing connection #0

    Hope this helps :)



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
      Yes, it does. Thank you very much indeed.

      Originally, I had been getting accurate vote information because I had opened the widget in Safari to check the basic layout and XmlHttpRequest logic (both of which work in Safari); this of course meant that it had picked up the permanent cookie which I already had, so I got the votes. When I opened it in Dashboard to get the preferences and so on working (those need the widget object, which Safari doesn't support), it didn't have that cookie anymore, so poof, no votes.

      I figured this out this morning just after I woke up; I'm glad to see that my idea was correct.

      Now whether people are going to be comfortable with a widget asking them for their perlmonks password or not is another consideration altogether. At the moment, I've simply got logic in there that ignotes the votes if they come back as -1. The interface will need some reconsideration if I'm to add login as well.

      You are correct; the code is indeed all Javascript, and I refrained from posting it for that reason, figuring I'd just tick off yet another set of folks. For anyone who's actually still interested after all this, I'll probably have the widget-without-votes ready on Monday. It's all artistic tweaking after this point - mostly the icon.

        Version 1.0 of the widget is now available at href:http://ibiblio.org/mcmahon/widgets/PerlmonksXP.wdgt.zip - it skips the vote stuff for now (but entrprising monks who take a gander at the source code can see that it's ready for it as soon as I decide on a nice way to handle logging in vs. not logging in).

        I'll link this from my home page as well.

        It uses the XP ticker node (see What XML generators are currently available on PerlMonks?) to get the data. and shows you your current XP and title, the number of points to the next level, and and your up/down change since the widget was launched.

        It supports all the standard stuff: multiple instances (so you can watch mulitiple users if you feel like it), internationalization (patches welcome to translate the stirings into other lanfuages). It remembers your ID across restart/logout. It currently restarts the delta tracking on each login; I nay change this to be remembered as well.

        I'm planning on adding the voting soon. I'd also be interested in hearing suggestions for other widgets. It was quite a lot of fun; Javascript can be entertaining to write, at least in this quick-feedback environment.

        Edit:
        Now linked at the top of this thread as well.

Re: PM XP OS X Widget
by chargrill (Parson) on Nov 25, 2006 at 18:28 UTC

    Seems to me that pemungkah was querying as to whether or not there was some logic in place in the perlmonks.org code that cared about certain aspects of an incoming request to the XP ticker. I doubt there's anything in place that cares about a user agent, as my understanding of the tickers as that they're designed for just such automated and non-human access.

    As I suspect the meat of the code that pemungkah is actually javascript (correct me if I'm wrong), posting it here will likely fan further flames and downvoting.

    pemungkah, the only advice I can give is to browse around some of the other monks' PM tools (like jimt's PM XP Junkie, and I'm sure there are others around that I can't quickly find ATM) that might give you easily browsable examples (some, like jimt's, even in other languages besides perl) of accessing the various tickers automatically.



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
Re: PM XP OS X Widget
by Anonymous Monk on Nov 23, 2006 at 08:54 UTC
    Where is your code?