def post_meme(self): self.settings = UserSettings.objects.get(userID=self.userID) if self.settings.memeOn: bot = Bot() bot.login(username=self.igusername, password=self.igpassword, use_cookie=False) memes = bot.get_hashtag_medias("420") posted_memes = open("{}/postedMemes.txt".format(self.accountDir), "r").read().splitlines() for m in memes: if str(m) not in posted_memes: try: bot.download_photo( m, filename=m, folder="{}/memesToBeUploaded".format( self.accountDir)) op = bot.get_media_info(m)[0]['user']['username'] bot.upload_photo('{}/memesToBeUploaded/{}.jpg'.format( self.accountDir, m), caption="Credits to {}".format(op)) os.remove('{}/memesToBeUploaded/{}.jpg'.format( self.accountDir, m)) f = open('{}/postedMemes.txt'.format(self.accountDir), 'a') f.write(str(m) + '\n') f.close() break except Exception as e: bot.logger.warning("Download Failed") print("Download Failed ", e) bot.logout()
def main(): # アカウント情報をロード with open('account_info.json', 'r') as f: data = json.load(f) username = data['username'] password = data['password'] # Login bot = Bot(base_path=LOG_DIR, comments_file=os.path.join(CONFIG_DIR, 'comments.txt')) bot.login(username=username, password=password) # 他人の画像をダウンロード target_user_id = "daisuke_clover" media_ids = bot.get_user_medias(user_id=target_user_id, filtration=None, is_comment=None) media_id = media_ids[0] # download photo dummy_file = os.path.join(DATA_DIR, "dummy") bot.download_photo(media_id, filename=dummy_file) dummy_file += '.jpg' # 引用する旨を伝える bot.comment_medias([media_id]) # キャプション準備 tags = ["#tokyo", "#awesomeplaces"] caption = "どこだか分かる?\n\n" caption += 'Credit: @{}\n\n'.format(target_user_id) caption += ' '.join(tags) # upload photo result = bot.upload_photo(dummy_file, caption=caption)
def main(): # アカウント情報をロード with open('account_info.json', 'r') as f: data = json.load(f) username = data['username'] password = data['password'] # create directories dirs = [PHOTO_DIR, VIDEO_DIR] for d in dirs: if not os.path.exists(d): os.makedirs(d) # URLリストをロード urls_file = os.path.join(ROOT_DATA_DIR, '_urls.txt') url_list = [] with open(urls_file, 'r') as f: for i in f: url_list.append(i.rstrip('\n')) # Login bot = Bot(base_path=LOG_DIR) bot.login(username=username, password=password) # download files for url in url_list: # get like medias from your timeline feed try: media_id = bot.get_media_id_from_link(url) except: continue # get media info info = bot.get_media_info(media_id)[0] # download dummy_file = str(media_id) if info['media_type'] == 1: # photo bot.download_photo(media_id, filename=dummy_file, folder=PHOTO_DIR) elif info['media_type'] == 2: # video bot.download_video(media_id, filename=dummy_file, folder=VIDEO_DIR) # delete directories which have no data dirs = [PHOTO_DIR, VIDEO_DIR] for d in dirs: if not os.listdir(d): os.rmdir(d)
def main(username, password, profile): workdir = 'ig_%s' % profile try: os.makedirs(workdir) except FileExistsError: pass medias = [] bot = Bot() profile = clean_username(profile) bot.login(username=username, password=password) mids = bot.get_total_user_medias(profile) for mid in mids: media = bot.get_media_info(mid).pop() medias.append(media) media_type = media.get('media_type') if media_type == 1: bot.download_photo(mid, folder=os.path.join(workdir, 'photos'), save_description=True) elif media_type == 2: bot.download_video(mid, folder=os.path.join(workdir, 'videos'), save_description=True) open(os.path.join(workdir, 'dump.json'), 'w').write(json.dumps(medias)) return True