weather-twitter.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:snapshot-twitter 作者: helioloureiro 项目源码 文件源码
def GetPhoto(f = None, quality = None):
    """
    Photo aquisition
    """
    global filename, FAILCOUNTER, error_tries

    debug("GetPhoto: failcounter=%d" % FAILCOUNTER)
    if FAILCOUNTER < 0:
        print "Fail counter reached maximum attempts.  Failed."
        debug("Trying to return a failed img.")
        filename = getfailedimg()
        if not filename:
            sys.exit(1)
        debug("Using failed img: %s" % filename)
        # it needs to be 0ed or it will fail
        FAILCOUNTER = 0
        return 0
    filename = None
    debug("Camera init")
    camera = PiCamera()
    debug("Camera start")
    camera.start_preview()
    time.sleep(10)
    #if not os.path.exists(SAVEDIR):
    #    os.makedirs(SAVEDIR)
    year = time.strftime("%Y", time.localtime())
    month = time.strftime("%m", time.localtime())
    if not os.path.exists("%s/%s/%s" % (SAVEDIR, year, month)):
        os.makedirs("%s/%s/%s" % (SAVEDIR, year, month) )
    if not f:
        timestamp = time.strftime("%Y-%m-%d_%H%M%S", time.localtime())
        filename = "%s/%s/%s/%s.jpg" % (SAVEDIR, year, month, timestamp)
    else:
        filename = f
    debug("Saving file %s" % filename)
    camera.capture(filename)
    camera.stop_preview()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号