![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
I was chatting to
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:
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.
MIT license.
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
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 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
- 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.
- Copy the code below into a file, for example
search_dreamwidth_posts_by_tag.py
. - Run the script with Python, for example by typing
python search_dreamwidth_posts_by_tag.py
in a terminal.
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.