def make_response(photo_ids): response = OrderedDict() for photo_id in photo_ids: r = id_to_record[photo_id] w, h = id_to_dims[photo_id] ocr_text = id_to_text.get(photo_id) # See also viewer/app.py title = decode(r.title()) original_title = None if title_cleaner.is_pure_location(title): original_title = title title = '' assert r.description() == '' assert r.note() == '' response[photo_id] = { 'title': title, 'date': re.sub(r'\s+', ' ', r.date()), 'folder': decode(r.location()), 'width': w, 'height': h, 'text': ocr_text } if original_title: response[photo_id]['original_title'] = original_title return response
def make_response(photo_ids): response = OrderedDict() for photo_id in photo_ids: r = id_to_record[photo_id] w, h = id_to_dims[photo_id] ocr_text = id_to_text.get(photo_id) # See also viewer/app.py title = decode(r.title()) original_title = None if title_cleaner.is_pure_location(title): original_title = title title = '' assert r.description() == '' assert r.note() == '' rotation = id_to_rotation.get(photo_id) if rotation and (rotation % 180 == 90): w, h = h, w date = re.sub(r'\s+', ' ', r.date()) response[photo_id] = { 'title': title, 'date': date, 'years': extract_years(date), 'folder': decode(r.location()), 'width': w, 'height': h, 'text': ocr_text, 'image_url': image_url(photo_id, is_thumb=False), 'thumb_url': image_url(photo_id, is_thumb=True) } if original_title: response[photo_id]['original_title'] = original_title if rotation: response[photo_id]['rotation'] = rotation # Sort by earliest date; undated photos go to the back. ids = sorted(photo_ids, key=lambda id: min(response[id]['years']) or 'z') return OrderedDict((id_, response[id_]) for id_ in ids)
def make_response(photo_ids): response = OrderedDict() for photo_id in photo_ids: r = id_to_record[photo_id] w, h = id_to_dims[photo_id] ocr_text = id_to_text.get(photo_id) # See also viewer/app.py title = decode(r.title()) original_title = None if title_cleaner.is_pure_location(title): original_title = title title = '' assert r.description() == '' assert r.note() == '' rotation = id_to_rotation.get(photo_id) if rotation and (rotation % 180 == 90): w, h = h, w response[photo_id] = { 'title': title, 'date': re.sub(r'\s+', ' ', r.date()), 'folder': decode(r.location()), 'width': w, 'height': h, 'text': ocr_text, 'image_url': image_url(photo_id, is_thumb=False), 'thumb_url': image_url(photo_id, is_thumb=True) } if original_title: response[photo_id]['original_title'] = original_title if rotation: response[photo_id]['rotation'] = rotation return response
def make_response(photo_ids): response = OrderedDict() for photo_id in photo_ids: r = id_to_record[photo_id] w, h = id_to_dims[photo_id] ocr_text = id_to_text.get(photo_id) # See also viewer/app.py title = decode(r.title()) original_title = None if title_cleaner.is_pure_location(title): original_title = title title = "" assert r.description() == "" assert r.note() == "" rotation = id_to_rotation.get(photo_id) if rotation and (rotation % 180 == 90): w, h = h, w response[photo_id] = { "title": title, "date": re.sub(r"\s+", " ", r.date()), "folder": decode(r.location()), "width": w, "height": h, "text": ocr_text, "image_url": image_url(photo_id, is_thumb=False), "thumb_url": image_url(photo_id, is_thumb=True), } if original_title: response[photo_id]["original_title"] = original_title if rotation: response[photo_id]["rotation"] = rotation return response
def test_clean_title(): for correct, title in TRUTH: assert correct == title_cleaner.is_pure_location( title), '%s %s' % (correct, title)
def test_clean_title(): for correct, title in TRUTH: assert correct == title_cleaner.is_pure_location(title), '%s %s' % (correct, title)