
import sys
import time
import picamera
import settings
from settings import IMAGE, SNAP
import uploader


def main():
    with picamera.PiCamera() as camera:
        camera.resolution = (IMAGE.resolution_x, IMAGE.resolution_y)
        time.sleep(2)
        output_file = settings.IMAGES_DIRECTORY + '/img{counter:03d}.jpg'
        capture = camera.capture_continuous(output_file, quality=IMAGE.quality)
        for i, _ in enumerate(capture):
            if i == SNAP.total - 1:
                break
            time.sleep(SNAP.interval)


if __name__ == '__main__':
    while True:
        main()


import time
import picamera
from settings import Job, IMAGES_DIRECTORY


def main():
    job = Job()
    if job.exists():
        resolution_x = job.image_settings.resolution_x
        resolution_y = job.image_settings.resolution_y
        image_quality = job.image_settings.quality
        snap_interval = job.snap_settings.interval
        snap_total = job.snap_settings.total
        with picamera.PiCamera() as camera:
            camera.resolution = (resolution_x, resolution_y)
            time.sleep(2)
            output_file = IMAGES_DIRECTORY + '/img{counter:03d}.jpg'
            capture = camera.capture_continuous(output_file, quality=image_quality)
            for i, _ in enumerate(capture):
                if i == snap_total - 1:
                    job.archive()
                    break
                time.sleep(snap_interval)


if __name__ == '__main__':
    while True:
        main()

Check for job in main loop
Check for job in main loop

  
- import sys
  import time
  import picamera
+ from settings import Job, IMAGES_DIRECTORY
- import settings
- from settings import IMAGE, SNAP
- import uploader
  
  
  def main():
+     job = Job()
+     if job.exists():
+         resolution_x = job.image_settings.resolution_x
+         resolution_y = job.image_settings.resolution_y
+         image_quality = job.image_settings.quality
+         snap_interval = job.snap_settings.interval
+         snap_total = job.snap_settings.total
-     with picamera.PiCamera() as camera:
+         with picamera.PiCamera() as camera:
-         camera.resolution = (IMAGE.resolution_x, IMAGE.resolution_y)
+             camera.resolution = (resolution_x, resolution_y)
-         time.sleep(2)
+             time.sleep(2)
-         output_file = settings.IMAGES_DIRECTORY + '/img{counter:03d}.jpg'
+             output_file = IMAGES_DIRECTORY + '/img{counter:03d}.jpg'
-         capture = camera.capture_continuous(output_file, quality=IMAGE.quality)
+             capture = camera.capture_continuous(output_file, quality=image_quality)
-         for i, _ in enumerate(capture):
+             for i, _ in enumerate(capture):
-             if i == SNAP.total - 1:
+                 if i == snap_total - 1:
+                     job.archive()
-                 break
+                     break
-             time.sleep(SNAP.interval)
+                 time.sleep(snap_interval)
  
  
  if __name__ == '__main__':
      while True:
          main()
  
Check for job in main loop
## Code Before:

import sys
import time
import picamera
import settings
from settings import IMAGE, SNAP
import uploader


def main():
    with picamera.PiCamera() as camera:
        camera.resolution = (IMAGE.resolution_x, IMAGE.resolution_y)
        time.sleep(2)
        output_file = settings.IMAGES_DIRECTORY + '/img{counter:03d}.jpg'
        capture = camera.capture_continuous(output_file, quality=IMAGE.quality)
        for i, _ in enumerate(capture):
            if i == SNAP.total - 1:
                break
            time.sleep(SNAP.interval)


if __name__ == '__main__':
    while True:
        main()

## Instruction:
Check for job in main loop
## Code After:

import time
import picamera
from settings import Job, IMAGES_DIRECTORY


def main():
    job = Job()
    if job.exists():
        resolution_x = job.image_settings.resolution_x
        resolution_y = job.image_settings.resolution_y
        image_quality = job.image_settings.quality
        snap_interval = job.snap_settings.interval
        snap_total = job.snap_settings.total
        with picamera.PiCamera() as camera:
            camera.resolution = (resolution_x, resolution_y)
            time.sleep(2)
            output_file = IMAGES_DIRECTORY + '/img{counter:03d}.jpg'
            capture = camera.capture_continuous(output_file, quality=image_quality)
            for i, _ in enumerate(capture):
                if i == snap_total - 1:
                    job.archive()
                    break
                time.sleep(snap_interval)


if __name__ == '__main__':
    while True:
        main()
