How to delete messages from Gmail using python IMAPclient ?

Google does not delete all messages at once according to
So, first, you have to delete messages in each folder:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from imapclient import IMAPClient

client = IMAPClient('', use_uid=True, ssl=True)
client.login('', 'password')

folders = [
    '[Gmail]/Sent Mail',

for f in folders:
    fold = client.select_folder(f)
    res = client.delete_messages(
    res = client.expunge()

#Google automatically will move deleted messages to "All Mail" folder. 
#Now we can remove all messages from "All Mail"

client.select_folder("[Gmail]/All Mail")
client.set_gmail_labels(, '\\Trash')

More information on how to work with Gmail using python IMAPClient can be found directly at
Read the source code, Luke 🙂

Simple site pinger

This simple script pings your websites and notifies when a website is down.
It’s written in python >= 2.5 and might be usefull for administrators and programmers.
Some parts of it was found somewhere in the internet and adjusted a bit for my needs.

Required packages can be installed easily from repository ( Ubuntu example ):

sudo apt-get install python-notify

or using pip/easy_install as well

sudo pip install notify

Running this script from command line is a bit annoying so I put to run it by crontab each 30 min:

$ crontab -e
*/30 * * * * DISPLAY=:0 /usr/bin/python /home/vs/bin/

Note that you need to set DISPLAY option to make notification visible for current X session.

#!/usr/bin/env python
from threading import Thread
import subprocess
from Queue import Queue
from pynotify import *

num_threads = 4
queue = Queue()
hosts = [
#wraps system ping command
def pinger(i, q):
    """Pings subnet"""
    while True:
        host = q.get()
        #print "Thread %s: Pinging %s" % (i, host)
        ret ="ping -c 5 %s" % host,
                        stdout=open('/dev/null', 'w'),
        if ret == 0:
            #print "%s: is alive" % host
            init("Server checker")
            msg =  "%s: did not respond" % host
            Notification("Server checker", msg).show()
#Spawn thread pool
for i in range(num_threads):

    worker = Thread(target=pinger, args=(i, queue))
#Place work in queue
for host in hosts:
#Wait until worker threads are done to exit