2017-12-31 UTC
# Loqi [indienews] New post: "I am curently writing a custom indieweb note system for my webiste, my requirements are different to most/all indieweb implementation as I need three different way of creating notes Text-editor, Browser and Offline
text-editor
I use a text editor to add entries to YAML file
This Github Sample is by tomasparks
_notes/local/2017/10.yml view raw
- date: 2017-10-19
type: twitter
message: "I've been watching Donald Trump and 'little rocket man' Kim Jong-un and it reminds me of [Team America: World Police](https://en.wikipedia.org/wiki/Team_America:_World_Police)"
- date: 2017-10-19
type: like
web Browser / mircopub
Unimplementated because I have not found a browser plugin/addon that support my wishlist1 yet, the closest i’ve found is Omnibear
Offline / CSV
I use a PDA2, when I away from my computers, the PDA has good database software witch can export CSV files
This Github Sample is by tomasparks
_notes/pda/2017/12.csv view raw
"twitter",,"its been 12 months sinceth glenfliet fire",,"15/12/2017"
"read","ASIN:B073GDQFJ2",,"page: 213","15/12/2017"
"read","ASIN:B073GDQFJ2","minitel ads were hated just as much as todays internet ads","page: 216-217","15/12/2017"
"bookmark","journey 1 and 2",,,"15/12/2017"
"read","ASIN:B073GDQFJ2",,"page: 251","16/12/2017"
data format
I am using the SQL format to demonstrate the data format
CREATE TABLE data (
date CHAR(255),
type CHAR(255),
tags CHAR(255),
url CHAR(255),
message TEXT
);
type is for the post type excluding articles
tags are a csv encoded key:value pairs
url are for Uniform Resource Identifier, I am currently using CSV ecoded key:value pairs, I am looking at using the Url Query format in the future
NOTE: data fomrat MUST be human editable
No url encoding
Source Code
This Github Sample is by tomasparks
_rake/notes.php view raw
#!/usr/bin/env php
<?php
// key: qhNU8kMDrqS2Ryk8ExmyA
//secret: 1tICNtAofpr0Coycb4eacrf4FcFCWSOzW8novjYL8
require_once './php-mf2/Mf2/Parser.php';
require_once './htmlpurifier/library/HTMLPurifier.auto.php';
require_once './goodreads-api/GoodReads.php';
function create_notes($data) {
foreach ($data as $note) {
print_r($note);
echo "\n";
$hash = hash ('sha1' , json_encode($note));
echo $hash."\n";
$date_split = date_parse($note['date']);
$isodate = sprintf("%04d-%02d-%02d", $date_split['year'], $date_split['month'], $date_split['day']);
$permdate = sprintf("%04d/%02d/%02d", $date_split['year'], $date_split['month'], $date_split['day']);
$mdfile = fopen($hash.".md", "w");
fwrite($mdfile, "---\n");
fwrite($mdfile, "layout: notes_".$note['type']."\n");
fwrite($mdfile, "date: ".$isodate."\n");
fwrite($mdfile, "type: ".$note['type']."\n");
//fwrite($mdfile, "date: ".$isodate."\n");
fwrite($mdfile, "permalink: /notes/".$note['type']."/".$permdate."/".$hash.".html\n");
switch ($note['type']) {
case "twitter":
//fwrite($mdfile, "ext-url: ".$note['url']."\n");
fwrite($mdfile, "---\n");
fwrite($mdfile, $note['message']."\n");
break;
case "like":
$html = file_get_contents($note['url']);
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
$cleanhtml = $purifier->purify($html);
$mf = Mf2\parse($cleanhtml, $note['url']);
fwrite($mdfile, "ext-url: ".$note['url']."\n");
fwrite($mdfile, "---\n");
//fwrite($mdfile, $note['message']."\n");
break;
case "read";
$goodreads_api = new GoodReads('qhNU8kMDrqS2Ryk8ExmyA', '/home/tom/github/blog/website/_rake/tmp/');
$tags = $note['tags'];
if (array_key_exists("asin",$tags)) {
$data = $goodreads_api->getBookByISBN($tags['asin']);
}
if (array_key_exists("ASIN",$tags)) {
$data = $goodreads_api->getBookByISBN($tags['ASIN']);
}
$book = $data['book'];
fwrite($mdfile, "book-title: \"".$book['title']."\"\n");
fwrite($mdfile, "book-image_url: \"".$book['small_image_url']."\"\n");
fwrite($mdfile, "book-url: \"".$book['url']."\"\n");
//foreach($note['tags'] as $tagkey => $tag_value) {
//fwrite($mdfile, "tags-".$tagkey.": ".$tag_value."\n");
//}
//foreach($note['urls'] as $urlkey => $url_value) {
//fwrite($mdfile, "urls-".$urlkey.": ".$url_value."\n");
//}
fwrite($mdfile, "---\n");
fwrite($mdfile, $note['message']."\n");
//fwrite($mdfile,json_encode($book)."\n");
break;
default:
fwrite($mdfile, "---\n");
fwrite($mdfile, $note['message']."\n");
break;
}
fclose($mdfile);
}
}
function csv_parse_file ( $file ) {
echo "opening ".$file."....";
if (($handle = fopen($file, "r")) !== FALSE) {
echo "Done\n";
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
print_r($data);
$res['type'] = $data['0'];
$tmpdate = date_create_from_format('d/m/Y', $data['4']);
$res['date'] = date_format($tmpdate, 'Y-m-d');
$res['message'] = $data['2'];
// $res['tag'] = $data['1'];
// $my_string = "key0:value0,key1:value1,key2:value2";
// tags
$oldtags_array = explode(',', $data['1']);
$tags_array = "";
for($i=0; $i < count($oldtags_array ); $i++){
$key_value = explode(':', $oldtags_array [$i]);
$tags_array[$key_value [0]] = $key_value [1];
}
$res['tags'] = $tags_array;
// url tags
if (strpos($data['3'], 'http') !== false) { $res['url'] = $data['3'];
} else {
$oldurl_array = explode(',', $data['3']);
$url_array = "";
for($i=0; $i < count($oldurl_array ); $i++){
$key_value = explode(':', $oldurl_array [$i]);
$url_array[$key_value [0]] = $key_value [1];
}
$res['urls'] = $url_array;
}
$ret[] = $res;
}
}
fclose($handle);
return $ret;
}
$path = getcwd();
$notes_path = str_replace("_rake","_notes",$path);
chdir($notes_path);
$notes_dir = scandir($notes_path);
foreach ($notes_dir as $dir) {
if ($dir === "." or $dir === ".." )
{continue;}
chdir($notes_path."/".$dir);
$year_dir = scandir($notes_path."/".$dir);
foreach ($year_dir as $ydir) {
if ($ydir === "." or $ydir === "..") {continue;}
chdir($notes_path."/".$dir."/".$ydir);
echo getcwd()."\n";
$filelist = scandir($notes_path."/".$dir."/".$ydir);
foreach ($filelist as $file) {
if ($file === "." or $file === "..") {continue;}
switch(true) {
case strstr($file, "md"):
echo "skipping md file\n";
continue 2;
case strstr($file, "yml"):
echo "yml file\n";
$data = yaml_parse_file ( $file );
create_notes($data);
break;
case strstr($file, "csv"):
echo "CSV file\n";
$data = csv_parse_file ( $file );
create_notes($data);
break;
}
}
}
}
?>
Support like/comments, UPDATE: I found own your comments and IndieWeb Reply Browser-Extension, but they seam like they have code rot :( ↩
It’s as psion 5mx Pro ↩
Date: 26 Dec 2017
Permalink: https://tomasparks.github.io//archive/2017/12/notes-system.html
Also posted on IndieNews
my photo
Tom Sparks
email,
I am a Alternative Technology Researcher, with a focus on Digital Communication Networks." https://tomasparks.github.io//archive/2017/12/notes-system.html