cleanup & comments

also TO DO items
main
Alexandre B A Villares 2020-07-05 19:41:14 -03:00
rodzic 4e068a728a
commit a69359ef80
2 zmienionych plików z 30 dodań i 25 usunięć

Wyświetl plik

@ -1,13 +1,15 @@
# read folder
# find missing entries
# check image types
# build markdown
# insert in propper place
# reads folder
# finds missing folders from last_done
# gets images, checks image types
# build markdown for entries
## TO DO:
# find last entry for me
# insert new entries in propper place
from os import listdir
from os.path import isfile, join
from helpers import name_image_files, build_entry
from helpers import get_image_files, build_entry
last_done = '2020_06_21'
YEAR = "2020"
@ -15,27 +17,17 @@ base_path = "/media/villares/VolumeD/GitHub/sketch-a-day"
year_path = join(base_path,YEAR)
folders = listdir(year_path)
# find folders after the last_done
new_folders = []
for f in reversed(folders):
if last_done in f:
break
else:
new_folders.append(f)
for f in new_folders:
img = name_image_files(year_path, f)
if img:
print(build_entry(img[0], YEAR))
sl = (
("sketch_2020_06_18a", ".gif"),
("sketch_2020_06_17a", ".png"),
("sketch_2020_06_16a", ".gif"),
("sketch_2020_06_15a", ".gif"),
)
# for s, OUTPUT in sl:
# SKETCH_NAME = s
# str(
imgs = get_image_files(year_path, f)
if imgs:
print(build_entry(imgs[0], YEAR))

Wyświetl plik

@ -1,7 +1,12 @@
from os import listdir
from os.path import isfile, join
def name_image_files(base, folder):
def get_image_files(base, folder):
"""
returns a list of image files from
a directory named folder at base/folder
but only if name contains the folder name
"""
contents = listdir(join(base, folder))
image_files = [f for f in contents
if is_img_ext(f)
@ -9,8 +14,11 @@ def name_image_files(base, folder):
return image_files
def is_img_ext(file_name):
"""
checks if file_name ends with
one of the valid_ext extensions
"""
ext = file_name.split('.')[-1]
# extensões dos formatos de imagem que o Processing aceita!
valid_ext = ('jpg',
'png',
'jpeg',
@ -21,6 +29,11 @@ def is_img_ext(file_name):
return ext.lower() in valid_ext
def build_entry(image, year):
"""
returns a string with markdown formated
for the sketch-a-day index page entry
of image (for a certain year)
"""
name, ext = image.split('.')
return """
---