Posts: 17
Joined: Thu Oct 18, 2012 2:52 pm


Mon May 14, 2018 4:09 pm

Currently I'm running a Python program to capture an image every 5 minutes and upload a photo on the hour which uses crontab to run every 5 minutes.

As most of the program only needs to be run once I thought about using a loop in Python instead and this is what I have come up with. My concern at the moment is having to use camera.capture twice, is there a better way of saving the same image to 2 places?

Also is there a better way of achieving what I am doing?

Code: Select all

#!/usr/bin/env python
import picamera
import time
import tweepy
from datetime import datetime

mydir = '/var/www/'
photo_path = mydir+'webcam.jpg'

# Consumer keys and access tokens, used for OAuth
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''

# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

# Creation of the actual interface, using authentication
api = tweepy.API(auth)

while True:
    now =
    timeInfo = now.strftime('%d/%m/%y %H.%M')
    timestamp = now.strftime('%H:%M')
    if now.minute % 5 == 0 and now.second <= 10:
        with picamera.PiCamera() as camera:
            camera.resolution = (1280, 1024)
            camera.annotate_background = picamera.Color('black')
            camera.annotate_text = timeInfo
            # Take a picture including the annotation
            camera.capture(mydir + 'webcam/webcam' + timestamp + '.jpg')
        if now.minute <= 4:
            status = 'Weather #Yeovil: ' + timeInfo
            api.update_with_media(photo_path, status=status)
Last edited by mfraser on Sat May 19, 2018 2:22 pm, edited 1 time in total.

Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6053
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Timelapse

Mon May 14, 2018 4:37 pm

Just copy the file? Two seconds with Google gave ... -in-python

Code: Select all

from shutil import copyfile
copyfile(photo_path, mydir + 'webcam/webcam' + timestamp + '.jpg')
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Posts: 17
Joined: Thu Oct 18, 2012 2:52 pm

Re: Timelapse

Sat May 19, 2018 2:33 pm

I had seen copyfile from shutil, but wasn't sure if it was suitable for the job. Now using it.

Many thanks.

Return to “Camera board”