Skip to content

Commit

Permalink
Path defaults for log file and image directory
Browse files Browse the repository at this point in the history
The log file and images created byt the email_time_lapse app
default to creating them in the CWD.
  • Loading branch information
channingko-madden committed Dec 30, 2024
1 parent ac7a108 commit cacbc28
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ dmypy.json

# images
*.jpg

# ripgrep
.ignore
6 changes: 3 additions & 3 deletions apps/email_time_lapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def main(args: argparse.Namespace) -> int:

builder = rca.emails.HtmlImageBody(args.to, args.gmail, "Greetings!")

def send_callback(images: list[str]) -> None:
def send_callback(images: list[Path]) -> None:
"""
Callback function for TimeLapseCapture that sends the images in an email
"""
Expand Down Expand Up @@ -77,14 +77,14 @@ def send_callback(images: list[str]) -> None:
"-f",
type=Path,
help="Provide directory to temporarily store photos (ex. /home/pi/Pictures/)",
default="./",
default=Path.cwd(),
)
parser.add_argument(
"-logfile",
"-lf",
type=Path,
help="Provide path to file for writing logs (ex. /home/pi/log.txt)",
default=None,
default=Path.cwd() / "email_time_lapse_log.txt",
required=False,
)

Expand Down
7 changes: 5 additions & 2 deletions rca/camera/time_lapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ def sync_capture(self, callback: Callable[[list[Path]], None]) -> None:
camera.start()
try:
camera.start_and_capture_files(
f"{self.image_folder / 'img{{:d}}.jpg'}",
str(self.image_folder / "time_lapse_capture_img{:d}.jpg"),
initial_delay=5,
delay=self.capture_delay,
num_files=self.image_count,
# show_preview=False,
)
if callable(callback):
file_list: list[Path] = [self.image_folder / f"img{x}.jpg" for x in range(0, self.image_count)]
file_list: list[Path] = [
self.image_folder / f"time_lapse_capture_img{x}.jpg" for x in range(0, self.image_count)
]
callback(file_list)
except Exception:
logger.exception("Encountered an error capturing images")
2 changes: 1 addition & 1 deletion rca/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def create_rca_logger(log_level: int = logging.DEBUG, log_file: Optional[Path] =
if log_file is not None:
file_handler = logging.FileHandler(log_file)
file_handler.setLevel(log_level)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)

Expand Down

0 comments on commit cacbc28

Please sign in to comment.