This is a re-post of the article that got lost when I dumped my personal blog. I thought it was of value so I am reposting it now.
The past week or so, I have been playing around with the APIs of a site called RolePlayGateway through Python. This blog post will be all about those APIs and how to work with it using Python. In this blog post I am going to assume you have some coding knowledge, Python is not hard to understand so anyone with a decent coding background would be able to read the following example. Keep in mind I am not a genius and some of this code could probably have written in a better way. Feel free to show me how in the comments section!
My experience with the API is great. I am working directly with the owner of the site, Eric Martindale, who is actively maintaining RolePlayGateway. Actually accessing and manipulating XML in python was easier then I thought it would be and bringing it into practice was a lot of fun. With a bit of creativity you can do a whole lot with the API of RolePlayGateway. In this blog post though, I will only be covering how to access the API through Python and working in the Python Interpreter.
Of course, If you want to work with the APIs, you will have to know where to look. In my case (as stated above) I worked directly with Eric who told me about the APIs. The following APIs are available on the site:
Through these APIs you can retrieve information and use that in your Python application.
To retrieve the XML from the site I used a module called “urllib”. This module has to do with urls, but the only function we’ll be using is urllib.urlopen(url). Then we’ll need something to parse the XML, this is done using the module “xml.dom.minidom”. Below is a link to the code of the full example I will be using.
If I would run this through the Python Interpreter I would get the following output.
As you can see in the example , Unicode / ASCII is a small issue you will have to keep in account. I found / edited a “translations” module that I use to edit names from Unicode to ASCII as the URL will require ASCII but the actual site will show Unicode.
I really like the APIs that Eric showed me, and he keeps adding more / refining it actively. I personally am still working on an application with these APIs that might be considered useful by the community. I hope this article was of use to some of you, others might have just enjoyed the read and some might have even thought “Oookay?”, But I tell you, these APIs are great!