Why I’m Moving to a CMS

For those of you who have been following the adventures of the #digimeth community here at the University of New Mexico, it should come as no surprise that I’ve been doing an awful lot of coding. The truth is that I don’t mind; there’s a kind of simple elegance to making useful code that does what I want it to do, and I can enjoy the act of creation when writing code like that.

The problem comes when not all code is like that. I’m not talking about the part where one wrestles with the code to make it do what one wants it to do, nor even the part where it’s difficult to integrate one part of one’s code with another part. I’m specifically speaking to the difficulties of maintaining code once it has ceased to be on the front burner. I’m talking about all of the ridiculous changes that need to be made just to move a collection of web pages to a subdirectory. Hand-coded websites are great and they show a dedication that is worthy of recognition, but let’s face it; if one is going to maintain a hand-coded website, it is highly unlikely that one will have the time to do anything worthy of mention on that website.

DrupalIt’s for this reason that I’ve decided to move justinlarsen.net to a web content management system called Drupal. The fact is that I’ve been so impressed with the way that the folks over at Reclaim Hosting have integrated WordPress (what you’re reading now) that it only makes sense to shift a few things around and install another piece of software designed to make life a lot easier, at least as far as upkeep is concerned.

I do, of course, understand the value of making people learn to code their own HTML, and I believe that there is a great deal to value about doing things the hard way at first. Once that lesson is learned, however, it stands to reason that we should not reinvent the wheel. More importantly, there are a number of things one can learn from using content management software that one can’t learn when one is elbows-deep in angle brackets and hrefs. As this is the kind of software most of us will use once we leave the context of the course, it stands to reason that gaining experience with this software would have a real benefit. It’s also important conceptually; the way that CMS systems handle processes like publishing and editing is different in important ways from the methods we’ve used to simply upload text files.

Thus, sometime in the next two weeks I’ll be backing up everything (including this blog) and converting over to the new system. The truth of the matter is that I’ll be doing nothing much over the Christmas holiday, anyway; this should keep me occupied for at least a little while. I’ll document how it all goes here, of course, too.

Encode This!

What is simultaneously a terrifically frustrating programming language to learn and a nigh-unredeemable horror flick starring Robert Englund (but without the really cool razorglove)? Give up?

It’s Python…er…Python!

The truth is, it’s not usually so bad. I’ve had much worse times learning things like VisualBasic and C++, so I guess I shouldn’t complain.  I’m just frustrated because I don’t have time to deal with something piddly like this: I have to figure out how to change the encoding on my files so I can use extended characters.

Why, you ask? Well, as I’m working with Old English in my webscraping/topic modeling project, I need to process texts that use characters that have disappeared from the language, specifically Æ (ash), Þ (thorn), and Ð (eth).  I also need to support both upper and lower case versions of these letter forms.  In the good news department, ᚹ (wynn, apparently not supported here, either) has already been converted to W in the source files I’ll be using.

So what now?  Well, I get to run a bunch of functions in Python that look like this:

def add_ash(input):
output = re.sub('&aelig', 'æ', input)
return output

The problem, of course, is that Python itself only supports ASCII in its base form, meaning it only understands about 128 characters natively (a move that I understand since the language is designed to be useful and low-overhead); I have to figure out how to change the encoding to UTF-8 or somesuch.

I honestly have no idea WHAT I need to change the encoding in (the entire script? the Python environment itself? Time and Space, perhaps?), nor how to go about doing so.  All I know is that the word “þæt” should not come out looking like “þæt” when I dump my data into Mallet.

Scraping Web Pages (But Not Off of the Kitchen Floor)*

Baby Steps by marisag on Flickr

Baby Steps by marisag on Flickr. Creative Commons license

Okay, so this is going to be a middle-of-the-process post as I attempt to make something useful using Python.  Specifically, I’m working on learning how to scrape web pages for content without going crazy or devoting more time to such a project than I would already use simply by going to each of these web pages and manually copying and pasting the text.  I say that it’s the middle of the process because I’ve already done some of the work (success!), although there’s still a lot to do and several technological problems to overcome first (not-yet-failures).

First, though, it’s probably a good idea for me to clarify the project so that I can talk lucidly about what I have not yet done.

Ultimately, this scraping project is about getting some texts together so that I can create some useful topic models for my own research on the Exeter Book. I’ve mentioned before that the corpus of surviving Anglo-Saxon poetry is fairly limited; we have a mere 30,000 lines or so, and those lines exist, for the most part, in four collections: the Junius Manuscript, the Vercelli Book, the Nowell Codex, and the Exeter Book.  Each of these books has been published several times, both as complete collections and as editions of individual poems.  This presents a problem insofar as the creation of topic models are dependent on great numbers of texts which, in this case at least, are not extant.

Well, the best thing I can do is work with what I have.  Jessica came across a pretty good source for the texts online, too: http://www.sacred-texts.org/neu/ascp/ seems to be pretty okay, and the fact is that I’m not at a point in the semester where I can go through and check their editing job, anyway.  This site certainly meets one criterion, though: the text isn’t bogged down with a lot of other material.  With relatively straightforward HTML, then, I should be able to scrape away with no issues!

With that in mind, I needed to develop a plan with definable goals so I could start getting done what needs to get done.  I came up with the following list of steps:

  1. Scrape the URLs of the child pages from the landing/parent page
  2. Remove the small number of unwanted URLs from the results
  3. Scrape the child pages
  4. Write the “scrapings” to a text file
  5. Profit!

So far, this is what I’ve done:

  1. Toss my current Python environment and start running Linux
  2. Install BeautifulSoup and a few other modules into Python
  3. Scrape the URLs of the child paes from the landing/parent page
  4. Write the scraped URLs to a text file

The first step was a little more work than I really wanted it to be; I’ve been running Python inside a Linux-like environment on Windows called Cygwin, but that has started to be more trouble than it’s worth.  For example, every tutorial I read on BeautifulSoup told me to start the script with the line

from bs4 import BeautifulSoup

The problem there is that Cygwin’s version of Python needed something different, specifically:

from BeautifulSoup import BeautifulSoup

I arrived at this information through extensive trial and error, not through any documentation, which is a real problem in Cygwin, it seems, because there are other differences in Python, as well, such as the use of module names written in camel-caps (capitalizing the first letter of the second word instead of using a space or underscore) instead of the otherwise-universally used underscore method of calling modules.  There needed to be a better way.

Indeed there was; rather than give up on Linux and its advantages for doing things in Python, and rather than continuing to suffer through the Cygwin problem, I decided to install Ubuntu on a flash drive and run from that.  This solution is great because it doesn’t wipe my hard drive at all, it doesn’t cause any problems as far as compatibility is concerned (as Windows or Cygwin do), and this way I get to play with Linux while scraping away.

Once in my new environment, I was happy to see that I could install and run the various necessary modules with the same common commands listed in much of the documentation we’ve seen linked in class.  The next problem would be to use the modules to scrape the code from the parent page.  Cobbling together code from two or three tutorials, I ended up with a script that looks like this:

from bs4 import BeautifulSoup
import requests

url = "http://www.sacred-texts.org/neu/ascp"
r  = requests.get(url)
data = r.text
soup = BeautifulSoup(data)

for link in soup.find_all('a'):
	address_text = link.get('href')
	target = open("target\targetURLs.txt", 'a')

This worked straight off the bat.  It also provided me with a text file of the results, which means that I can go through and manually clean up the two or three additional links that I don’t need to follow when building my catalog of Old English poetry.

There you have it.  My next goal is to learn how to read through the text file and load each line into a loop so that it can function as a full URL.  Then it’s off to scraping to another file and ultimately to cleaning up the text, although I may have a lead on the latter that will make things a lot easier, even it it is a little bit like cheating.  More later!

*In case you’re wondering, the title is a reference to one of the recent cartoons that marks the triumphant return of Homestar Runner, or in this case, the triumphant return of Strong Bad and the Cheat making music videos.

I just put a new portfolio project idea on the map

I just put a new portfolio project idea on the map

No, the jokes don’t get any better than that.

For those of you who don’t know, I’m working with the Exeter Book for my dissertation, which is a remarkable privilege and something that I hope I don’t hate doing after this whole process is over. As a result, I guess it’s a surprise to no one that I try to apply new digital tricks to what I read in the Book, and I think I may have finally found a way to make the study of KML worthwhile to me.

I’m going to try and map out the travels of Ƿidsið (“Widsith”).

The very name “Widsith” means “wide(ly) travel(ed),” which is as apt a description as one can give of the main character in the Anglo-Saxon poem. As a traveling scop, Widsith travels and performs in numerous courts and halls, but he never stays put for long.  The poem itself is a catalog of these visits, often giving names of the tribe and their leader.  My proposed mapping project will be to collect as much information about places mentioned in the poem and then place that information on a map in order to get a clear idea of the scope of his wanderings.

This really will be a great deal of work as there are a lot of locations, I’ll be doing a lot of normal, everyday research for it, such as digging in books or on the web for good information, but I’ll also be doing a great deal of research into the use of QGIS and KML, too.  It’s entirely possible that doing all of that work might very well end up creating nothing interesting, but I think something else will happen: it will make for a very interesting map once the research has been done and I have a set of coordinates for each of the kingdoms in the list.

Now who wants to help me learn how to run the necessary software?