Created
October 15, 2012 21:37
-
-
Save brainstorm/3895708 to your computer and use it in GitHub Desktop.
Timelapse experiment with cheap hardware (efikamx and benq old (web)camera)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import flickrapi | |
import datetime | |
import os | |
import shutil | |
import subprocess | |
api_key = 'SETME!!!' | |
api_secret = 'SETME!!!' | |
def upload_webcam_pic(src): | |
''' | |
Uploads the webcam picture from a path "src" | |
''' | |
f = flickrapi.FlickrAPI(api_key, | |
api_secret, | |
store_token=True) | |
try: | |
f.auth_checkToken() | |
except flickrapi.FlickrError: | |
print "Ooops" | |
fname = _now()+".png" | |
shutil.copy(os.path.join(src, "00000001.png"), | |
os.path.join(src, fname)) | |
f.upload(os.path.join(src,fname), tags='''timelapse''', is_public=0) | |
_purge_pic(os.path.join(src,fname)) | |
def get_webcam_pic(dst): | |
''' | |
Gets a single frame from the webcam | |
''' | |
subprocess.check_call(["mplayer", "-nosound", "-vo", "png:outdir="+dst, "-frames", "1", "tv://"]) | |
def _purge_pic(target): | |
os.remove(target) | |
def _now(): | |
timestamp = datetime.datetime.utcnow() | |
return str(timestamp)+'Z' | |
if __name__ == "__main__": | |
get_webcam_pic("/tmp") | |
upload_webcam_pic("/tmp") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment