Skip to content

Commit

Permalink
Delete broken images on raffer (#2)
Browse files Browse the repository at this point in the history
* added script to delete broken images on raffer

* added condition to check for broken images

* added pillow as requirement
  • Loading branch information
maexled authored Jun 4, 2022
1 parent 71cc738 commit 78886d5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The project is designed to manage images uploaded by a (Hikvision) IP-Camera in
raffer_execution="00:15"
samba_user="samba"
object_detection="true"
check_for_broken_images="true"
save_longtime_pictures="true"
save_object_detection="true"
save_to_nextcloud="true"
Expand Down
21 changes: 21 additions & 0 deletions delete_broken_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import argparse
from PIL import Image

# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-f", "--folder", required=True,
help="path to the images")
args = vars(ap.parse_args())

for filename in os.listdir(args["folder"]):
if filename.endswith(".jpg"):
f = os.path.join(args["folder"], filename)
# checking if it is a file
if os.path.isfile(f):
try:
im = Image.open(f)
verify = im.verify()
except:
print(f'{f} has errors, deleting it...')
os.remove(f)
6 changes: 6 additions & 0 deletions raffer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ fulldateyesterday=$(date --date='-1 day' +'%Y-%m-%d')

echo "Starting for $fulldateyesterday"


if [ "$check_for_broken_images" == "true" ]; then
echo "Checking for broken images..."
python3 $DIR/delete_broken_images.py -f $datediryesterday
fi

cd $datediryesterday
zip $fulldateyesterday.zip *.jpg

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
numpy==1.22.4
imutils==0.5.4
opencv-python==4.5.5.64
pillow==9.0.1

0 comments on commit 78886d5

Please sign in to comment.