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

Nice code, would make a good API #55

Closed
eamonnkenny opened this issue Mar 23, 2018 · 5 comments
Closed

Nice code, would make a good API #55

eamonnkenny opened this issue Mar 23, 2018 · 5 comments

Comments

@eamonnkenny
Copy link

If you were to change google_images_download.py to be a class rather than a set of functions and main caller, you could then allow it to be used as an API from other python scripts. That way it becomes a very powerful tool.

This is more of a feature request, not a bug.

@hardikvasa
Copy link
Owner

@eamonnkenny thanks for your feedback :-)

This script, as you know would run from Command Line Interface. With that, could you tell me how do you propose it to be used from within other python files? Like even if the methods were put in classes, how would it still be like an API?

For now, the best way to call this from within another python file would be
subprocess.call("googleimagesdownload -cf config.json)

and have all the arguments in the config (JSON) file. And since it is JSON format, it could also be automated as required.

Thnx

@eamonnkenny
Copy link
Author

The issue is that with an API the individual using it does not want to have all the configuration in one script. I for instance would like to use it as an API with some default behaviour, downloading 10 labeled for reuse images given some input search string that changes each time.
(by the way, typos related to labled instead of labeled in your main calling function, need fixing)

I've attached a calling function that includes a class. Basically its probably better if you use a class instead of a function call and this gives people the ability to manipulate some of the variables.

I have to say you have done a great job on this as it stands. I really like the results that the functions use and you have so much added functionality and configurability. Its great.

I've attached a workaround for what I am trying to do. I basically wrapped your code up in a class.
The class could be extended to have a whole lot more default arguments. I also have the ability at the moment to just add in extra arguments (this isn't actually the way to do it), but it would be nicer if every single argument can be passed to a constructor of a class. The calling function can be basically what you have with lots of arguments and then fed into the class afterwards. Hope this makes sense. That way the class then becomes the front for the API calls. The command line main function is just a usage of the API.

ImageDownloadClass.zip

@hardikvasa
Copy link
Owner

hardikvasa commented Apr 5, 2018

@eamonnkenny thanks for the suggestion. The new version of this lib allows you to call it from another python file. An example is provided in the docs. You can now create an object and pass on the parameters inside it.

Had to make a lot of changes in the code for good to implement this... :D . Few minor changes around the edges will be done in coming days...but for now this works fine.

Do let me know if this is more usable now.

@hardikvasa
Copy link
Owner

Closing this issue. Seems to be stable on all major OSs.

@eamonnkenny
Copy link
Author

Great work. Really like what you have done with this.

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

2 participants