<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Atomic Spatula &#187; python</title>
	<atom:link href="http://atomicspatula.com/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://atomicspatula.com</link>
	<description>Greg Nichols</description>
	<lastBuildDate>Mon, 30 Apr 2012 15:57:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Web Cam and Time Lapse</title>
		<link>http://atomicspatula.com/2009/01/28/web-cam-and-time-lapse</link>
		<comments>http://atomicspatula.com/2009/01/28/web-cam-and-time-lapse#comments</comments>
		<pubDate>Thu, 29 Jan 2009 03:34:28 +0000</pubDate>
		<dc:creator>greg</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://atomicspatula.com/?p=95</guid>
		<description><![CDATA[I&#8217;ve got a web camera attached to my Mac Mini. First, I wanted to set it up to take pictures out of my office window every 5 minutes or so, and upload them to this site. That might seem like a simple thing, but none of the easy-to-use Apple applications offered any help. With a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve got a web camera attached to my Mac Mini.   First, I wanted to set it up to take pictures out of my office window every 5 minutes or so, and upload them to this site.   That might seem like a simple thing, but none of the easy-to-use Apple applications offered any help.  With a little poking around, I found <a href="http://www.intergalactic.de/pages/iSight.html">isightcapture</a>, and wrote a short python script to call it every 5 minutes and ftp the resulting picture to my server.</p>
<pre>
while True:
    # take a picture
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    filename = "/tmp/pic-%s.jpg" % timestamp
    print "Say Cheese!"
    os.system('isightcapture -w 960 -h 720 %s' % filename)

    # upload it
    try:
        file = open(filename, 'r')
        print "uploading..."
        connection = ftplib.FTP('ftp.atomicspatula.com', 'henry@atomicspatula.com', 'password')
        connection.storbinary('STOR pic.jpg', file)
        file.close()
        connection.quit()
        print "done"
    except exception:
        print exception
    time.sleep(60)
</pre>
<p>This code writes timestamped pictures into /tmp, and uses it to upate a single file on the server.</p>
<p>With a nice sequence of pictures, I wanted to use QuickTime to make a nice time-lapse movie.  But QuickTime seems to require that the pictures all have the same name with a sequence number, such as  pic00001.jpg, pic0002.jpg, etc.   Why Apple couldn&#8217;t have just suck in all the pictures in the folder in alpha-numeric order is beyond me.   So, I wrote another little script to rename them:</p>
<pre>
rootdir = "/Users/henry/time-lapse"
files = sorted(os.listdir(rootdir))
i = 1
for file in files:
    print file
    shutil.move(file, "pic%.6d.jpg" % i)
    i = i  + 1
</pre>
<p>Tomorrow, I&#8217;m going to run it all day at 1 picture per minute, and see what that looks like at 15 fps.</p>
<p>Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://atomicspatula.com/2009/01/28/web-cam-and-time-lapse/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

