If you intend to build scripts, you may want to investigate launchpadlib.
However, since I don't use launchpadlib directly, I'll give a couple pointers that hopefully illustrate the gist of manually using data provided in Launchpad to generate diffs.
Here're references for using with a web browser or bzr for an example source package, alsa-driver.
Debian unstable (Sid) is at https://code.launchpad.net/~ubuntu-branches/debian/sid/alsa-driver/sid. The URI you can use with bzr is lp:debian/sid/alsa-driver
Ubuntu 10.10 (Maverick) is at https://code.launchpad.net/~ubuntu-branches/ubuntu/maverick/alsa-driver/maverick. The URI you can use with bzr is lp:ubuntu/maverick/alsa-driver
Then, you simply bzr diff your branches of lp:debian/sid/alsa-driver and lp:ubuntu/maverick/alsa-driver to obtain what is essentially a
diff -uNr $debian_sid $ubuntu_maverick. I'm fairly certain this approach directly addresses what you seek with "Ubuntu changes from debian mainline", but it may be far easier to accomplish with existing tools involving launchpadlib.
In fact, MOTU often use something similar; you can find an overview at https://wiki.ubuntu.com/DistributedDevelopment/Documentation/Merging.