26 (edited by ThomD 2010-02-26 10:46:11)

Re: Package Tracker Widget

The links to the source PHP are all dead.  Does anyone have the php script?

Update: Never mind.  I pulled the file from the Wayback Machine.

Re: Package Tracker Widget

It looks like UPS (and probably others) have changed the layout of their HTML pages, so the old script did not work.  I've redone the script to handle UPS. I'll tackle FedEx in the next week or so.  When it is ready for public use, I'll post here.

Re: Package Tracker Widget

I have a stupid question that may be related to the issue above about the layout change.

What goes in the "RSS URL" field when configuring this widget?  I kept the default but got an error.  Then I tried the .php.txt file referenced in Reply 18 of this thread but got the same error.

If it helps, I'm trying to track 2 UPS shipments.

Re: Package Tracker Widget

The original links don't work anymore because the carriers have changed their response layouts.  Try this

http://www.tandemhearts.com/trk/track2.php

That links to my script on my server.  It should work for UPS and FedEx.  Let me know how it goes for you. The script has a 5 hours refresh cache interval, so any package's status only updates 4 times per day.

What I really need is somebody with a FedEx package in transit to test it to see if that works.  All my FedEx packages have been delivered.

Re: Package Tracker Widget

For any German users here who want to track packets for DHL Germany you can replace the "parseDHL" function with this:

    function parseDHL()
    {
            $link = 'http://nolp.dhl.de/nextt-online-public/set_identcodes.do?lang=de&idc=' . urlencode($this->trackingNumber);
            $html = file_get_contents($link);

            if(!strpos($html, "IDC-Pr")) {      // check for part of error-text
                error_reporting(0);     // have to disable error reporting because the DHL website is malformed
                
                // create a new DOM object
                $dom = new domDocument;
                $dom->loadHTML($html);
                $dom->preserveWhiteSpace = false;

                $tables = $dom->getElementsByTagName('table');
                $rows = $tables->item(0)->getElementsByTagName('tr');

                // loop over all table rows
                $stats = array();
                $rowcount = 0;
                foreach ($rows as $row)
                {
                    if($row->getAttribute('class') == 'listeven')
                    {
                        $cols = $row->getElementsByTagName('td');
                        
                        switch($rowcount) {
                            case '0':       // product type
                                // product
                                $stats['service'] = $cols->item(1)->nodeValue;
                                break;
                            case '1':       // receiver
                                $stats['destination'] = $cols->item(1)->nodeValue;
                                break;
                            case '2':       // current status
                                $stats['status'] = trim($cols->item(1)->nodeValue);
                                break;
                            case '3':       // status update time
                                $stats['lastupdate'] = $cols->item(1)->nodeValue;
                                break;
                            case '4':       // next step
                                $stats['next'] = trim($cols->item(1)->nodeValue);
                                break;
                            }
                        $rowcount++;
                    }
                } 
                return $this->generateSummaryItem($stats);
            } 
            return $this->invalidTrackingNumber();
    }

And modify generateSummaryItem like this:

    function generateSummaryItem($data)
    {
        $output = "\t\t" . '<item>' . "\n";
        $output .= "\t\t\t" . '<title>Summary</title>' . "\n";
        $output .= "\t\t\t" . '<description>';

        if (isset($data['status']) && !empty($data['status'])) {
            $output .= '&lt;b&gt;Status:&lt;/b&gt; ' . $data['status'];
                    if (isset($data['lastupdate']) && !empty($data['next']))
                        $output .= ' (' . $data['lastupdate'] .  ')';
                    $output .= '&lt;br/&gt;';
                }

        if (isset($data['departure']) && !empty($data['departure']))
            $output .= '&lt;b&gt;Departure:&lt;/b&gt; ' .  date($this->dateFormat, strtotime($data['departure'])) .  '&lt;br/&gt;';

        if (isset($data['destination']) && !empty($data['destination']))
            $output .= '&lt;b&gt;Destination:&lt;/b&gt; ' . $data['destination'] . '&lt;br/&gt;';

        if (isset($data['service']) && !empty($data['service']))
            $output .= '&lt;b&gt;Service Type:&lt;/b&gt; ' . $data['service'] . '&lt;br/&gt;';

        if (isset($data['est_arrival']) && !empty($data['est_arrival']))
            $output .= '&lt;b&gt;Est. Arrival:&lt;/b&gt; ' . date($this->dateFormat, strtotime($data['est_arrival'])) .  '&lt;br/&gt;';
        else if (isset($data['arrival']) && !empty($data['arrival']))
            $output .= '&lt;b&gt;Arrival:&lt;/b&gt; ' . date($this->dateFormat, strtotime($data['arrival'])) .  '&lt;br/&gt;';

        if (isset($data['last_location']) && !empty($data['last_location']))
            $output .= '&lt;b&gt;Last Location:&lt;/b&gt; ' . $data['last_location'] .  '&lt;br/&gt;';

        if (isset($data['details']) && !empty($data['details']))
            $output .= '&lt;b&gt;Details:&lt;/b&gt; ' . $data['details'] .  '&lt;br/&gt;';
        
                if (isset($data['next']) && !empty($data['next']))
            $output .= '&lt;b&gt;Next:&lt;/b&gt; ' . $data['next'] .  '&lt;br/&gt;';

                if (isset($data['lastupdate']) && !empty($data['lastupdate']) && empty($data['status']))
            $output .= '&lt;b&gt;Last Update:&lt;/b&gt; ' . $data['lastupdate'] .  '&lt;br/&gt;';


        $output .= '</description>' . "\n";

        if (isset($data['last_location']) && !empty($data['last_location']))
        {
            $response = $this->geocode($data['last_location']);
            if (is_array($response))
                $output .= "\t\t\t" . '<coords>' . $response['coord_lng'] . ', ' . $response['coord_lat'] . '</coords>' . "\n";
        }

        $output .= "\t\t\t" . '<pubDate>' . date('D, d M Y H:i:s O') . '</pubDate>' . "\n";
        $output .= "\t\t" . '</item>' . "\n";

        return $output;
    }

That provides the most basic information, but no detailed tracking history. It's sufficient for me right now.
Note that I've (mis-)used the DHL US function here so tracking US packets is broken if you do the modifications above. Maybe the author of the widget can add my "German" parseDHL function as a new widget configuration option and include it in the basic PHP script? You can use the code I posted above however you like.

Re: Package Tracker Widget

It's funny that you should pick DHL to update.  DHL does not ship small packages in the US anymore, so that's a good one to change.

32 (edited by Loibisch 2010-03-01 16:28:47)

Re: Package Tracker Widget

Well, I only picked it because I thought the US DHL function would be quite easy to adapt to the German layout, until I discovered that it's pretty much completely different and ended up rewriting the whole function, lol. smile

Re: Package Tracker Widget

There are a couple of package tracking RSS feeds here, not sure if they are *really* working since I did not have a package to track.

Might be of use to someone.

Cheers.

Re: Package Tracker Widget

THANK GOD the one I was trying to get to work for the past two hours is not among that List lol

Re: Package Tracker Widget

cbreeze wrote:

There are a couple of package tracking RSS feeds here, not sure if they are *really* working since I did not have a package to track.

Might be of use to someone.

Cheers.

I tested the UPS one and it sort of works.  The detail is at least partially right, but it reported the package delivered 67 days ago (not 7 like it should be).

Re: Package Tracker Widget

Oh, and not to scare anyone, but since that php file is hosted on my server, I can see your results in the cache.  I promise not to read them until they are at least 30 days old.  At that point I might look at them to see if I can improve the results. More likely I will just forget they are there and delete them maybe annually.

Somebody has been testing, so how about some feedback (suggestions)? smile

Re: Package Tracker Widget

I've updated the widget so that UPS handles detailed locations better and the feed reports when it was last updated.

Re: Package Tracker Widget

I finally have a FedEx package in transit, so I've improved the FedEx part for the current layout.

Re: Package Tracker Widget

I've fixed the FedEx tracker. I'm almost ready to make the php file available for download.

Re: Package Tracker Widget

FedEx and UPS are working fine, so I'm making the script available for anyone who wants to host their own php files. 

http://www.tandemhearts.com/trk/track2.txt

Re: Package Tracker Widget

I just tried this for the first time. FedEx seems to be working. UPS just gives me:

"As of [date, time]"

and no information

Brian, #1 Joan Jett Fan

Re: Package Tracker Widget

Joan Jett wrote:

I just tried this for the first time. FedEx seems to be working. UPS just gives me:

"As of [date, time]"

and no information

It looks like UPS has changed the format of their output.  I'll try to fix it this weekend.

Re: Package Tracker Widget

ThomD wrote:
Joan Jett wrote:

I just tried this for the first time. FedEx seems to be working. UPS just gives me:

"As of [date, time]"

and no information

It looks like UPS has changed the format of their output.  I'll try to fix it this weekend.

Thanks Thom -- just can't say thanks enough to you widget developers! Wish I could get my head around the process or find the time to do some myself.

Brian, #1 Joan Jett Fan

Re: Package Tracker Widget

Sorry Joan, et al

UPS has made a big change to how they handle tracking requests, so the UPS function is broken indefinitely. I won't have the time to work on this for at least a few weeks.

45 (edited by ApoXX 2010-07-28 10:41:33)

Re: Package Tracker Widget

Thanks for helping ot maintain this ThomD (and Loibisch)! It's nice to see other developers picking up
my code (and hopefully understanding it), keeping it maintained, and improving on it. Greatly appreciated!!

I've updated the widget with a working URL (and I included your link as an alternative ThomD - but I'll remove it ASAP if you'd prefer it stay in the forums only). The widget has a little nicer looking error page and I've created a new icon but nothing has changed UI-wise. If you already have this widget added to a channel, you will have to manually update the RSS URL configuration for the tracking to work again.

With regards to the PHP code, I've updated the parsing routines for UPS and FedEx. I've also refactored the code to make it more object-oriented. While there are now more files and lines, I think the new organization will make it less intimidating for other developers to pick up and write or rewrite carrier-specific parsers because they'll be able to zero in on only the relevant parts of the code. Also, if someone wants to integrate an official API, it should be a bit easier to do so. (A link to the source, now at Google Code, has been included in the first post of this thread.)

My next piece of maintenance for the package tracker widget is adding support for the 800x480 and 800x600 resolutions which are now offered. I'd love to get my hands on one of the Infocast frames for some testing (although I can use the virtual Chumby, it's not nearly as much fun hehe).

I'd love to develop the widget further and add new features (see the first post of this thread) but I haven't felt much engagement from the community. Are there any flash developers (and non-technical people too!) out there willing to pitch in a few hours? Maybe we should think about creating an organized backlog of feature requests. It'd be interesting to try and engage the carriers directly to discuss developing official widgets for them.

Chumby has sort of stagnated for me but I'm expecting an upsurge in usership when Chumby becomes available on the Android OS and I definitely want to try and keep this widget maintained as long as people are using it (myself included). smile

46 (edited by ApoXX 2010-07-30 16:14:54)

Re: Package Tracker Widget

I just found a package tracking site that offers mapping + an RSS feed, pretty nice UI as well.

http://boxoh.com/

I'd love to do point-to-point mapping like this on the Chumby (and it wouldn't be hard at all) but the limited screen real estate poses some interesting UI design challenges. I may pick up one of the 800px width devices and create an enhanced widget specifically for that resolution.

I'm planning to continue maintaining my own RSS feed/code for the reason that it's open source and may eventually provide some custom hooks for the Chumby - latitude/longitude lookup, output preferences, embedded image, etc.. That being said, the package tracker widget should be able to display any 3rd party feed.

The caveat is that currently my RSS script expects the tracking number to be passed as the "&num=" query string parameter but this site expects it as "&t=". You could get around that with a simple proxy script (may need to be modified depending on your particular configuration):

<?php
echo file_get_contents('http://boxoh.com/?rss=1&t=' + $_REQUEST['num']);
?>

47 (edited by ApoXX 2010-07-31 14:26:04)

Re: Package Tracker Widget

I've added auto-detection of carriers to the PHP code and the widget. The fields in the configuration have been reordered so that the tracking number is first and is the only required field. If the name is omitted, the widget will simply show it as "Package".

Selecting your carrier is still required for SmartPost and DHL Germany (which is now supported thanks to Loibisch), and may also be needed in the event that your number is not auto-detected. Please let me know if it's not detecting a valid tracking number so that I may add support for it.

There is now a generic graphical theme that will show up while loading and when using 3rd party feeds or new carriers. If the widget is able to detect the appropriate carrier, and has a theme for it, the carrier's theme will be displayed.

Re: Package Tracker Widget

This widget had a mention by Gina in the Sony Style blog a couple months ago, check it out:

http://blog.discover.sonystyle.com/dash … s-answered

Re: Package Tracker Widget

I just tried tracking a DHL Germany package again and only a few months after I wrote the code it now seems broken, grrrr.
Currently only have very limited time, but I'll try to fix it as soon as I can get to it.

Re: Package Tracker Widget

I posted some feedback over in the app page. Moving over here to ask some more detailed questions.

So one of my gripes was this magical url that had to be set up in the package tracking app. It wasn't clear what this URL is or why its there.

I dug around in the code and I see how it works. That url exists to point to the PHP scripts that then go out and chatter with the shipper APIs. I would like to compliment the developers, this is gorgeous code even for PHP.

Why can't the application hit the shipper APIs directly from the chumby?

I skimmed a few of them and the USPS and UPS classes look like a screen scrapers. I'm seeing regexes for HTML tags. Are no proper APIs available? What drove the decision to parse the HTML instead of using an API?

Fedex is a bit better, looks like it picks out a JSON object and parses that.

Thanks for taking the time to answer my questions. I will confess to skimming these while waiting on a build at my day job, I may have missed something obvious.