Nov. 28th, 2019

alexwlchan: (face)
[personal profile] alexwlchan
I was chatting to [personal profile] cesy this evening, and we were chatting about tagging on Dreamwidth (because I've just written about how I use tags to organise my scanned documents). In particular, we were talking about ways to find posts with particular combinations of tags.

As far as we both know (please correct us if we're wrong!), you can only filter your posts by a particular tag. For example, to see all of my posts tagged with "meta", I'd visit https://alexwlchan.dreamwidth.org/tag/meta.

What if you want to search by more than one tag? For example:
  • Which posts have I tagged with reviews and quotes? (An AND query)

  • Which posts have I tagged with at least one of person:alex or person:lexie? (An OR query)
I decided to try writing a script for this.

I already had code that uses the XML-RPC API to get all my posts (to get a backup of my Dreamwidth entries). I added some extra filtering, and now it can search posts using the queries of the form above.

Usage

  1. You need Python installed (downloads page). Python 2.7 or 3.x is fine; if you already have Python installed on your computer, that should be fine.

  2. Copy the code below into a file, for example search_dreamwidth_posts_by_tag.py.

  3. Run the script with Python, for example by typing python search_dreamwidth_posts_by_tag.py in a terminal.
The script will ask you for your Dreamwidth username and password (to talk to the API), and what sort of tags you want to search for. It saves the results to a spreadsheet, for maximum nerd points.

Reusing the code

If you know a bit of Python, you should be able to pull out bits of this code and reuse it elsewhere -- the XML-RPC API client, downloading all your posts, checking a user's password. You could modify it to find posts by different criteria: posts within a particular date range, or posted at the weekend, or that don't contain the letter e.

MIT license.

The code

Code behind a cut tag )

Profile

dw_dev: The word "develop" using the Swirly D logo.  (Default)
Dreamwidth Open Source Development

July 2025

S M T W T F S
  12345
6789101112
13141516171819
20212223 242526
2728293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 26th, 2025 08:45 am
Powered by Dreamwidth Studios