Created
May 27, 2015 11:04
-
-
Save samsamm777/d5c8f2ba621aaf783df9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_images(vin, host, d=0): | |
""" | |
- Return a list of lists of images on disk for the give vin, younger than 'days' | |
List objects: [ index, image_url ] | |
- Don't return _thumbs. | |
""" | |
days = int(d) | |
image_list = [] | |
now = time.time() | |
try: | |
images = os.listdir(_get_path(vin)) | |
for i in images: | |
if days > 0 | |
fullpath = os.path.join(_get_path(vin), i) | |
if os.stat(fullpath).st_mtime < now - days * 86400: | |
continue | |
m = re.match(r"(?P<vin>.*)-(?P<index>...)_(?P<ar>\d*x\d*)(?P<other>\D*)\.jpg", i) | |
# Files like: WDDHF7EB3DA711640-004_4x3.jpg | |
# <vin>-<index>_<aspect ratio>[_thumb].jpg | |
# Yes, 4x3 and 1024x768 are the same aspect ratio. | |
if "thumb" in m.group('other'): | |
continue | |
img_num = int(m.group('index')) | |
aspect_ratio = m.group('ar') | |
url = '/'.join([host, "image", vin, aspect_ratio, str(img_num)]) | |
# URL like http://<hostname>:<port>/image/WDDAK76F08M001632/4x3/15 | |
# /image/<vin>/<aspect ratio>/<index> | |
# I don't need the img_num | |
# image_list.append([img_num, url]) | |
image_list.append(url) | |
except: | |
pass | |
return image_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment