How to delete spam comments on your WordPress blog, with Python via the Wordress API

In this tutorial we’ll be covering how to delete all those spam comments you’re getting posted to your
blog using the wordpress api via it’s fantastic Python wrapper, python-wordpress-xmlrpc, and make sure you’ve enabled the XMLRPC API on your blog.

How this script works is that it pulls all the comments that are in the pending
queue and then if it contains any words from the list of words that are likely spam words,
like ‘ambien’ or ‘oakley’, then take care of by deleting or marking them as spam. Here’s the full PasteBin of the script, and as usual, it’s also included in full at the end of this post.
Nothing too tricky, let’s get started!

Continue reading

How to compile Libtcod and C++, mirrored from


So I was playing with the Doryen Library, aka libtcod, the other day.  What a fantastic little library.  I had just finished a small demo for displaying how influence maps works (more for my own education, as I’m a pretty inexperienced programmer and doing is how I learn) and was pretty pleased with the result.   I’m using Visual Studio Express because I use Windows and happen to like it a bit more than Code::Blocks.

Okay, so I don’t need that debug window anymore.  Go into the linker properties, specify the subsystem as Windows app, compile…. and BAM!

MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Sigil\VS\InfluenceMap\Debug\InfluenceMap.exe : fatal error LNK1120: 1 unresolved externals

Hmm, okay what’s going on here?  Check the libtcod documentation… no, there’s nothing here about this.  Why is this happening?

The answer to this lies in the way the program is run.  Before, I was compiling the program as a console app.  For this, the standard C++ entry point, main, was sufficient.

int main(int argc, char** argv)

But the moment I specified the program as a Windows application, the rules changed.  To use the Windows api, I need a Windows entry point, which is defined like this:

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

But the samples I’ve seen don’t define this entry point.  They define a standard main().  So what am I missing?  As it turns out, I’m missing SDL!

libtcod is an SDL library, and SDL has its own way of mapping main() to WinMain().  But in order to make this happen, you also need to link in SDL and pull in the SDL.h header.

Here’s how to set up a Visual Studio project with both libtcod and SDL.  You can then write and test your application using the console window, and when the time is right, switch to a native windows app without any issues!

Here’s the exact procedure I followed.

  1. Download and extract the libtcod library for Visual Studio to wherever you place your libraries.  In my case, I extracted it to C:\Sigil\VS\libs, which resulted in the folder C:\Sigil\VS\libs\libtcod-1.5.1.
  2. Download and extract the SDL development libraries for Visual Studio.  You want the latest one available, I used  I extracted it to C:\Sigil\VS\libs\SDL-1.2.14.
  3. Open Visual Studio Express.  Create an Empty project for your new libtcod application.
  4. Right click on your project in the Solution Explorer and select Properties.
  5. Go to Configuration Properties -> VC++ Directories.
  6. Click on Include Directories, and from the little drop-down box on the right, select <Edit…>
  7. Click on the little folder icon to add a new folder to your include directories, specify the directory for your libtcod library (for me, C:\Sigil\VS\libs\libtcod-1.5.1\include).
  8. Do the same for SDL (mine was C:\Sigil\VS\libs\SDL-1.2.14\include).
  9. Click OK.
  10. Now do the same for the Library Directories, specifying the folders for your libtcod and SDL lib directories.
  11. Now go to Configuration Properties -> Linker -> Input.  Click on Additional Dependencies, click on the drop-down box, select <Edit…>.  Add the following dependencies, one per line: libtcod-VS.lib, SDL.lib, SDLmain.lib.  Click on OK.
  12. There’s one final step left.  You need to pull in the main SDL header file.  At the top of your main file, add #include <SDL.h>

You’re now set!  Go ahead and develop your application as normal.  Whenever you’re ready (or just want to test it) you can set your linker to produce a native Windows application.  To do this, you need to go into the Properties windows again, and select Configuration Properties -> Linker -> System.  In the right-hand pane, click on SubSystem and select Windows (/SUBSYSTEM:WINDOWS) from the drop-down menu.

Build your application again, and you should now be enjoying some console-free Windows goodness!

Imgur API part 3: OAuth2

It’s been a while since I wrote the last one, but a user on reddit asked how to get OAuth working with Imgur, and I couldn’t resist giving it one more shot. Thanks to my recent experience with the Netflix API, even though it was in C# rather than in Python, I was able to wrangle a quick and easy script for getting started.

Here’s the PasteBin with the complete code, thought it’s shown at the bottom of the page, as usual. Continue reading

Netflix Catalog January update

Took a few  weeks off, first for school, and then for christmas. Back only a few days, and I’ve learned the basics about Cookies and Filters in ASP.NET MVC. They’re both pretty simple, even moreso than I thought. Instead of rewriting a lot of the stuff I read, I’ll just link to the StackOverflow answers that I used directly.

For the cookies, it’s here, where it shows both how to add and delete (via setting the Expiry of the cookie to yesterday) a cookie. I thought that was pretty neat. Basically all it is is a number that the browser stores, and then the server has to do something with that.

Which brings me to Filters, with a SO answer in two parts: Here and the offical docs, which are very surprisingly handy this time. Filters just run before and after certain events, like Authorization, Actions, Results and Exceptions. I’ve only played with “OnResultExecuting” which mean before the ViewResult has been finished being processed, since if I change the ViewBag in the filter, the returned view with contain the modified data.

Other than that, I’ve run into a strange issue which I’m really hoping to solve: the catalog index I got the from Netflix API is incomplete! It’s got about 56k titles on there, individual shows included as separate entries (something I still have to sort out) and I can’t find certain titles, like Dexter and The 4400, which are both available for streaming off I’ve made a post asking for clarification here but looking at the post, it seems like I’ll need to cross post into the “Help me” subforum, rather than the “API forum” forum.

My buddy is still working on the Rotten Tomatoes thing, which has taken a few months now. He hasn’t made much progress as far entering things into the database, but then I realized that without the huge /catalog/titles/streaming resource, I’d probably be in the same spot he is. I’ll have to remind him about the OMDB tool, and how we can just pull the RottenTomatoes data from there instead. Then it’ll be a matter of associating the Netflix movie with the RottenTomatoes movie. That’ll be tricky.

Anyway wanted to make a post here because  it’s been a while, and it doesn’t get any easier to write these. And although I now manage to get about 1000 people to the site a month, I realized 75%+ of them are here for the tutorials I have written. I really should keep working on those… If you ever have something you’d like to learn about, please hit me up!

You should follow me on twitter @tankorsmash to hear me complain about the official docs, or how All That Remains is dead