How to remove ‘lastsaid’ history and chat logs from Pidgin

Turning on History plugin in Pidgin will insert the last conversation into your current conversation. All this lastsaid entries can be found somewhere inside of blist.xml file which is located in your Pidgin conf directory (/home/username/.purple directory in GNU/Linux (not sure about where it is in MS Windows though)).

This is convinient if you want to view what was written before you accidentialy closed the chat window or if you forgot what were you last talking about with someone and if you want that information quickly. But, it is not convinient at all if you want to wipe it along with chat logs since lastsaid entries are at a different location and are not the only entries that can be found in blist.xml so you can’t just remove that file either. If you use a couple of protocols and have more than just a few buddies, removing lastsaid lines from blist.xml manually would probably prove to be pain in the ass.

So, what every curious programmer does in case he doesn’t have a feature he wants/needs? – He just makes it. :D Since I started playing with Python, I decided to create a small py3k script I could use every once in a while to completely wipe both lastsaid history and chat logs from Pidgin.

What you need to do to make this script work is – you need to put it into your Pidgin conf directory (just put it into a file called something.py) and after that just run the script (you need to have python installed on your machine to run this script).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#! /usr/bin/env python3
import xml.etree.ElementTree as etree
import shutil
import os

# deletes 'lastsaid' blist.xml entries
if os.path.exists("blist.xml"):
   tree = etree.parse("blist.xml")

   buddies = tree.findall(".//buddy")      
   for buddy in buddies:
      nodes = buddy.findall("setting")    
      for node in nodes:
         if node.attrib == {"type": "string","name": "lastsaid"}:
            buddy.remove(node)

tree.write("blist.xml")


# deletes chat log files if they exist
if os.path.exists("logs"):
   shutil.rmtree("logs")

I hope this helps. Also, if you have any questions/problems with the script, feel free to drop a comment..