3 ms·
Raspberry Pi camera – script to back up images to my server
- atum47 5y agoI wrote this simple python script to automate the backing up of the generated images to my server. I'm not using rsync or scp cause I don't want my keys on the PI, cause it can be stole. I'm using a sqlite3 DB to keep track of each file that was already uploaded so it won't be upload again. this week I'll need to make a glass | acrylic enclosure to install the camera on the site and start capturing images for my time lapse. first video here: https://www.youtube.com/watch?v=ArZ-almMSxQ https://www.youtube.com/watch?v=ArZ-almMSxQ
- atum47 5y ago#!/usr/bin/python3 import os import glob import requests import sqlite3 from dotenv import load_dotenv load_dotenv() passwd = os.getenv('PASSWD') url = os.getenv('URL') folder = os.getenv('FOLDER') images = sorted(glob.glob(folder + '*.jpg')) conn = sqlite3.connect('rpicamera.db') cur = conn.cursor() for image in images: image_name = image.replace(folder, '') row = cur.execute("SELECT id FROM uploads WHERE filename = '%s'" % image_name) if len(row.fetchall()) > 0: continue response = requests.post(url, files={'file': open(image, 'rb')}, data={'passwd': passwd}) if response.json(): print("Error uploading '%s'" % image_name) continue cur.execute("INSERT INTO uploads (filename) VALUES ('%s')" % image_name) print("'%s' uploaded" % image_name) cur.close() conn.commit() conn.close()
- atum47 5y agofirst test end to end: https://www.youtube.com/watch?v=kw9DmxiPdhg https://www.youtube.com/watch?v=kw9DmxiPdhg