class UploadToIG: def __init__(self, folder_one, folder_two): self.folder_one = folder_one self.folder_two = folder_two self.list_files_one = folder_to_list(folder_one) self.list_files_two = folder_to_list(folder_two) self.cl = Client() self.cl.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD) create_dir(CURRENT_FOLDER) create_dir(ERRORS_FOLDER) def upload(self, image_one, image_two, caption): self.cl.album_upload([image_one, image_two], caption=caption) def process(self): while self.list_files_one: # take first element file_one = self.list_files_one[0] if self.list_files_one else None file_two = self.list_files_two[0] if self.list_files_two else None # move it to the current folder img_one = CURRENT_FOLDER + file_one img_two = CURRENT_FOLDER + file_two os.replace(self.folder_one + file_one, img_one) os.replace(self.folder_two + file_two, img_two) del (self.list_files_one[0]) del (self.list_files_two[0]) # upload to IG try: self.upload(image_one=img_one, image_two=img_two, caption=CAPTION) except: os.replace(img_one, ERRORS_FOLDER + file_one) os.replace(img_two, ERRORS_FOLDER + file_two)
for image in post: imageset[image] = find_faces(image) final = sorted(imageset.items(), key=lambda kv: kv[1]) final = collections.OrderedDict(final) instapost = [] numofimages = 0 for number in range(len(final) - 1, -1, -1): if numofimages < 10: instapost.append(list(final.keys())[number]) numofimages += 1 if len(instapost) != 0: bot = Client() bot.login("username", "password") album_path = instapost text = "caption" bot.album_upload(album_path, caption=text) print("Posted!") else: print("No need to post") driver.quit()
# Creating a bot from instagrapi and login in into the instagram account bot = Client() bot.login(USERNAME, PASSWORD) """ Getting informations about 2 users with their Instagram user Id Instagram user Id can be get by running "print(bot.user_info_by_username(username))" User id is a integer: "123456789" """ usr1_id = bot.user_info(XXXXXXXXXXX) usr2_id = bot.user_info(XXXXXXXXXXX) # Create Usertag objet to pin on the post tag = [Usertag(user=usr1_id, x=0, y=1), Usertag(user=usr2_id, x=1, y=1)] # List of Path to images to post album_path = ["Image/Panorama.jpg", "Image/imageToPost.jpg"] # Caption of the post text = "Pays : " + str(country) + "\nLatitude : {}, Longitude : {}".format(lat, lon) + \ "\nImage from google map posted by my bot.\nBot made by @usr1 and @usr1\n#googlemap #googleearth #googlestreetview "\ "#google #bot #photo #paysage #picture #landscape #beautifull #programmation #code #programming #globe #earth #panorama #360 "\ "#litleplanet #tinyplanet #ia #random" # Creating of the location of the pictures loc = bot.location_complete(Location(name=country, lat=lat, lng=lon)) # Uploading the album to Instagram bot.album_upload(album_path, caption=text, location=loc, usertags=tag) print("Images published!")