Tools

Content tools for WordPress

Three custom tools for managing content in WordPress: XML import,

2 min read

Before getting into systems administration, I spent a lot of time publishing content for clients, and a good part of that work was repetitive: copying events from a website, pasting them into WordPress, re-entering the date, category, and image. Out of that came three tools that saved me hours every week.

From the city council website to XML

The first piece is an agenda extractor. Several city councils (Arenys de Mar, el Masnou, Premià de Mar) publish their event calendars online, and I had to collect them every week. I built an application with Tkinter (a Python library for creating windows), where each municipality has its own extraction module and its own JSON configuration file (a text format for parameters): using requests and BeautifulSoup—two libraries for reading web pages—it downloads the calendars and outputs them in XML (a data exchange format using tags). A collapsible log panel—the journal of each execution—shows what happened during each extraction, which turns out to be more useful than it seems when a website changes its structure.

From XML to WordPress

The second tool takes that XML and publishes it directly into WordPress using its REST API (the entry point that allows creating content from the outside). What gave me the most trouble were the dates: they came in plain text and in Catalan, like "del 15 de juliol" ("from July 15"), and I had to map them to the format WordPress expects. There's also a field and category mapping step, since each source had its own. My first attempt was a single monolithic script—I still keep it in the repository under the name "proceso-archivo inicial sin modular.py"; when I reopened it months later, I split it into modules: interface, functionalities, field mapping, and category mapping.

The bookmarks manager

The third tool is the only one that lives inside WordPress. It's a plugin (an extension installed on the content management system), in a single PHP file: not a snippet like the ones in How to remove admin menu items with Code Snippets, but a full-blown piece. It creates a "Bookmarks" content type: you paste in a URL (the address of a page) and the plugin extracts the title, description, and favicon—the site's small icon, converted to JPG for storage—and generates the slug (the short address) from the domain. I used it to maintain a reference library without depending on browser bookmarks.

What I'd do differently today

I'd add tests from day one: when a website changes its HTML, the extractor notices because it finds nothing, but it doesn't tell you exactly where things broke. And I'd separate each municipality's configuration even further from the code, because in practice that's where changes were needed almost every month. Even so, the three tools did what they were supposed to do: making sure the content reached WordPress on its own.