Linux Windows Usage Surveillance in Python

Lets say you want to keep track of a computers usage, for remote working. It should deliver hourly shots of computer usage to an email address that you’ll give it. It will also deliver screen shots every 2 minutes, but you can choose whether it does that or not!

Part 1: Python Screen Capture
Part 2: Python Emailer
Part 3: Setting up the schedule

Part 1: Python Screen Capture


  • Python2.4 or greater
  • Windows or Linux based OS
  • On Windows, you’ll need to get Python Image Library
  • On Linux, you’ll need to have mogrify, which comes as part of ImageMagick.

If you don’t have it use your package manager to get it.

sudo apt-get install imagemagick

The screen module:
import os
import platform
import shutil
from config import launchCommand

def printScreen(filename):
“””prints the screen and saves it as the filename given”””
if platform.system()==’Windows’ or platform.system()==’Microsoft’:
import ImageGrab
img = ImageGrab.grab()
launchCommand(‘/usr/bin/xwd -display :0 -root -out %s’%filename)

def convertImage(filename, width=160, height=100):
“””Converts the image found in filename to one of the dimensions given. returns a gif filename”””
if platform.system()==’Windows’ or platform.system()==’Microsoft’:
import Image
im1 =
im2 = im1.resize((width, height), Image.NEAREST)‘%s.gif’%filename)
launchCommand(‘/usr/bin/mogrify -format gif -resize %sx%s %s’%(width, height, filename))
return ‘%s.gif’%filename

def removeImage(filename):
“””removes the imagename given”””

def copyFile(source,destination):
“””copys a file from source to destination”””
shutil.copyfile(source, destination)

def grabScreen(filename, width=160, height=100):
“””given a filename, width and height, grabs a screen shot of the current desktop,
scales it to the sizes passed in (default 160×100) and saves it to the filename given”””
tmpName = ‘tmp_image’
imageName = convertImage(tmpName)
copyFile(imageName, filename)

Leave a Reply

Your email address will not be published. Required fields are marked *