From 0753bfefd7444712a20cee28fdb057e48602b2eb Mon Sep 17 00:00:00 2001 From: nicosomb Date: Wed, 17 Apr 2013 10:35:50 +0200 Subject: [PATCH] import depuis Pocket, yeah cf #3 --- CREDITS | 1 + README.md | 4 + import.php | 55 ++ inc/simple_html_dom.php | 1722 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 1782 insertions(+) create mode 100644 import.php create mode 100644 inc/simple_html_dom.php diff --git a/CREDITS b/CREDITS index 916eae5..6df488e 100644 --- a/CREDITS +++ b/CREDITS @@ -4,6 +4,7 @@ poche is based on : * Encoding https://github.com/neitanod/forceutf8 * logo by Brightmix http://www.iconfinder.com/icondetails/43256/128/jeans_monotone_pocket_icon * icons http://icomoon.io +* PHP Simple HTML DOM Parser (for Pocket import) http://simplehtmldom.sourceforge.net/ poche is developed by Nicolas Lœuillet under the Do What the Fuck You Want to Public License diff --git a/README.md b/README.md index d1e1f0f..c678d11 100755 --- a/README.md +++ b/README.md @@ -27,6 +27,10 @@ You **have** to protect your db/poche.sqlite file. Modify the virtual host of yo ``` +## Import from Pocket + +If you want to import your Pocket datas, [export them here](https://getpocket.com/export). Put the HTML file in your poche directory, execute import.php file locally by following instructions. Be careful, the script can take a very long time. + ## License Copyright © 2010-2013 Nicolas Lœuillet This work is free. You can redistribute it and/or modify it under the diff --git a/import.php b/import.php new file mode 100644 index 0000000..7a657c2 --- /dev/null +++ b/import.php @@ -0,0 +1,55 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +set_time_limit(0); + +include dirname(__FILE__).'/inc/config.php'; +include dirname(__FILE__).'/inc/simple_html_dom.php'; + +if (!isset($_GET['start'])) { + echo 'Please execute the import script locally, it can take a very long time.
Bye bye Pocket, let\'s go !'; +} +else { + $html = new simple_html_dom(); + $html->load_file('ril_export.html'); + + $read = '0'; + $errors = array(); + foreach($html->find('ul') as $ul) + { + foreach($ul->find('li') as $li) + { + $a = $li->find('a'); + $url = $a[0]->href; + $parametres_url = prepare_url($url); + $sql_action = 'INSERT INTO entries ( url, title, content, is_read ) VALUES (?, ?, ?, ?)'; + $params_action = array($url, $parametres_url['title'], $parametres_url['content'], $read); + try + { + # action query + if (isset($sql_action)) + { + $query = $db->getHandle()->prepare($sql_action); + $query->execute($params_action); + } + } + catch (Exception $e) + { + $errors[] = $e->getMessage(); + } + } + # Pocket génère un fichier HTML avec deux