{"id":1,"date":"2024-04-01T06:37:52","date_gmt":"2024-04-01T06:37:52","guid":{"rendered":"https:\/\/fugutabetai.com\/blog\/?p=1"},"modified":"2024-04-08T09:11:40","modified_gmt":"2024-04-08T00:11:40","slug":"hello-world","status":"publish","type":"post","link":"https:\/\/fugutabetai.com\/blog\/2024\/04\/01\/hello-world\/","title":{"rendered":"Reviving the blog"},"content":{"rendered":"\n<p>In December, 2023, I had to shut down my blog because it was hacked. Now I&#8217;m trying to revive the blog by importing data from my old blog into a new one, with different software. Since I had the database with all the content, I have high hopes that I can do that.<\/p>\n\n\n\n<p>First, I needed to export the data to a form that my new blog can understand, and XML is one of the supported formats. I thought it would be fun to write a Python script, but since I don&#8217;t know Python well enough to interface with a database, that posed a problem. I decided to use a LLM to have it generate something for me, and I was very happy with Google&#8217;s Gemini and the script it generated for me. I needed to customize it, but for the most part, everything worked great. <\/p>\n\n\n\n<p>It was really interesting using a LLM to build a framework to start from. My python isn&#8217;t great, I have to look up syntax for stuff (how do you slice an array again? What is the form the ternary operator again?) and certainly don&#8217;t know what libraries to use to access a Database. Interestingly Gemini chose to use <code>mysql.connector<\/code>. Later, I found that there are at least three reasonable choices for database access, and that was actually one of the harder ones to install on Debian &#8211; I needed to download a .deb package from the internet. It wasn&#8217;t available in the default repositories. It worked fine for what I wanted, and being a pure python implementation meant that I didn&#8217;t have to worry about dependencies, so that&#8217;s fine. <\/p>\n\n\n\n<p>The LLM made a script, not a program. So I had to add a main function and make a function for the main work, but it is still a real hacky script. Once I got the database dump working (to XML) I tried to use an extension to import the data, but I never got the extension to work. I really want to have the post IDs remain the same between my old blog and new one so I can use a simple URL redirect to make the old URLs still work. So I thought I would directly insert data into the Database tables, but that proved to be hard. <\/p>\n\n\n\n<p>I found a blog talking about using WordPress&#8217;s REST API to insert posts, so I used that. Not bad! There was lots of annoying things to take care of before things were working well. The biggest problem was that the Post IDs were about 4 out of sync by the end of the 600+ posts. Turned out my old blog had 4 posts missing, maybe deleted or something. So I needed to add dummy posts, but after that everything worked fine.<\/p>\n\n\n\n<p>Now I face the problem that <code>&lt;script&gt;<\/code> tags in the raw HTML of my posts don&#8217;t work. I need to figure out what WordPress is doing to them &#8211; I use scripts from Flickr for images and Twitter to embed tweets, both of which I want to work before putting my blog back in service. I also will need to look at CSS and the theme but I&#8217;m less concerned about that if I can get the images with captions and twitter embeds in here. <\/p>\n\n\n\n<p>Anyway, looks like things are working reasonably well. I had to give up on hosting wp-content in a separate directory, but that is fine. Mod_rewrite is a real beast. There is still a lot of work to do &#8211; old posts have different CSS so I should try to see if I can do something for that, and I haven&#8217;t played with the theme at all. Still, great to have the blog back and a real history (of my own) preserved. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In December, 2023, I had to shut down my blog because it was hacked. Now I&#8217;m trying to revive the blog by importing data from my old blog into a new one, with different software. Since I had the database with all the content, I have high hopes that I can do that. First, I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":677,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,5],"tags":[],"_links":{"self":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/posts\/1"}],"collection":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":3,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":678,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/posts\/1\/revisions\/678"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/media\/677"}],"wp:attachment":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}