Properly speaking, this should probably go under one of the script forums, or maybe the plugin forum, but since I won't know which without determining what approach is best, I guess I'll stick it here. :)
The situation is this:
I have a database of characters on my MUSH. Each entry has its own object, and each of those objects then have the necessary attributes for holding the information about each character.
I'd like to harvest this data from the MUSH in some way and compile it into some sort of standardized database format which I then can import into a web-based database to make it accessible that way too. Precisely what format it should go into isn't decided, however.
My first question, before I continue on to discuss anything else, is simply: does this sound doable? And if so, what would it likely take? A script (what language?), a plugin or ... something else?
This is easy enough, I have done it to collect item data, you just use Python with a MySQL library (whose name is on my other pc :/). But it's a few calls, I could look it up if you want.
When you get a chance, I'd love to see an example of how you do this. :)
Although, it sounds (since you use a mySQL library) as if you put the data straight into mySQL?
Since the mySQL db I'll be using isn't on the same server as the game, I probably won't be able to do a direct transfer. Also, I'll probably need to import the data into a pre-existing tabel structure (I will be using a blog/cms tool called Expression Engine to manage the database), rather than simply create a new one, which is why I was looking to put it into an importable format.
Hmm, I see. The MySQL server doesn't have to be on the same server as the game, you just have to be able to reach both from your machine. You could use one you setup locally or wherever you want. You can also use ActiveX to create databases, as demonstrated in one of Nick's plugins. You can use this for python: http://sourceforge.net/projects/mysql-python
Hrm, looks like I'll have to give this some more thought. :)
Basically, creating a database out of the data from the MUSH straight off isn't what I need. Instead, I need the data organized in a format that I can import into my already existing database. And preferably import into the structure created by Expression Engine.
Lets say, since I think EE can handle this through plugins, that I want the data from the MUSH put into a specific XML structure. Could I do this via a script or a plugin too? And could that be a single large document, or would each character need its own XML file?
Another option would be to create some kind of .csv file that EE can parse, I suppose.
What format is the database in now? Is it stored on your PC, or is it on the MUD?
Its on the MUSH. Format is homecooked (each 'entry' is an object with the 'fields' being attributes).
Ah, I see. Well then, you could store it as anything, csv, xml (using Python's XML module), MS access, mysql, anything you want.
Ah, okay. :)
Has there been any previous discussion anywhere on the forum that you know of how to go about grabbing data and storing it as csv or xml?
I am pretty completely clueless about doing any scripting from the ground up, but I have been known to occasionally be able to figure out how to modify existing scripts. ;)
Storing it as XML is not at all complicated, don't even think it warrants a discussion. Here's an example Python snippet for converting an internal representation (internal for the program this was used in) of a Mushclient trigger into its XML equivalent:
import xml.sax.saxutils as sax
def write_trigger(trig, section=1):
output = ""
if section: output = output + "<triggers>\n"
output = output + "<trigger\n"
for key in trig.keys():
if key == "send":
continue
output = output + " " + key + '="' + trig[key] + '"\n'
output = output + ">"
if trig.has_key('send'):
output = output + "<send>" + sax.escape(trig['send'], {'"':'"'})
output = output + r"</send></trigger>" + "\n"
if section: output = output + r"</triggers>" + "\n"
return output
def write_triggers(trig_list):
trigs = "<triggers>\n"
if type(trig_list) == type(list()):
for trig in trig_list:
trigs = trigs + write_trigger(trig, 0)
trigs = trigs + r"</triggers>" + "\n"
return trigs
As you can see - it's all about converting a Python dictionary into formatted text, escaping any special characters using xml.sax.saxutils.escape(), which is part of a standard distribution. Reading the data from the MUSH probably wouldn't be any more difficult - you'd just use triggers, convert the wildcards into a Python object, then convert the object to XML as above.