def _photos(candidates: Iterable[str]) -> Iterator[Result]: geolocator = Nominatim() # TODO does it cache?? from functools import lru_cache @lru_cache(None) def get_geo(d: Path) -> Optional[LatLon]: geof = d / 'geo.json' if not geof.exists(): if d == d.parent: return None else: return get_geo(d.parent) j = json.loads(geof.read_text()) if 'name' in j: g = geolocator.geocode(j['name']) lat = g.latitude lon = g.longitude else: lat = j['lat'] lon = j['lon'] return LatLon(lat=lat, lon=lon) for path in map(Path, candidates): if config.ignored(path): log.info('ignoring %s due to config', path) continue parent_geo = get_geo(path.parent) mime = fastermime(str(path)) yield from _make_photo(path, mime, parent_geo=parent_geo)
def _photos(candidates: Iterable[Res[str]]) -> Iterator[Result]: geolocator = Nominatim() # TODO does it cache?? from functools import lru_cache @lru_cache(None) def get_geo(d: Path) -> Optional[LatLon]: geof = d / 'geo.json' if not geof.exists(): if d == d.parent: return None else: return get_geo(d.parent) j = json.loads(geof.read_text()) if 'name' in j: g = geolocator.geocode(j['name']) lat = g.latitude lon = g.longitude else: lat = j['lat'] lon = j['lon'] return LatLon(lat=lat, lon=lon) pool = Pool() futures = [] for p in candidates: if isinstance(p, Exception): yield p continue path = Path(p) # TODO rely on get_files if config.ignored(path): logger.info('ignoring %s due to config', path) continue logger.debug('processing %s', path) parent_geo = get_geo(path.parent) mime = fastermime(str(path)) futures.append( pool.submit(_make_photo_aux, path, mime, parent_geo=parent_geo)) for f in futures: yield from f.result()