mapillary_download/images_par_username.py
2025-07-28 12:15:43 +02:00

75 lines
2 KiB
Python

import os, requests, json
import argparse
from urllib.parse import quote
def parse_args(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument(
"--access_token",
type=str,
default=os.environ["MAPILLARY_DEV_TOKEN"],
help="Your mapillary access token",
)
parser.add_argument(
"--username",
type=str,
required=True,
help="Username to get the sequences id of",
)
parser.add_argument(
"--pictures",
type=str,
default=500,
help="Limit of pictures to fetch, max=5000",
)
parser.add_argument(
"--bbox",
type=str,
default=None,
help="Limit to a bounding box, e.g. '-5.5,47.3,-1.2,48.9', use http://bboxfinder.com",
)
parser.add_argument(
"--fr",
type=bool,
default=True,
help="Limit to the Fr metropolitan bouding box",
)
global args
args = parser.parse_args(argv)
FRANCE_MIN_LAT = 42.25
FRANCE_MIN_LON = -4.77
FRANCE_MAX_LAT = 51.10
FRANCE_MAX_LON = 9.57
if __name__ == "__main__":
print('images_par_username')
parse_args()
mly_key = args.access_token
creator_username = args.username
max_img = args.pictures
if args.fr:
bbox_filter = f"&bbox={FRANCE_MIN_LAT},{FRANCE_MIN_LON},{FRANCE_MAX_LAT},{FRANCE_MAX_LON}"
bbox_filter = f'&bbox={args.bbox}' if args.bbox is not None else ''
url = f"https://graph.mapillary.com/images?access_token={mly_key}&creator_username={creator_username}&limit={max_img}&fields=id,sequence{bbox_filter}"
print("prendre les séquences de l'utilisateur :",url)
response = requests.get(url)
if response.status_code == 200:
json = response.json()
# tri des séquences uniques
sequences_ids = [obj["sequence"] for obj in json["data"]]
unique_ids = list(set(sequences_ids))
print(unique_ids)
print("---")
print(" ".join(unique_ids))
else:
print(response)