All scripts in one repository
This commit is contained in:
parent
a0a86492ee
commit
9f9304d6aa
61 changed files with 6668 additions and 681 deletions
106
blogger2rangitaki/blogger2rangitaki.php
Executable file
106
blogger2rangitaki/blogger2rangitaki.php
Executable file
|
@ -0,0 +1,106 @@
|
|||
#!/bin/php
|
||||
<?php
|
||||
// This is a php script for converting a blogger atom feed into rangitaki blog posts
|
||||
require './vendor/autoload.php';
|
||||
use League\HTMLToMarkdown\HtmlConverter;
|
||||
if(in_array($argv[1], array("-h", "--help", "--usage", "-?"))) {
|
||||
help();
|
||||
} else if (isset($argv[1])) {
|
||||
$content = file_get_contents("$argv[1]");
|
||||
$xml = new SimpleXMLElement($content);
|
||||
$converter = new HtmlConverter(array('strip_tags' => true));
|
||||
$i = 0;
|
||||
foreach ($xml->entry as $entry) {
|
||||
if($i > 56) {
|
||||
|
||||
// TITLE
|
||||
$title = $entry->title;
|
||||
|
||||
// CONTENT
|
||||
$content = $entry->content;
|
||||
$content = $converter->convert($content);
|
||||
|
||||
// AUTHOR
|
||||
$author = $entry->author->name;
|
||||
|
||||
// TAGS
|
||||
if (isset($entry->categories)) {
|
||||
echo "YES!";
|
||||
foreach ($entry->categories->attributes as $tag) {
|
||||
if (!(substr_compare($tag->scheme, "http://schemas.google.com/", 0, 26))) {
|
||||
$tags = $tags . $tag->term . ", ";
|
||||
}
|
||||
$tags = substr($tags, 0, strlen($tags) - 2);
|
||||
}
|
||||
}
|
||||
|
||||
// Pubdate
|
||||
$pubdate = $entry->published;
|
||||
date_default_timezone_set("UTC");
|
||||
$pubdate = date("d F Y", strtotime($pubdate));
|
||||
|
||||
// FILENAME
|
||||
$date = $entry->published;
|
||||
$date = date("Y-m-d-H-i", strtotime($date));
|
||||
$filetitle = str_replace(" ", "-", $title);
|
||||
$filename = $date . "-" . $filetitle . ".md";
|
||||
|
||||
if(isset($tags)){
|
||||
$filecontent = <<<EOD
|
||||
%TITLE: $title
|
||||
%DATE: $pubdate
|
||||
%AUTHOR: $author
|
||||
%TAGS: $tags
|
||||
|
||||
$content
|
||||
EOD;
|
||||
} else {
|
||||
$filecontent = <<<EOD
|
||||
%TITLE: $title
|
||||
%DATE: $pubdate
|
||||
%AUTHOR: $author
|
||||
|
||||
$content
|
||||
EOD;
|
||||
}
|
||||
|
||||
|
||||
// Make a output directory
|
||||
if(!(file_exists("articles"))) {
|
||||
mkdir("articles");
|
||||
}
|
||||
|
||||
// Save the file
|
||||
$handle = fopen("articles/$filename", "c");
|
||||
fwrite($handle, $filecontent);
|
||||
fclose($handle);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
help();
|
||||
}
|
||||
|
||||
function help() {
|
||||
$help = <<<EOD
|
||||
|
||||
blogger2rangitaki
|
||||
|
||||
A small PHP script which converts a Blogger XML export to Rangitaki blog posts.
|
||||
|
||||
COPYRIGHT © 2015 Rangitaki Project
|
||||
|
||||
MIT License
|
||||
|
||||
Usage:
|
||||
|
||||
./blogger2rangitaki filename.xml
|
||||
|
||||
Where filename.xml is the Blogger export.
|
||||
|
||||
The articels are saved in articles/
|
||||
|
||||
EOD;
|
||||
|
||||
echo $help;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue