#/bin/env python#-*-coding:utf=8-*-ImportOs,time,subprocess,shlexImportUrllib2defUpload_yeelink (Image_name, log_file):#upload URL of your own deviceURL ='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 notos.path.exists (Images_path): Os.makedirs (images_path) com_line='fswebcam-d/dev/video0-r--bottom-banner--title "%s"--no-timestamp%s/%s.jpg' whileTrue: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)PrintCom_line_now Time.sleep (11)
Code from: Https://github.com/coolbit-in/yeelink_photos_upload
[Reprint] Upload images to yeelink using Python