Compare commits
2 Commits
b7a7ae13c9
...
ed63e229d6
Author | SHA1 | Date | |
---|---|---|---|
ed63e229d6 | |||
437e8e80d4 |
@ -0,0 +1,50 @@
|
||||
import os
|
||||
import shutil
|
||||
import exifread
|
||||
import piexif
|
||||
|
||||
# Définition du rectangle entourant la France métropolitaine
|
||||
france_bbox = (42.0, -5.0, 51.0, 10.0) # (lat_min, lon_min, lat_max, lon_max)
|
||||
|
||||
# Chemin du répertoire source
|
||||
source_dir ='source'
|
||||
|
||||
# Chemin du répertoire destination
|
||||
destination_dir = 'destination'
|
||||
|
||||
# Crée le répertoire destination si il n'existe pas
|
||||
if not os.path.exists(destination_dir):
|
||||
os.makedirs(destination_dir)
|
||||
|
||||
# Fonction pour déplacer un fichier si il est dans le rectangle de la France
|
||||
def move_file_if_in_france(filepath, filename):
|
||||
# Ouvre le fichier image et lit les informations EXIF
|
||||
with open(filepath, 'rb') as f:
|
||||
tags = exifread.process_file(f)
|
||||
|
||||
# Recherche les informations GPS dans les informations EXIF
|
||||
gps_tags = tags.get('GPS')
|
||||
if gps_tags:
|
||||
gps_lat = gps_tags.get('GPSLatitude')
|
||||
gps_lon = gps_tags.get('GPSLongitude')
|
||||
if gps_lat and gps_lon:
|
||||
gps_lat = gps_lat.values[0].num / gps_lat.values[0].den
|
||||
gps_lon = gps_lon.values[0].num / gps_lon.values[0].den
|
||||
if (france_bbox[0] <= gps_lat <= france_bbox[2] and
|
||||
france_bbox[1] <= gps_lon <= france_bbox[3]):
|
||||
# Déplace le fichier dans le sous-répertoire "photos_in_france"
|
||||
dest_subdir = os.path.join(destination_dir, 'photos_in_france', 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, filename))
|
||||
print(f"Moved {filename} to {dest_subdir}")
|
||||
return True
|
||||
return False
|
||||
|
||||
# Parcourt tous les fichiers dans le répertoire source et ses sous-répertoires
|
||||
for root, dirs, files in os.walk(source_dir):
|
||||
for filename in files:
|
||||
# Vérifie si le fichier est une image
|
||||
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp', '.tif')):
|
||||
filepath = os.path.join(root, filename)
|
||||
move_file_if_in_france(filepath, filename)
|
BIN
mastodon-tags-links/barres_liens_tag_votepirate.png
Normal file
BIN
mastodon-tags-links/barres_liens_tag_votepirate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 122 KiB |
File diff suppressed because it is too large
Load Diff
Before Width: | Height: | Size: 339 KiB After Width: | Height: | Size: 351 KiB |
Loading…
Reference in New Issue
Block a user