Created
August 18, 2017 08:39
-
-
Save dmerejkowsky/14b7084b8f4dbab9da616e88d04d2f76 to your computer and use it in GitHub Desktop.
dotclear to hugo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+import sqlite3 | |
+import re | |
+import arrow | |
+ | |
+connection = sqlite3.connect("/home/dmerej/backups/dmerej.info/blog/db/blog-2016-05-21.sqlite") | |
+ | |
+cursor = connection.cursor() | |
+ | |
+def slugify(text): | |
+ res = re.sub('[^\w\s-]', '', text).strip().lower() | |
+ return re.sub('[-\s]+', '-', res) | |
+ | |
+for title, contents, dc_date in cursor.execute("""\ | |
+SELECT | |
+ post_title, post_content, post_creadt | |
+FROM dc_post | |
+WHERE post_type == "post" | |
+""" | |
+): | |
+ iso_date = arrow.get(dc_date).isoformat() | |
+ slug = slugify(title) | |
+ path = "content/post/%s.md" % slug | |
+ with open(path, "w") as fp: | |
+ fp.write("""\ | |
++++ | |
+date = "{date}" | |
+draft = false | |
+title = "{title}" | |
++++ | |
+ | |
+""".format(date=iso_date, title=title)) | |
+ | |
+ if not contents.endswith("\n"): | |
+ contents += "\n" | |
+ with open(path, "a") as fp: | |
+ fp.write(contents) | |
+ print("Imported", path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment