Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import glob
- import os
- import random
- import shutil
- from google_images_download import google_images_download
- from InstagramAPI import InstagramAPI
- keyw = ["turtles", "cats", "dogs", "birds", "landscape", "skyline", "satellite images", "exoplanets", "lakes", "hippos", "exotic animals"]
- path2img = ""
- username = ""
- password = ""
- tofetch = 50
- # login
- api = InstagramAPI(username, password)
- api.login()
- def fetch(keyw):
- # google images download
- response = google_images_download.googleimagesdownload()
- arguments = {"keywords": keyw, "limit": tofetch, "print_urls": True, "type": "photo", "size": ">800*600", "output_directory": "./images", "safe_search": True}
- response.download(arguments)
- # move ./images/*keyword* to ./images/
- try:
- for i in glob.glob("./images/*/*"):
- shutil.move(i, "./images")
- except:
- print("error while moving downloaded images a dir up")
- # some other file operation?
- try:
- for i in glob.glob("./images/*"):
- shutil.rmtree("./images/"+keyw, ignore_errors=True)
- except:
- pass
- firstFilePath = path2img+os.listdir(path2img)[0]
- print("image to be uploaded: "+firstFilePath)
- try:
- API.uploadPhoto(firstFilePath, caption="1 bild fΓΌr dich lol :)")
- except:
- print("upload failed")
- exit()
- # remove image to avoid dups uploads
- os.remove(firstFilePath)
- # if <2 images in imagedir, fetch new ones
- if len(os.listdir(path2img)) < 2:
- chosen_keyw = keyw[random.randint(0, len(keyw))]
- # keyw.pop(chosen_keyw)
- fetch(chosen_keyw)
- print("uploaded: "+firstFilePath)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement