码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-04-05 23:14:45      阅读:249      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!