Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename saved images #13

Open
KAEYL98 opened this issue Nov 10, 2020 · 2 comments
Open

Rename saved images #13

KAEYL98 opened this issue Nov 10, 2020 · 2 comments

Comments

@KAEYL98
Copy link

KAEYL98 commented Nov 10, 2020

Hi,

Is it possible to specify the filename of the downloaded images when using results.download_links()?

Thank you

@kevalshah90
Copy link

kevalshah90 commented Dec 26, 2021

Same issue here. Did you figure out a way to do this?

@KAEYL98

I'am using this module to download several images and need them stored with unique file names. file_name is accessible by using .get method of python dictionary.

results.metadata[0].get('_file')

You can try something like this:

results.metadata[0]['_file'] = 'file_name.jpg'

results.metadata

@lorenzoromani1983
Copy link

I slightly changed the api.py file, editing the results class as follows:

  def __init__(
    self,
    params,
    coordinates,
    heading,
    site_api='https://maps.googleapis.com/maps/api/streetview',
    site_metadata='https://maps.googleapis.com/maps/api/streetview/metadata'):

...

    self.params = params
    self.coordinates = coordinates
    self.heading = heading

...

  for i, url in enumerate(self.links):
    if metadata[i][metadata_status] == status_ok:
      file_path = path.join(dir_path, coordinates + "_" + str(heading) + '.jpg')
      metadata[i]['_file'] = path.basename(file_path) # add file reference
      helpers.download(url, file_path)

in such a way, you can instantiate the results class passing as arguments the parameters, the lat,lon coordinates and the heading value. All become mandatory with such a solution:

results = google_streetview.api.results(params, "45.1234,15.759", "270")

the file name will be created accordingly by joining the lat-lon-heading values and no overwriting will occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants