From 1a716f9b94c8393e56fbb453650041b98ca0549c Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 24 Aug 2021 07:36:35 +0200 Subject: [PATCH] oneplus fix --- ordigi.py | 8 ++++---- ordigi/geolocation.py | 15 +++++++++++---- ordigi/media.py | 4 +++- tests/test_filesystem.py | 1 + 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ordigi.py b/ordigi.py index a0d06b0..26a5b2f 100755 --- a/ordigi.py +++ b/ordigi.py @@ -6,7 +6,6 @@ import sys from datetime import datetime import click -from send2trash import send2trash from ordigi import config from ordigi import constants @@ -112,14 +111,15 @@ def _sort(debug, dry_run, destination, clean, copy, exclude_regex, filter_by_ext # Initialize Db db = Db(destination) - if 'Directory' in conf and 'day_begins' in conf['Directory']: - config_directory = conf['Directory'] - day_begins = config_directory['day_begins'] + if 'Path' in conf and 'day_begins' in conf['Path']: + config_directory = conf['Path'] + day_begins = int(config_directory['day_begins']) else: day_begins = 0 filesystem = FileSystem(cache, day_begins, dry_run, exclude_regex_list, filter_by_ext, logger, max_deep, mode, path_format) + import ipdb; ipdb.set_trace() summary, has_errors = filesystem.sort_files(paths, destination, db, remove_duplicates, ignore_tags) diff --git a/ordigi/geolocation.py b/ordigi/geolocation.py index b595f3f..0aa45d7 100644 --- a/ordigi/geolocation.py +++ b/ordigi/geolocation.py @@ -26,7 +26,9 @@ def coordinates_by_name(name, db): # If the name is not cached then we go ahead with an API lookup geocoder = get_geocoder() if geocoder == 'Nominatim': - locator = Nominatim(user_agent='myGeocoder') + # timeout = DEFAULT_SENTINEL + timeout = 10 + locator = Nominatim(user_agent='myGeocoder', timeout=timeout) geolocation_info = locator.geocode(name) if geolocation_info is not None: return { @@ -135,14 +137,19 @@ def lookup_osm(lat, lon, logger=logging.getLogger()): prefer_english_names = get_prefer_english_names() try: - locator = Nominatim(user_agent='myGeocoder') + timeout = 10 + locator = Nominatim(user_agent='myGeocoder', timeout=timeout) coords = (lat, lon) if(prefer_english_names): lang='en' else: lang='local' - return locator.reverse(coords, language=lang).raw - except geopy.exc.GeocoderUnavailable as e: + locator_reverse = locator.reverse(coords, language=lang) + if locator_reverse is not None: + return locator_reverse.raw + else: + return None + except geopy.exc.GeocoderUnavailable or geopy.exc.GeocoderServiceError as e: logger.error(e) return None # Fix *** TypeError: `address` must not be None diff --git a/ordigi/media.py b/ordigi/media.py index 772cc8b..7a64432 100644 --- a/ordigi/media.py +++ b/ordigi/media.py @@ -5,6 +5,7 @@ Media :class:`Media` class to get file metadata import logging import mimetypes import os +import six # load modules from dateutil.parser import parse @@ -147,7 +148,8 @@ class Media(): value = re.sub(regex , r'\g<1>-\g<2>-\g<3>', value) return parse(value) except BaseException or dateutil.parser._parser.ParserError as e: - self.logger.error(e) + self.logger.error(e, value) + import ipdb; ipdb.set_trace() return None def get_coordinates(self, key, value): diff --git a/tests/test_filesystem.py b/tests/test_filesystem.py index cda0707..70e786e 100644 --- a/tests/test_filesystem.py +++ b/tests/test_filesystem.py @@ -153,6 +153,7 @@ class TestFilesystem: for mode in 'copy', 'move': filesystem = FileSystem(path_format=self.path_format, mode=mode) # copy mode + import ipdb; ipdb.set_trace() src_path = Path(self.src_paths, 'photo.png') dest_path = Path(tmp_path,'photo_copy.png') src_checksum = filesystem.checksum(src_path)