mirror of
https://forge.chapril.org/tykayn/mapillary_download
synced 2025-10-09 17:02:46 +02:00
correct text-array to download script, ask for usernames if empty, improve argparse, linting to black
Signed-off-by: Matthias <matthias@pebble>
This commit is contained in:
parent
ff90b70d5d
commit
795fd20030
8 changed files with 398 additions and 189 deletions
|
@ -12,9 +12,19 @@ import shutil
|
|||
import exifread
|
||||
|
||||
# Définition du rectangle entourant la France métropolitaine et un peu autour
|
||||
france_bbox: tuple[float, float, float, float] = (42.0, -5.0, 51.0, 10.0) # (lat_min, lon_min, lat_max, lon_max)
|
||||
france_bbox: tuple[float, float, float, float] = (
|
||||
42.0,
|
||||
-5.0,
|
||||
51.0,
|
||||
10.0,
|
||||
) # (lat_min, lon_min, lat_max, lon_max)
|
||||
# Définition du rectangle entourant la France métropolitaine et un peu autour
|
||||
france_bbox: tuple[float, float, float, float] = (42.0, -5.0, 51.0, 10.0) # (lat_min, lon_min, lat_max, lon_max)
|
||||
france_bbox: tuple[float, float, float, float] = (
|
||||
42.0,
|
||||
-5.0,
|
||||
51.0,
|
||||
10.0,
|
||||
) # (lat_min, lon_min, lat_max, lon_max)
|
||||
|
||||
# Définition du rectangle entourant la Guadeloupe
|
||||
guadeloupe_bbox: tuple[float, float, float, float] = (15.8, -61.8, 17.3, -59.3)
|
||||
|
@ -50,11 +60,11 @@ pf_bbox: tuple[float, float, float, float] = (-27.5, -140.0, -7.5, -134.0)
|
|||
taaf_bbox: tuple[float, float, float, float] = (-49.5, 68.5, -37.5, 77.5)
|
||||
|
||||
# Chemin du répertoire source
|
||||
source_dir: str = '/home/cipherbliss/Téléchargements/FIBRELAND/TEST_IN_FR/'
|
||||
source_dir: str = "/home/cipherbliss/Téléchargements/FIBRELAND/TEST_IN_FR/"
|
||||
|
||||
# Chemin du répertoire destination
|
||||
destination_dir: str = '/home/cipherbliss/Téléchargements/FIBRELAND/IN_FRANCE/'
|
||||
sequence_folder: str = 'principale_sequence'
|
||||
destination_dir: str = "/home/cipherbliss/Téléchargements/FIBRELAND/IN_FRANCE/"
|
||||
sequence_folder: str = "principale_sequence"
|
||||
count_files_all: int = 0
|
||||
count_files_moved: int = 0
|
||||
# Crée le répertoire destination si il n'existe pas
|
||||
|
@ -71,18 +81,19 @@ def move_file_if_in_france(filepath, sequence_folder):
|
|||
latitude, longitude = get_gps_info(filepath)
|
||||
|
||||
if latitude and longitude:
|
||||
print(f'Latitude: {latitude}, Longitude: {longitude}')
|
||||
print(f"Latitude: {latitude}, Longitude: {longitude}")
|
||||
if are_lat_lon_in_france(latitude, longitude):
|
||||
move_file_in_destination(filepath, sequence_folder)
|
||||
else:
|
||||
print('Informations GPS non trouvées')
|
||||
print("Informations GPS non trouvées")
|
||||
|
||||
|
||||
def move_file_in_destination(filepath, sequence_folder):
|
||||
global count_files_moved
|
||||
# Déplace le fichier dans le sous-répertoire "photos_in_france"
|
||||
dest_subdir = os.path.join(destination_dir, sequence_folder,
|
||||
os.path.basename(os.path.dirname(filepath)))
|
||||
dest_subdir = os.path.join(
|
||||
destination_dir, sequence_folder, os.path.basename(os.path.dirname(filepath))
|
||||
)
|
||||
if not os.path.exists(dest_subdir):
|
||||
os.makedirs(dest_subdir)
|
||||
shutil.move(filepath, os.path.join(dest_subdir, filepath))
|
||||
|
@ -90,6 +101,7 @@ def move_file_in_destination(filepath, sequence_folder):
|
|||
print(f"Moved {filepath} to {dest_subdir}")
|
||||
return True
|
||||
|
||||
|
||||
def are_lat_lon_in_france(gps_lat, gps_lon):
|
||||
"""
|
||||
recherche d'une zone du territoire français
|
||||
|
@ -117,37 +129,63 @@ def are_lat_lon_in_france(gps_lat, gps_lon):
|
|||
|
||||
print("lat lon :", gps_lat, gps_lon)
|
||||
|
||||
if (france_bbox[0] <= gps_lat <= france_bbox[2] and france_bbox[1] <= gps_lon <= france_bbox[3]):
|
||||
if (
|
||||
france_bbox[0] <= gps_lat <= france_bbox[2]
|
||||
and france_bbox[1] <= gps_lon <= france_bbox[3]
|
||||
):
|
||||
return "France métropolitaine"
|
||||
elif (taaf_bbox[0] <= gps_lat <= taaf_bbox[2] and taaf_bbox[1] <= gps_lon <= taaf_bbox[3]):
|
||||
elif (
|
||||
taaf_bbox[0] <= gps_lat <= taaf_bbox[2]
|
||||
and taaf_bbox[1] <= gps_lon <= taaf_bbox[3]
|
||||
):
|
||||
return "Terres australes et antarctiques françaises"
|
||||
elif (guyane_bbox[0] <= gps_lat <= guyane_bbox[2] and guyane_bbox[1] <= gps_lon <= guyane_bbox[3]):
|
||||
elif (
|
||||
guyane_bbox[0] <= gps_lat <= guyane_bbox[2]
|
||||
and guyane_bbox[1] <= gps_lon <= guyane_bbox[3]
|
||||
):
|
||||
return "Guyane française"
|
||||
elif (reunion_bbox[0] <= gps_lat <= reunion_bbox[2] and reunion_bbox[1] <= gps_lon <= reunion_bbox[3]):
|
||||
elif (
|
||||
reunion_bbox[0] <= gps_lat <= reunion_bbox[2]
|
||||
and reunion_bbox[1] <= gps_lon <= reunion_bbox[3]
|
||||
):
|
||||
return "La Réunion"
|
||||
elif (wf_bbox[0] <= gps_lat <= wf_bbox[2] and wf_bbox[1] <= gps_lon <= wf_bbox[3]):
|
||||
elif wf_bbox[0] <= gps_lat <= wf_bbox[2] and wf_bbox[1] <= gps_lon <= wf_bbox[3]:
|
||||
return "Wallis-et-Futuna"
|
||||
elif (stm_sbh_bbox[0] <= gps_lat <= stm_sbh_bbox[2] and stm_sbh_bbox[1] <= gps_lon <= stm_sbh_bbox[3]):
|
||||
elif (
|
||||
stm_sbh_bbox[0] <= gps_lat <= stm_sbh_bbox[2]
|
||||
and stm_sbh_bbox[1] <= gps_lon <= stm_sbh_bbox[3]
|
||||
):
|
||||
return "Saint-Martin et Saint-Barthélemy"
|
||||
elif (spm_bbox[0] <= gps_lat <= spm_bbox[2] and spm_bbox[1] <= gps_lon <= spm_bbox[3]):
|
||||
elif (
|
||||
spm_bbox[0] <= gps_lat <= spm_bbox[2] and spm_bbox[1] <= gps_lon <= spm_bbox[3]
|
||||
):
|
||||
return "Saint-Pierre-et-Miquelon"
|
||||
elif (mayotte_bbox[0] <= gps_lat <= mayotte_bbox[2] and mayotte_bbox[1] <= gps_lon <= mayotte_bbox[3]):
|
||||
elif (
|
||||
mayotte_bbox[0] <= gps_lat <= mayotte_bbox[2]
|
||||
and mayotte_bbox[1] <= gps_lon <= mayotte_bbox[3]
|
||||
):
|
||||
return "Mayotte"
|
||||
elif (martinique_bbox[0] <= gps_lat <= martinique_bbox[2] and martinique_bbox[1] <= gps_lon <= martinique_bbox[3]):
|
||||
elif (
|
||||
martinique_bbox[0] <= gps_lat <= martinique_bbox[2]
|
||||
and martinique_bbox[1] <= gps_lon <= martinique_bbox[3]
|
||||
):
|
||||
return "Martinique"
|
||||
elif (guadeloupe_bbox[0] <= gps_lat <= guadeloupe_bbox[2] and guadeloupe_bbox[1] <= gps_lon <= guadeloupe_bbox[3]):
|
||||
elif (
|
||||
guadeloupe_bbox[0] <= gps_lat <= guadeloupe_bbox[2]
|
||||
and guadeloupe_bbox[1] <= gps_lon <= guadeloupe_bbox[3]
|
||||
):
|
||||
return "Guadeloupe"
|
||||
|
||||
elif (pf_bbox[0] <= gps_lat <= pf_bbox[2] and pf_bbox[1] <= gps_lon <= pf_bbox[3]):
|
||||
elif pf_bbox[0] <= gps_lat <= pf_bbox[2] and pf_bbox[1] <= gps_lon <= pf_bbox[3]:
|
||||
return "Polynésie française"
|
||||
elif (nc_bbox[0] <= gps_lat <= nc_bbox[2] and nc_bbox[1] <= gps_lon <= nc_bbox[3]):
|
||||
elif nc_bbox[0] <= gps_lat <= nc_bbox[2] and nc_bbox[1] <= gps_lon <= nc_bbox[3]:
|
||||
return "Nouvelle-Calédonie"
|
||||
else:
|
||||
return None # "Hors de France"
|
||||
return None # "Hors de France"
|
||||
|
||||
|
||||
def get_gps_info(filepath):
|
||||
with open(filepath, 'rb') as f:
|
||||
with open(filepath, "rb") as f:
|
||||
tags = exifread.process_file(f)
|
||||
gps_info = {}
|
||||
|
||||
|
@ -155,12 +193,12 @@ def get_gps_info(filepath):
|
|||
|
||||
# print("clés exif ", tags.keys())
|
||||
for tag in tags.keys():
|
||||
if tag.startswith('GPS'):
|
||||
if tag.startswith("GPS"):
|
||||
gps_info[tag] = tags[tag]
|
||||
|
||||
# Extraction des informations de latitude et de longitude
|
||||
gps_latitude = convert_rational_to_float(gps_info.get('GPS GPSLatitude'))
|
||||
gps_longitude = convert_rational_to_float(gps_info.get('GPS GPSLongitude'))
|
||||
gps_latitude = convert_rational_to_float(gps_info.get("GPS GPSLatitude"))
|
||||
gps_longitude = convert_rational_to_float(gps_info.get("GPS GPSLongitude"))
|
||||
|
||||
if gps_latitude and gps_longitude:
|
||||
return gps_latitude, gps_longitude
|
||||
|
@ -172,22 +210,38 @@ def convert_rational_to_float(rational):
|
|||
return float(rational.values[0].num) / float(rational.values[0].den)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--source_dir', default='/home/cipherbliss/Téléchargements/FIBRELAND/TEST_IN_FR/', help='Chemin du répertoire source')
|
||||
parser.add_argument('--destination_dir', default='/home/cipherbliss/Téléchargements/FIBRELAND/IN_FRANCE/', help='Chemin du répertoire destination')
|
||||
parser.add_argument('--sequence_folder', default='principale_sequence', help='Nom du dossier de séquence')
|
||||
parser.add_argument(
|
||||
"--source_dir",
|
||||
default="/home/cipherbliss/Téléchargements/FIBRELAND/TEST_IN_FR/",
|
||||
help="Chemin du répertoire source",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--destination_dir",
|
||||
default="/home/cipherbliss/Téléchargements/FIBRELAND/IN_FRANCE/",
|
||||
help="Chemin du répertoire destination",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--sequence_folder",
|
||||
default="principale_sequence",
|
||||
help="Nom du dossier de séquence",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Parcourt tous les fichiers dans le répertoire source et ses sous-répertoires
|
||||
for root, dirs, files in os.walk(args.source_dir):
|
||||
for filename in files:
|
||||
# Vérifie si le fichier est une image
|
||||
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp', '.tif')):
|
||||
if filename.lower().endswith(
|
||||
(".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tif")
|
||||
):
|
||||
filepath = os.path.join(root, filename)
|
||||
move_file_if_in_france(filepath, sequence_folder)
|
||||
|
||||
print('fichiers se situant en france déplacés: ', count_files_moved, ' / ', count_files_all)
|
||||
print(
|
||||
"fichiers se situant en france déplacés: ",
|
||||
count_files_moved,
|
||||
" / ",
|
||||
count_files_all,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue