Import Google Notebook entries into local database, part 2Posted by Matt Thommes on February 1, 2010 | Post type: Gain Our previous post on migrating Google Notebook entries to a personal database only touched briefly on how to setup your own notebook application using PHP and MySQL. I've refined the script and database structure slightly. OverviewUsing PHP, I've set up a script that reads a Google Notebook Atom XML file, and inserts each note into a few database tables. I am then developing a front-end interface to view, add, and edit notebook entries. I will only cover the initial migration aspect in this article - developing the front-end interface is up to you. Create database tablesFirst, create three MySQL database tables: CREATE TABLE `note` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `date_created` datetime NOT NULL, `date_modified` datetime DEFAULT NULL, `content` text NOT NULL, PRIMARY KEY (`id`) ); CREATE TABLE `category` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(250) NOT NULL, `slug` varchar(250) NOT NULL, PRIMARY KEY (`id`) ); CREATE TABLE `note_category` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `noteid` int(11) NOT NULL, `categoryid` int(11) NOT NULL, PRIMARY KEY (`id`) ); A description of each table is below:
Insert Notebook names as categoriesSince I only had a dozen or so individual notebooks, I just manually inserted each into the
INSERT INTO `category` (`name`, `slug`) VALUES ('My Notebook', 'my-notebook');
Note the unique ID for each notebook, which will be used when importing individual notes. Create PHP scriptThis example script assumes the following things:
$notes = file_get_contents("mynotebook.xml");
$notes = simplexml_load_string($notes);
foreach ($notes -> entry as $note)
{
$noteid = &$db_conn -> query("INSERT INTO note (date_created, date_modified, content) VALUES (NOW(), '" . date( "Y-m-d G:i:s", strtotime($note -> updated) ) . "', '<p>" . str_replace( "'", "\'", $note -> content ) . "</p>')") -> insertId();
$category_insert = &$db_conn -> query("INSERT INTO note_category (noteid, categoryid) VALUES (" . $noteid . ", 1)");
echo "Note #" . $noteid . " inserted successfully.<br>";
}
You need to also change the "1" in the Export and upload Google Notebook fileIn Google Notebook, click the "Export" link at the bottom of page, while viewing the notebook you wish to migrate:
Then click "Atom" to export the notebook as an XML file:
Upload this file to your web server, where your PHP script can access it. In your script that loops through each note, change the source file in this line to match the name of your uploaded XML file:
Final stepsRun the PHP page in your browser, and you should see a confirmation that each note got imported into your own database. Do this for each individual Google Notebook, and you'll have all of your notes safely backed up, and available to use for creating your own notebook interface. About the author(s)Matt Thommes is an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from a suburb of Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us. Comments
|
Quick Link to this postTTIP.me/2278 |