Thimbron

September 20, 2020

Simple Mp-wp Article Import Script

Filed under: alethepedia, mp-wp — thimbronion @ 12:36 a.m.

Below is a simple script for importing an article directly into mp-wp via the db inspired by lobbes' previous work on importing logs into mp-wp. It is a necessary step towards being able to import the entire Encyclopedia Britannica into mp-wp. I thought it might be useful for anyone wishing to automate creation of articles.

#!/usr/bin/python

import mysql.connector
import time
import json
from pprint import pprint

def add_article(cnx, article):
        cursor = cnx.cursor()

        content = article['content'] 

        current_date = time.strftime("%Y-%m-%d %H:%M:%S",
                                                     (1910, 1, 1, 1, 3, 38, 1, 48, 0))
        current_date_gmt = current_date
        title = article['title']
        post_url_relative = '-'.join(title.split())

        query = '''INSERT INTO wpmp_posts(post_author, post_date,
                        post_date_gmt, post_content, post_title,
                        post_category, post_status, comment_status, ping_status,
                        post_name, post_modified, post_modified_gmt, post_parent,
                        guid, menu_order, post_type, comment_count,
                        post_excerpt, to_ping, pinged, post_content_filtered,
                        post_mime_type, post_password) VALUES (%s,%s,%s,%s,
                                %s,%s,%s,%s,
                                %s,%s,%s,%s,
                                %s,%s,%s,%s,
                                %s,%s,%s,%s,
                                %s,%s,%s) ; '''
        cursor.execute(
                query,
                (0, current_date, current_date_gmt, content, title, 0, "publish",
                 "open", "open", post_url_relative, current_date,
                 current_date_gmt, 0, "", 0, "post", 0, "", "", "", "", "", "")
        )

        cnx.commit()

cnx = mysql.connector.connect(user='jwz', password='justwantedto',
                host='127.0.0.1',
                database='alethepedia')
json_file = '../data/encyclopedia.json'
with open(json_file) as json_data:
    data = json.load(json_data)
add_article(cnx, data[0]['articles'][0])
cnx.close()

May 27, 2020

Rule Britannica

Filed under: alethepedia, news, propaganda — thimbronion @ 4:20 p.m.

Absolutely Nobody:

Me: Let’s scrape the 1910 Encyclopedia Britannica and load it up into an mp-wp instance.

When writing qntra articles I often found myself depending on Pediwiki to find original sources when doing background checks. This was a revolting experience to say the least.

To address this, I am standing up an mp-wp instance containing the the entire 11th edition of Encyclopedia Britannica, which is available in unusable form only from the Internet Archive and Project Gutenberg. It goes without saying that this will be added to lekythion’s search index.

Obviously it won’t contain bios of more recent public figures, but it is a start, and would perhaps have come in handy when writing the unpersoning piece.

I look forward to being able to reference specific phrases/lines in the best encyclopedia ever.

Powered by WordPress