Stuff now imported into dasBlog
I went ahead and wrote a little C# program to convert a sharpreader-style cache RSS file into a set of dasBlog-compatible dayentry files. One little problem surfaced in that while BlogX used a url + random GUID for each entry’s guid, dasBlog uses only a random guid. This will have the effect of a bunch of entries (15, to be exact) appearing as new in your RSS aggregators. Sorry about that as well.
Anyway, if someone needs to do something similar, here’s the code I used. It expects a sharpreader-generated file named “backup.xml” in its working directory (look for a suitable file in %USERPROFILE%\Application Data\SharpReader\Cache and rename it), and if you’re not in the CEST timezone, you should probably fix the line with the FIXME comment.
using System;
using System.Xml;
namespace DasBlogImport
{
class Importer
{
static private void addElementToEntry(XmlDocument doc,
XmlElement entry,
String elementName,
String elementValue)
{
XmlElement e = doc.CreateElement(elementName);
e.InnerText = elementValue;
entry.AppendChild(e);
}
[STAThread]
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("backup.xml");
XmlNodeList nodeList = doc.GetElementsByTagName("Items");
XmlNode element;
XmlNode entries = null;
String lastDate = String.Empty;
XmlDocument dayentry = null;
foreach (XmlNode item in nodeList)
{
element = item.SelectSingleNode("PubDate");
String date = element.InnerText.Substring(0,10);
if (date != lastDate)
{
// flush the entries for the current day, and start a new document
if (dayentry != null)
dayentry.Save(lastDate+".dayentry.xml");
dayentry = new XmlDocument();
dayentry.LoadXml(" “);
XmlElement root = dayentry.DocumentElement;
element = dayentry.CreateElement(”Date”);
element.InnerText = date + “T02:00:00.0000000+02:00″; // FIXME: If you’re not in the CEST timezone, you probably want to change this
root.AppendChild(element);
entries = dayentry.CreateElement(”Entries”);
root.AppendChild(entries);
lastDate = date;
}
XmlElement entry = dayentry.CreateElement(”Entry”);
entries.AppendChild(entry);
addElementToEntry(dayentry, entry, “Content”, item.SelectSingleNode(”Description”).InnerText);
addElementToEntry(dayentry, entry, “Created”, item.SelectSingleNode(”PubDate”).InnerText);
addElementToEntry(dayentry, entry, “Modified”, item.SelectSingleNode(”PubDate”).InnerText);
String guid = item.SelectSingleNode(”Guid”).InnerText;
addElementToEntry(dayentry, entry, “EntryId”, guid.Substring(guid.Length-36,36)); // 36 = the length of a 128-bit GUID in standard string form
addElementToEntry(dayentry, entry, “Description”, String.Empty);
addElementToEntry(dayentry, entry, “Title”, item.SelectSingleNode(”Title”).InnerText);
if (item.SelectSingleNode(”Subject”) != null)
addElementToEntry(dayentry, entry, “Categories”, item.SelectSingleNode(”Subject”).InnerText);
else
addElementToEntry(dayentry, entry, “Categories”, String.Empty);
addElementToEntry(dayentry, entry, “IsPublic”, “true”);
addElementToEntry(dayentry, entry, “ShowOnFrontPage”,”true”);
addElementToEntry(dayentry, entry, “Crossposts”, String.Empty);
}
}
}
}
Tags: dasBlog, metablogging