zoukankan      html  css  js  c++  java
  • [转载]使用python上传图片到 yeelink

    #/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 + '
    ')
    
    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

  • 相关阅读:
    数据库底层索引
    shell脚本
    备份还原ESXi 中的虚拟机快照
    docker proxy
    yum
    ubuntu系统更换源和apt命令参数
    前端BootStrap框架和django创建项目和app
    python之路5:常用模块
    python之路3:文件操作和函数基础
    python之路4:各种器
  • 原文地址:https://www.cnblogs.com/sn-dnv-aps/p/4394931.html
Copyright © 2011-2022 走看看