#!/usr/bin/python import os from ftplib import FTP import time import imageFilter picture_dir = '/home/olpc/olpc/' # location on your computer to store the images ftp_url = 'earobinson.org' # ftp url ftp_name = 'use your ftp name' # ftp user name ftp_pw = 'use your ftp password' # ftp password verbose = True ftp_dir = '/files/olpc/' # Location in the ftp to store the files def take_webcam_picture(filename): if verbose: print 'Taking a webcam picture' os.system('gst-launch-0.10 v4l2src ! ffmpegcolorspace ! pngenc ! filesink location=' + filename) def connect_to_ftp(url, user, pw): if verbose: print 'Connecting to ftp' ftp = FTP(url) ftp.login(user, pw) return ftp def disconect_from_ftp(ftp): if verbose: print 'Disconnecting from ftp' ftp.quit() def send_file(ftp, filename): if verbose: print 'Copying file to ftp' #ftp.retrbinary('/tmp/a.png', open('a.png', 'wb').write) filename_split = filename.split('/') fid=open(filename,'rb') ftp.storbinary('STOR '+ftp_dir+filename_split[len(filename_split) - 1], fid) fid.close() def main(): mostly_white = True attempt_number = 0 while mostly_white: picture_name = str(time.time()) + '_' + time.asctime(time.localtime()).replace(' ', '_') + '_' + str(attempt_number) + '.png' picture_filename = picture_dir + picture_name print picture_filename # Take picture take_webcam_picture(picture_filename) mostly_white = imageFilter.check_mostly_white(picture_filename) if mostly_white: os.remove(picture_filename) attempt_number = attempt_number + 1 if False: # Connect to FTP ftp = connect_to_ftp(ftp_url, ftp_name, ftp_pw) # Copy Picture to FTP send_file(ftp, picture_filename) index_filename = picture_dir + 'index.html' fid = open(index_filename, 'w') fid.write('
Image Updated: '+picture_name.replace('.png', '').replace('_', ' ')+'
List All Pictures -- Display All Pictures') fid.close() # Copy index to FTP send_file(ftp, index_filename) # Disconect from FTP disconect_from_ftp(ftp) os.remove(picture_filename) if __name__ == "__main__": main()