Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import json
- import os
- import sys
- import datetime
- with open("old.json", "r") as f:
- raw = f.read()
- old = json.loads(raw)
- posts = old["db"][0]["data"]["posts"]
- postcount = len(posts)
- # Data Munging
- tags = {}
- for item in old["db"][0]["data"]["tags"]:
- tags[item["id"]] = item["slug"]
- post_tags = {}
- for item in old["db"][0]["data"]["posts_tags"]:
- post_tags.setdefault(item["post_id"], []).append(tags[item["tag_id"]])
- # Kickoff the processing
- print("Found %s posts" % postcount)
- if not os.path.exists('content'):
- print("I don't think we're in the pelican directory. Exiting")
- sys.exit(1)
- def find_post_tags(postid):
- if post_tags.has_key(postid):
- return ", ".join(post_tags[postid])
- return "untagged"
- for post in posts:
- date = datetime.datetime.fromtimestamp(post["created_at"] / 1e3)
- filename = "{}-{}.md".format(date.strftime("%Y-%m-%d"), post["slug"])
- print "Processing {}".format(filename)
- with open("content/{}".format(filename), 'w+') as f:
- f.write("Title: {}\n".format(post['title']))
- f.write("Date: {}\n".format(date.strftime("%Y-%m-%d %H:%m")))
- f.write("Tags: {}\n".format(find_post_tags(post["id"])))
- f.write("Slug: {}\n".format(post['slug']))
- f.write("---\n")
- f.write("{}".format(post['markdown'].encode('utf8')))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement