首页 > 编程语言 > 详细

[转载]使用python上传图片到 yeelink

时间:2015-04-05 23:14:01      阅读:354      评论:0      收藏:0      [点我收藏+]
#/bin/env python
# -*-coding:utf=8 -*-
import os,time,subprocess,shlex
import urllib2
def upload_yeelink(image_name, log_file):
    #自己设备的 upload url
    url = ‘http://api.yeelink.net/v1.0/device/XXX/sensor/XXXX/photos‘
    length = os.path.getsize(image_name)
    image_data = open(image_name, ‘rb‘)
    request = urllib2.Request(url, data=image_data)
    request.add_header(‘U-ApiKey‘, ‘14765d*********880398486d08f9c‘)
    request.add_header(‘Content-Length‘, ‘%d‘ % length)
    res = urllib2.urlopen(request).read().strip()
    log_file.write(res + ‘\n‘)

if __name__ == ‘__main__‘:
    images_path = os.path.join(os.getcwd(), ‘image‘)
    log = open(os.path.join(os.getcwd(), ‘output.log‘),‘w+‘)
    if not os.path.exists(images_path):
        os.makedirs(images_path)
    com_line = ‘fswebcam -d /dev/video0 -r 320x240 --bottom-banner --title "%s" --no-timestamp %s/%s.jpg‘
    while True:
        time_now = time.strftime(‘%Y-%m-%d-%H-%M-%S‘)
        com_line_now = com_line % (time_now, images_path, time_now)
        subprocess.call(shlex.split(com_line_now), stdout=log, stderr=log)
        upload_yeelink(‘%s/%s.jpg‘ % (images_path, time_now), log)
        print com_line_now
        time.sleep(11)

代码来自于 :https://github.com/coolbit-in/yeelink_photos_upload

[转载]使用python上传图片到 yeelink

原文:http://www.cnblogs.com/sn-dnv-aps/p/4394931.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!