1 2 3 | import ImageGrab img = ImageGrab.grab() img.save('arkadian.png','PNG') |
A quick and easy way to take a snapshot of your current window.
You can always use JPG, but the quality is better in PNG.
Works in Windows and requires PIL.
1 2 3 | import ImageGrab img = ImageGrab.grab() img.save('arkadian.png','PNG') |
A quick and easy way to take a snapshot of your current window.
You can always use JPG, but the quality is better in PNG.
Works in Windows and requires PIL.
Here is a very simple python script that marges two pdf files, using the pyPDF library.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import os.path import pyPdf pdfOne = "C:\\a.pdf" pdfTwo = "C:\\b.pdf" merged = "C:\\c.pdf" if os.path.exists(pdfOne) and os.path.exists(pdfTwo): output = pyPdf.PdfFileWriter() pdfOne = pyPdf.PdfFileReader(open(pdfOne, "rb")) for page in range(pdfOne.getNumPages()): output.addPage(pdfOne.getPage(page)) pdfTwo = pyPdf.PdfFileReader(open(pdfTwo, "rb")) for page in range(pdfTwo.getNumPages()): output.addPage(pdfTwo.getPage(page)) outputStream = open(merged, "wb") output.write(outputStream) outputStream.close() |
For a while now, I have been thinking about putting together a video surveillance system at home, based on linux, webcams and python. I’m aware that out of the box systems exist, but I wanted to create something more personalised, which, let’s face it, it’s more fun!
After reading a bit online, I decided to use a command-line tool to grab frames from my webcams. There is a little program called “streamer” which allows you to save frames from the various webcams as jpegs (or videos if you like). In ubuntu type
sudo apt-get install streamer
to install it and then something like:
to take a snapshot of whatever dev/video1 is looking at… (look at streamer –help for more options).streamer -q -c /dev/video1 -b 32 -s 1600×1200 -o outfile.jpeg
My python script will be checking for new jpegs on a regular basis and will be uploading them on a remote ftp server. The complete python script will (hopefully) follow shortly.
Eli Bendersky has three interesting posts on plotting data with Python and matplotlib:
matplotlib-plotting-with-python
matplotlib-with-wxpython-guis
matplotlib-with-pyqt-guis
Thanks for sharing Eli!
With the arrival of the iPads, we’ve been changing many of our processes in order to put information on the fingertips of our senior mgmt team. Our key app right now is Dropbox and we convert most of the files to pdf.
Dropbox is a great little tool, as it enables us to update files on the fly. As it stands right now though, it is not suitable for wide corporate use for 3 reasons.
The first reason is that it doesn’t have a central admin point. For example, I can share folders with my contacts, and my contacts can share folders with others. Ideally, you need a service where access management is controlled centrally. If an employee leaves, we don’t want him/her to be able to access confidential data.
The second reason is that you cannot save the dropbox folder on the company network. To bypass the access mgmt control issue, my original plan was to set up a pc with dropbox and save the dropbox folder in one of our network drives. That would allow our colleagues to save files directly in specific folders (within the dropbox folder, saved in our network). This problem was solved by writing a simple sync script in python that synchronises various folders and files from our network with the dropbox folder which is located on a single machine. This solution turned up to be a better solution in the end as I managed to pick up a lot of files from their original network locations and sync them with the local dropbox folder, meaning that most of my colleagues kept saving their files as normal and minutes later these files would appear on the various ipads. A simple python script allowed us to avoid installing dropbox on every pc and creating an administrative nightmare for ourselves!
The third reason is that, due to the way dropbox saves files in a remote cloud, we don’t quite control our files. This can be addressed with a corporate company-owned dropbox server.
By having a single pc with drobox installed and a python script that syncs the files every couple of minutes, we created a practical configuration that allows our senior mgmt team to access the files they need on their ipads, without having to install dropbox on various machines, create accounts, share folders and create an admin nightmare for ourselves.
Gnuplot is a great command line tool that creates very quickly graphs from data files.
The official site of Gnuplot is: http://www.gnuplot.info/ . To see examples of graphs produced by Gnuplot, you should have a look here: http://gnuplot.sourceforge.net/demo_4.4/.
Using python and gnuplot, I produced approx 80 graphs similar to the one below, that fitted nicely on 5 A4 pages. 
Python scans a very long file with all the historical data and passes the required data for each graph to gnuplot. The result is 80 graphs as png files in less than a minute. Then another script in processing puts everything together in a 5 page pdf file (2 cols x 8 rows = 16 per page). AutoHotKey is what “glues” everything together and makes this a “single click” solution.