A Python content management system designed for kirsle.net featuring a blog, comments and photo albums. https://rophako.kirsle.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.1KB

  1. #!/usr/bin/env python
  2. """Migrate blog database files from a PerlSiikir site to Rophako.
  3. Usage: scripts/siikir-blog-migrate.py <path/to/siikir/db/root>
  4. Rophako supports one global blog, so the blog of UserID 1 in Siikir is used."""
  5. import sys
  6. import os
  7. import codecs
  8. import json
  9. import glob
  10. sys.path.append(".")
  11. import rophako.jsondb as JsonDB
  12. # Path to Siikir DB root.
  13. siikir = None
  14. def main():
  15. if len(sys.argv) == 1:
  16. print "Usage: {} <path/to/siikir/db/root>".format(__file__)
  17. sys.exit(1)
  18. global siikir
  19. siikir = sys.argv[1]
  20. print "Siikir DB:", siikir
  21. if raw_input("Confirm? [yN] ") != "y":
  22. sys.exit(1)
  23. convert_index()
  24. #convert_tags()
  25. convert_posts()
  26. def convert_index():
  27. print "Converting blog index"
  28. index = json_get("blog/index/1.json")
  29. new = {}
  30. for post_id, data in index.iteritems():
  31. del data["id"]
  32. # Enforce data types.
  33. data["author"] = int(data["author"])
  34. data["time"] = int(data["time"])
  35. data["sticky"] = bool(data["sticky"])
  36. new[post_id] = data
  37. JsonDB.commit("blog/index", new)
  38. def convert_tags():
  39. print "Converting tag index"
  40. index = json_get("blog/tags/1.json")
  41. JsonDB.commit("blog/tags", index)
  42. def convert_posts():
  43. print "Converting blog entries..."
  44. for name in glob.glob(os.path.join(siikir, "blog/entries/1/*.json")):
  45. name = name.split("/")[-1]
  46. post = json_get("blog/entries/1/{}".format(name))
  47. post_id = post["id"]
  48. del post["id"]
  49. # Enforce data types.
  50. post["time"] = int(post["time"])
  51. post["author"] = int(post["author"])
  52. post["comments"] = bool(post["comments"])
  53. post["sticky"] = bool(post["sticky"])
  54. post["emoticons"] = bool(post["emoticons"])
  55. print "*", post["subject"]
  56. JsonDB.commit("blog/entries/{}".format(post_id), post)
  57. def json_get(document):
  58. fh = codecs.open(os.path.join(siikir, document), 'r', 'utf-8')
  59. text = fh.read()
  60. fh.close()
  61. return json.loads(text)
  62. if __name__ == "__main__":
  63. main()