Python og WordPress

The Nusse Conglomerate har behov for at kunne automatisere hvad der ligger på en given side.

Mere præcist, jeg har brug for at lade diverse scripts, af typen internet-of-things, uploade data til nettet, og trække det ned igen.

Det kan gøres på mange måder, men af ideosynkratiske årsager, ønsker jeg at det skal spille sammen med WordPress. Så det kommer det til, come hell or high water.

Jeg er nået til at få uploadet data. Og efterfølgende også redigere det. Det gøres således:

import datetime, xmlrpclib
wp_url = “http://www.geekhome.dk/xmlrpc.php”
wp_username = “Her står brugernavnet”
wp_password = “Nej, jeg skriver nok ikke mit password her…”
wp_blogid = “”
status_draft = 0
status_published = 1
post_type=’page’

server = xmlrpclib.ServerProxy(wp_url)

title = “Title with spaces”
content = “Nu voldsomt redigeret”
#date_created = xmlrpclib.DateTime(datetime.datetime.strptime(“2011-10-20 21:08”, “%Y-%m-%d %H:%M”))
categories = [“category here”]
tags = [“sometag”, “othertag”]
data = {‘title’: title, ‘description’: content, ‘categories’: categories, ‘mt_keywords’: tags, ‘post_type’: post_type}

post_id = server.metaWeblog.editPost(wp_blogid, wp_username, wp_password, data, status_published)

Godt så. Det her er måden at redigere det på. Det kræver at man lige fortæller hvilket ID siden har (post_type fortæller at det er en page). Vi kunne kalde den for 42.

Skal siden derimod oprettes, er det newPost der skal stå i serverkaldet. Og er det et blogindlæg kan man fjerne post_type helt – det er som standard blogindlæg der oprettes på denne måde. Datoen er her udkommenteret. Den kan også sættes. Det er formentlig muligt at sætte hvad som helst.

Det var første trin, jeg kan nu få et pythonscript til at oprette og ændre i en side på wordpress. Næste trin er at få trukket data ud af en given side.

OK, langt om længe

En af de ting der har forsinket udviklingen i the Nusse conglomerate, har været flytningen af indhold fra den eksisterende Drupal installation på nesdunk.dk til en wordpress installation.

Ikke at jeg har noget som helst imod Drupal. Den taler til nørden i mig, og det var den jeg helst ville køre. Men…

WordPress har en funktion hvor der automatisk sker opdateringer af koden når der kommer sikkerhedsopdateringer. Det er der ikke i Drupal, af velbegrundede årsager. Men det er et problem når man i en travl hverdag skal holde et tocifret antal sites kørende og opdaterede. Så, derfor en migration til WordPress. Det er nu sket. Historiske indlæg tilbage til februar 2003 er flyttet med. Lækkert.

R and interruptions

For some interesting reasons, I’m learning Python and R. I’m done with the Codecademy introduction course in Python – and still lacking about 9000 hours of experience.

At the moment I’m doing the R introduction course from Datacamp. Not as good a course as the Codecademy, but good enough.

When I was much younger, and studying at the Technical University of Denmark, this would have been af three-week course, with an estimated workload of 140 hours (yep, we studied for almost 47 hours every week). Now, I have a lot more experience, and should be able to do it faster. On the other hand, I do not have 47 uninterrupted hours to set aside each week. More like 4. And they will be interrupted. At least twice every hour.

A post on DJØF-bladets homepage (in danish) tells of swedish research, revealing that when you are in flow, that is, when you are working at optimum efficiency, it will take 25 minutes to recover from an interruption.

A qualified guess is, that at the current level of interruptions, this three-week course, is converted to an 84 week course.

Moving the print journals

All the print journals, and all print books in closed stacks, have been moved from my little library. We started monday, and was finished friday. More or less, the materials have not yet been placed on their new shelfes at our main library. Now we’re just waiting to get rid of all the empty shelfes, and getting the new furniture for our students. More than 220 square meters for them! The students are looking forward to it, the faculty are worried that it’ll get to cozy at the library, and that the students will be late for classes. Yay!

Is everything just nice and great? No. It is strange, even for the former ebook-coordinator at the royal library, to see all the empty shelfes. Print books and journals have a permanence, that communicatets solidity and symbolises the scientific progress and knowledge in a way that digital ressources simply cannot. At least to people who grew up in the last millenium.

Moving print materials from open to closed stacks also symbolizes the changing world of libraries. We have always been the keepers of knowledge, and paper was the tangible symbols of that knowledge. We know that our mission is to provide access to information, and we know that we are able to do that much more efficiently with digital than with print materials. But it feels profoundly strange to relegate a couple of hundred years accumulated knowledge to closed stacks.

I sincerely believe that this is the future. I believe that the students will get better service even if we move the print material. But it still feels strange.