gcerretani / antenati

Tools to download data from Portale Antenati

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need option to use an existing directory

vinnydabody opened this issue · comments

If an archive for a particular year (example: Modugno births 1866) has multiple subfolders (in this case Parte 1 and Parte 2), when executing the script for the first image in Parte 1 if no folder exists, a folder is created on the local drive and the images are fetched, adding "Parte 1" before the folio number and image number in the filename. When trying to execute the script for the first image in Parte 2, the script tells you the folder already exists and exits.

I added some logic when a folder already exists to ask the user if he wants to continue using click.confirm(), with an abort option. It seems to work although the abort is less than elegant (I admit to being a hack at programming). I've attached a zip antenati2.py.zip with the updated code. May require installation of click through pip.

Here's the added code (also the addition of "import click")

    if os.path.exists(foldername):
        click.confirm("Directory " + foldername + " already exists.Do you want to copy images to this directory?", default=True, abort=True)    

    if not os.path.exists(foldername):
	os.mkdir(foldername)

    os.chdir(foldername)

Below is the output with the option enabled (yes or enter is the default and will continue with images pulled into the existing directory).

Directory Modugno_Morti_1866 already exists.Do you want to copy images to this directory? [Y/n]: n
Traceback (most recent call last):
  File "/usr/bin/antenati2.py", line 86, in <module>
    main()
  File "/usr/bin/antenati2.py", line 60, in main
    click.confirm("Directory " + foldername + " already exists.Do you want to copy images to this directory?", default=True, abort=True)
  File "~/.local/lib/python2.7/site-packages/click/termui.py", line 181, in confirm
    raise Abort()
click.exceptions.Abort

improvement already included 4b872a5