testtestHome

How to grab your Google Reader OPML using PHP and cURL

29.03.2009 by Mich - lire la version francophone - lees dit in het Nederlands

I don't like doing some things twice. When I subscribe to a blog, I want it to be added to my blogroll as well. Until now, I had to add the link manually to blog, since I don't want to use ugly widgets here. There is an easy solution, called OPML.

My idea was to fetch the OPML-file once a day from Google Reader and save it somewhere here. The blogroll will then be generated from the OPML each time some one will check my blogroll. Using this technique, there would only be a 24 hour delay in displaying new blogs I've subscribed to.

But there is an annoying part. To be able to download your OPML-file you have to sign on. That's pretty annoying. And for that I had to do something I never did before: use cURL with cookies.

It's actually quite simple: just fill in a Google sign on form from cURL and save what is returned for a cookie to a file. Use that file as cookie when accessing the OPML-file URL directly.

If you're using Google Reader, the URL of your OPML-file is the next :

http://www.google.com/reader/public/subscriptions/user/<user_id>/

You can obtain your user id by clicking on « All Items ». A URL will appear, containing your user id between two %2F's. In my case, it is ‘06937166373900766291’:

http://www.google.com/reader/view/#stream/user%2F06937166373900766291%2Fstate%2Fcom.google%2Freading-list

Here is the PHP-script that I used for signing on and grabbing the OPML-file. I used absolute paths, because I'm planning to use it in a crontab as well :

<?
$email="barney.stinson@gmail.com";
$password="br0";

$url = "https://www.google.com/accounts/ServiceLoginAuth?service=reader";
$params = "service=reader";
$params.= "&Email=".urlencode($email);
$params.= "&Passwd=$password";
$params.= "&continue=http://www.google.com/reader/";
$params.= "&hl=en";
$params.= "&nui=1";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, "http://www.google.com/reader/public/subscriptions/user/06937166373900766291/");
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEJAR, '/tmp/cookie.txt');
curl_setopt($ch2, CURLOPT_COOKIEFILE, '/tmp/cookie.txt');
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch2);
curl_close($ch2);

$fp = fopen("/home/emich.be/public_html/misc/google-reader-subscriptions.xml","w");
fputs($fp,$data);
fclose($fp);
unlink("/tmp/cookie.txt");
?>

Don't forget to replace login, password and user id in the above script. I've saved the cookie file in the /tmp folder because I don't want anyone to be able to access that file from the outside.

This script can also be written in bash script using cURL directly. But I've used the PHP-option because a lot of people just don't have command-line access to their web servers.

tags: . .

1 comment(s)

Obama FAIL

09.02.2009 by Mich

Where? | tags:

Add a comment

Extracting GPS data from a photo's EXIF-data using PHP…

01.02.2009 by Mich - lire la version francophone (2) - lees dit in het Nederlands

I recently bought a new mobile phone, the Nokia N79, successor of my old N73. The N79 has a GPS-chip and a camera, which means geotagging fun !

The N79 stores GPS-data in the EXIF-information of the photo. By default, this is disabled. You'll have to turn it on in the settings of the camera:

Once activated, GPS-coordinates will be stored in the EXIF-headers. You can read those using the following code:

Reading EXIF data:
$exif = exif_read_data('dummyimage.jpg',0,TRUE);

Degrees:
$deg=$exif["GPS"]["GPSLatitude"][0];

Minutes:
$min=$exif["GPS"]["GPSLatitude"][1];

Seconds:
$sec=$exif["GPS"]["GPSLatitude"][2];

Hemisphere (N, S, W ou E):
$hem=$exif["GPS"]["GPSLatitudeRef"];

Altitude:
$alt=$exif["GPS"]["GPSAltitude"][0];

(for longitude, replace "GPSLatitude" by "GPSLongitude" in the above code)

I'm using this code to grab GPS data out of pictures so I can geotag blog-entries posted from my mobile.

tags: . . .

Add a comment

Test moblog + geotag

31.01.2009 by Mich

Where? | tags:

Add a comment

How to auto-follow people on Twitter based on keyword…

23.01.2009 by Mich - lire la version francophone (3) - lees dit in het Nederlands (2)

This probably has happened to you: you say something on Twitter and 5 minutes later some unknown person is following you. That new follower's principal subject is related to a word that you dropped in one of your previous twits. This happened to me with 'failwhale' and 'twhisky'.

This gave me the idea to build the same thing for a blog I write on. I wanted bxlblog's twitter account to automatically follow everyone that was saying 'bruxelles', 'brussels' or 'brussel', hoping that the person I'd have subscribed to would return the favor and become a reader of the cityblog bxlblog.

How can you achieve such a thing? It actually is quite simple: by sending a simple HTTP-request to the Twitter-search, containing the keywords you are looking for. Then you parse the result to extract user names and send another request to Twitter to just follow them. That's it! It's better for you to put that in crontab, every 5 minutes or so.

To run my script you need two things: first of all, a Linux-machine where you have shell-access in administrator mode (I use Ubuntu). Then you also have to install the curl-package that will send the follow-requests using POST and basic authentication :

sudo apt-get install curl

After that, open an editor for the script:

nano /home/emich/twittersearch.sh

And paste the following script and save/exit :

#!/bin/bash
/usr/bin/wget -O /home/emich/twittersearchresult http://search.twitter.com/search?q=bruxelles+OR+brussels+OR+brussel
NAMES=`/bin/cat /home/emich/twittersearchresult`
for value in $NAMES
do
    if [[ $value =~ home\?status\=@([^\"]*)\" ]];then
        i=1
        n=${#BASH_REMATCH[*]}
        while [[ $i -lt $n ]]
        do
            /usr/bin/curl --basic --user twitteruser:twitterpassword --data status="follow ${BASH_REMATCH[$i]}" http://twitter.com/statuses/update.xml
            let i++
        done
        shift
    fi
done

Now we need to change permission, in order to be able to execute that script :

chmod +x /home/emich/twittersearch.sh

Finally, add it to your crontab :

crontab -e

Let's say, every 5 minutes :

*/5 * * * * /home/emich/twittersearch.sh

This script can easily be written in other languages. Just don't abuse.

tags: . . .

Add a comment - 18 trackback(s)

How to convert an AVCHD-videofile (.mts/.mt2s)?

13.08.2008 by Mich - lire la version francophone (5) - lees dit in het Nederlands (6)

Making HD video is fun. But one of the things everyone tends to forget is that the video is usually recorded in a proprietary format, that, as I speak, can’t be read by Windows Media Player or Adobe Premiere.

This mini-tutorial is the result of frustrations and long hours of searching. I could only do one thing with this: share.

For converting, I used a program named TMPGEnc 4.0 Xpress, by Pegasys Inc. You need to buy a license for this but you can also download a 14-day evaluation version on their site. This program supports AVCHD and can convert it to a load of other formats. What I will show you here is the conversion of an AVCHD video made with a Canon HF10 camera (framerate-setting 50i, default) to MPEG-I.

Continue reading...
tags: . .

7 comment(s)

Google Health…

20.05.2008 by Mich - lire la version francophone (5) - lees dit in het Nederlands

It seems like Google Health is finally launched. I was waiting for this, because the only thing that was made public earlier by Google were a few screenshots on their blog.

Google Health is a personal medical file where you can put allergies, antecedents, results among other personal medical information. Your file can be made available to other healthcare actors like your practitioner, hospital or physician. You can even find a doctor that suits your needs. You can also browse their encyclopedia and link the results to your file.

At this stage, Google Health is only available for the US. It works closely with Cleveland Clinic (the pilot) and a few other institutions. The purpose would be to have a decentral, globally accessible file instead of one at your practicioner, the other at a hospital, etc and to make facilitate the interchange of documents in your file. In other words: ease your medical life.

With this, Google is making an extra step towards what it knows about me: Google knows what I’m reading (Google Reader), what I’m mailing (Gmail), what I’m searching (Google Search), where I’m going (Google Maps), etc. Now Google can also know about my health. Scary, huh? It can be a real danger. Suppose that someone gets in and steals information in order to sell it to insurance companies. If your file contains sensitive stuff, you might not be able to get an insurance anywhere. Security is a primary concern, here.

Microsoft has a similar product, HealthVault. Finland is also working on a global medical patient record for its 7 million citizens.

In order to become a success, Google will have to collaborate with a lot of healthcare institutions. I don’t know if in my country, Belgium, they are looking forward to that.

Add a comment

Fring test

20.04.2008 by Mich
tags:

Add a comment

Catastrophic failure…

17.01.2008 by Mich

Catastrophic failure !

...or an error that you can’t recover from. Doesn’t happen a lot, but always makes me smile. It’s a catastrophe! Let’s all go to those shelters! We’re all going to die! Less funny of course is trying to find what the cause of the error is.

tags:

1 comment(s)

WordPress Geotagging Plugin…

29.03.2007 by Mich
Have you ever wondered if it was possible to geotag your posts in WordPress in an easy way? So have I. And since there wasn’t anything easy available out there, I decided to write a plugin for that, using an industry standard: Google Maps.

What does the plugin do?
  • The plugin lets you geotag an entry on your blog, directly from a place you click on a Google Map in your posting screen or by entering an address into a search box. Your geotagged entries will have a link “see on map”.
  • The plugin will make your Atom, RSS2 as well as RDF feeds GeoRSS compatible, which will allow you to load it into Google Maps (example here with my photblog feed) and loads of other cool stuff!

Wordpress Post screen Wordpress feed in Google Maps


How can it be installed?
  • Download the WordPress geotagging plugin here.
  • Put the ‘geotagging’ folder into your ‘wp-content/plugins’ folder of your WordPress installation.
  • Activate the plugin in your WordPress admin console.
    Go to “Options” and “Geotagging”. There, enter your Google Maps API key (that is freely available here).
  • Change all other settings to suite your needs. Click “Save”.
  • When you will be writing a new post, there will be a box available below called “Geotagging”. It’s now up to you to find the correct spot by browsing the map or entering the address.

The plugin is running on my experimental WordPress blog, which contains some other plugins I am also writing, like the Google Maps lightbox plugin that combined with geotagged posts will make your WordPress geotagging experience a lot more fun.
tags: . . .

16 comment(s)

previous