async def menu(message: types.Message): global user, userid, profile row = db.execute_one_query( conn, f'SELECT * FROM users WHERE user_id = "{message.from_user.id}"') msg = message.text if '/s/' in msg: await message.reply(key[row[1]][12]) elif 'instagram.com/p/' in msg: SHORTCODE = msg.split('/p/')[1].split('/?')[0] post = Post.from_shortcode(L.context, SHORTCODE) if post.owner_profile.is_private == True: await message.reply(key[row[1]][1]) else: await post_downloader(message, post=post) elif 'instagram.com/' in msg: user = msg.split('.com/')[1][0:-1] if '?' in msg: user = msg.split('.com/')[1].split('?')[0] profile = Profile.from_username(L.context, user) userid = profile.userid print(userid) if profile.is_private == True: await message.reply(key[row[1]][1]) else: await post_downloader(message, posts=1) else: try: msg = msg.replace('@', '') profile = Profile.from_username(L.context, msg) userid = profile.userid if profile.is_private == True: await message.reply(key[row[1]][1]) else: await post_downloader(message, posts=1) except: await message.reply(key[row[1]][2])
def load_photo_from_post(short_code): L = Instaloader(download_pictures=False, download_comments=False, compress_json=False, download_videos=True) try: post = Post.from_shortcode(L.context, short_code) except Exception: return {'status': 'bad'} L.download_post(post, target=short_code) super_json = glob.glob(short_code + '/*.json')[0] response = {} super_dict = json.loads(open(super_json).read()) if 'edge_sidecar_to_children' in super_dict['node']: response['img'] = [] for i in super_dict['node']['edge_sidecar_to_children']['edges']: response['img'].append(i['node']['display_resources']) else: response['img'] = [super_dict['node']['display_resources']] response['owner'] = super_dict['node']['owner'] response['status'] = 'ok' shutil.rmtree(short_code) return response
def instaPostDownloader(): shortcode = (request.data.decode().split(sep='/'))[4] try: #Post instances post = Post.from_shortcode(L.context, shortcode) #result list posts = [] if (post.mediacount > 1): for i, j in zip(range(post.mediacount), post.get_sidecar_nodes()): if (j.is_video): posts.append(j.video_url) else: posts.append(j.display_url) else: if (post.is_video): posts.append(post.video_url) else: posts.append(post.url) return jsonify({'Username': post.owner_username, 'posts': posts}) except Exception as exp: return jsonify({'Error': f'{exp}'})
def get_media_details(link): shortcode = link.split('/p/')[1].replace('/', '') post = Post.from_shortcode(L.context, shortcode) owner_profile = post.owner_profile full_name = owner_profile.full_name followers = owner_profile.followers followees = owner_profile.followees is_verified = owner_profile.is_verified is_private = owner_profile.is_private bio = owner_profile.biography external_url = owner_profile.external_url owner_username = post.owner_username url = post.url caption = post.caption caption_hashtags = post.caption_hashtags if len(caption_hashtags) == 0: caption_hashtags = None caption_mentions = post.caption_mentions if len(caption_mentions) == 0: caption_mentions = None is_video = post.is_video video_url = post.video_url if (is_video): media_url = video_url else: media_url = url likes = post.likes comments = post.comments return (full_name, followers, followees, is_verified, is_private, bio, external_url, owner_username, url, caption, caption_hashtags, caption_mentions, is_video, media_url, likes, comments)
def get_post_likers(shortcode, loader): try: post = Post.from_shortcode(loader.context, shortcode) except KeyError as e: logger.exception(f"Exception details: {e}") logger.error(f"HUMAN READABLE ERROR LOG:\n\ Could not create post from shortcode '{shortcode}'.\n\ Make sure:\n\t-the post is not deleted and \n\t-there is no typo in the shortcode \n then try again" ) sys.exit("Exited 1") except instaloader.QueryReturnedBadRequestException as e: remove_file(SESSION_FILE) logger.exception(f"Exception details: {e}") logger.error(f"HUMAN READABLE ERROR LOG:\n\ Well, I guess Instagram limited the Account '{USERNAME} again.\n\ Solve the captcha from instagram web and make sure the password is correct.\n\ If the problem persisted remove session file '{SESSION_FILE}'." ) telegram_send( TELEGRAM_ID, "Account limited", f"Account {USERNAME} was limited while fetching {HASHTAG} posts,\ solve captcha and and run the code again. it will resume automatically" ) sys.exit("DO ABOVE ADN RUN AGIAN.\nEXITED 1") post_likers = [] for liker_profile in post.get_likes(): post_likers.append(liker_profile.username.lower()) return post_likers
def getComments(): # print("This function will get comments") global btn_getRandom global label global usernames L = instaloader.Instaloader() post = Post.from_shortcode(L.context, 'CDjK4YqA5r6') usernames = list(set([comment.owner.username for comment in post.get_comments()])) #shuffling the list randomly random.shuffle(usernames) btn_getInfo.destroy() btn_getRandom = Button(canvas, text = "Randomly Select a Winner", font=("Helvetica", 12), command=selectWinner) canvas.create_window(250,200,window=btn_getRandom) label = Label(text = "Winner will be displayed here", font=("Helvetica", 12)) canvas.create_window(250,270,window=label) #let me remove my own account from the list : usernames.remove("femindharamshi") usernames.remove("beyondhelloworld") for user in sorted(usernames): print(user)
def Main_Ting(): L = instaloader.Instaloader() USER = str( pd.read_csv("Instagram_accounts.csv") ["AdminFollowing_Bot_Username"].iloc[0]) PASSWORD = str( pd.read_csv("Instagram_accounts.csv") ["AdminFollowing_Bot_Password"].iloc[0]) L.login(USER, PASSWORD) df1 = pd.read_csv( "Group_1/Leeching_Bot/Links_That_Need_To_Give_Engagment.csv") #df1["Links"].iloc[0] post = Post.from_shortcode(L.context, str(df1["Links"].iloc[0])) Username_Of_Owner = post.owner_username Following = instaloader.Profile.from_username( L.context, Username_Of_Owner).get_followees() df2 = pd.read_csv("Group_1/Group1_Admins_IG.csv", skiprows=1)["UserNames"] Num_Of_Admins_Following = 0 Num_Of_Admins_Not_Following = 0 Num_Of_Admins_Usernames = len(df2) Reminder_Messages_Sent = 0 Comment_Checker_Activated = 0 #Stops the comment checker to run more than once for i in Following: for x in df2: if str(x)[1:] in str(i): Num_Of_Admins_Following += 1 elif Num_Of_Admins_Following == Num_Of_Admins_Usernames and Comment_Checker_Activated == 0: #Checks their link becuase they are following all admins Comment_Checker_Activated += 1 import Group_1.Leeching_Bot.Like_Checker as Like_Checker Like_Checker.Main_Ting() import Group_1.Leeching_Bot.Comment_Checker as Comment_Checker Comment_Checker.Main_Ting() elif Num_Of_Admins_Not_Following > 0 and Reminder_Messages_Sent == 0 and Comment_Checker_Activated == 0: #Remind the user privately that they need to follow all admins Reminder_Messages_Sent += 1 Bot_With_Token = telegram.Bot( token=pd.read_csv("Group_1/Group1_Global_Settings.csv") ["Leeching_Bot_Key"].iloc[0]) Bot_With_Token.sendMessage( chat_id=str(df1["Link_User_Id"].iloc[0]), text= "@{} You MUST follow all the admins on Instagram before posting a link" .format(df1["User_Name"].iloc[0])) Bot_With_Token.sendMessage( chat_id=str(df1["Link_User_Id"].iloc[0]), text="{}".format(df2.to_string( header=False, index=False))) #TEST THISSSSSSSSSS else: #Runs when they are not folowing a admin Num_Of_Admins_Not_Following += 1
def download_insta_picture_from_post(url): shortcode = url.split("/")[-2] L = instaloader.Instaloader() post = Post.from_shortcode(L.context, shortcode) response = requests.get(post.url) if post.is_video: raise Exception('This post is a video, it will not be downloaded') return response.content
def download_photos(username): L = Instaloader(download_videos = False, download_video_thumbnails = False, download_comments = False, compress_json = False, dirname_pattern = "../Data/Photos/{target}") posts = [] with open("../Data/Posts_list/" + username + ".json") as f: posts = json.load(f) for post in posts: post = Post.from_shortcode(L.context, post) L.download_post(post, username)
def get_insta_links(url): try: shortcode = get_insta_shortcode(url) post = Post.from_shortcode(L.context, shortcode) return True, post except Exception as e: print(str(e)) return False, []
async def instagram_rip(self, shortcode, message): try: async with message.channel.typing(): post = Post.from_shortcode(self.insta.context, shortcode.group(2)) self.insta.download_post(post, "instagram") return True except TypeError: return False except Exception as e: await message.channel.send(f"Unable to download instagram post; error is {e}") return False
def users_list_from_post_shortcode_list(post_shortcode_list): print("Importing <1000 usernames for each post") likers=[] for shortcode in post_shortcode_list: post = Post.from_shortcode(L.context, shortcode) for liker in post.get_likes(): likers.append(liker.username) print(len(likers)) if len(likers) == 999: break return likers
def downloadMetadata(self): """Downloads metadata of this post to the database""" L = self.__startInstaloaderInstance() shortcode = self.metadata['photo_url'].split('/')[-2] profile = Profile.from_username(L.context, self.metadata['photographer_name']) post = Post.from_shortcode(L.context, shortcode) data_profile = profile._asdict( ) # accessing the metadata dict from the profile structure, UGLY data_post = post._asdict( ) # accessing the metadata dict from the post structure, UGLY metadata = {} metadata['photo_url'] = self.metadata['photo_url'] metadata['likes'] = post.likes ## TOO LONG STILL timestamp = str(data_post['taken_at_timestamp']) timetaken = datetime.datetime.fromtimestamp( int(timestamp)).strftime('%Y-%m-%d %H:%M:%S') datetimeFormat = '%Y-%m-%d %H:%M:%S' postdate = datetime.datetime.strptime(timetaken, datetimeFormat) time_now = datetime.datetime.now() dt = time_now - postdate TimeDifferenceInHours = dt.total_seconds() / 3600.0 TimeDifferenceInDays = TimeDifferenceInHours / 24.0 TimeDifferenceInDays = round(TimeDifferenceInDays, 2) metadata['age'] = TimeDifferenceInDays ## TOO LONG STILL metadata['downloaded'] = str(datetime.datetime.now()) # get image descriptions try: metadata['IG_category'] = \ data_post['edge_sidecar_to_children']['edges'][0]['node']['accessibility_caption'].split( 'Image may contain:')[1].split("\n")[0] except: metadata['IG_category'] = '' hashtags_original = post.caption_hashtags # reformating into one string with '#' in front if not hashtags_original: hashtags_original = self.scanCommentsForHashtags(data_post) hashtags = [] if hashtags_original: for tags in hashtags_original: hashtags.append('#' + tags) hashtags_str = str(hashtags).replace(",", "").replace("'", "").replace( "[", "").replace("]", "") metadata['hashtags'] = hashtags_str metadata['photographer_name'] = data_post['owner']['username'] metadata['followers'] = data_post['owner']['edge_followed_by']['count'] metadata['following'] = data_profile['edge_follow']['count'] metadata['photo_name'] = shortcode metadata[ 'is_downloaded'] = True # this method is only used for saved posts self.metadata = metadata print('| Metadata was scrapped') return metadata
def like_post(self): shortcode = list(self.posts).pop(0) post = Post.from_shortcode(self.context, shortcode) self.logger.info( f'Liking {post_url(post)} by {post.owner_username} ({len(self.posts)})' ) if not self.insta.like_post(post).viewer_has_liked: self.logger.warning( 'Liking is probably banned, removing session file') os.remove(self.session_file) raise BotExitException() self.posts.remove(shortcode)
def get_posts(urls): posts_dict = {} L = instaloader.Instaloader() for index, url in enumerate(urls): shortcode = url.split("/")[-2] # time.sleep(0.1) try: post = Post.from_shortcode(L.context, url.split("/")[-2]) posts_dict[shortcode] = post except: pass return posts_dict
def get_insta_links(L: Instaloader, url: str) -> tuple: """ Return list of shortcodes :param url: URL :return: success status and list of shortcodes """ try: shortcode = get_insta_shortcode(url) post = Post.from_shortcode(L.context, shortcode) return True, post except Exception as e: print(str(e)) return False, []
def downloadPic(self): """Downloads the jpg of this post (or all jpgs, if multiimage) to a folder named by the Instagram User Returns a True flag if image was saved Since this flag is not 100% reliable, this is complemented by the confirmPresenceOfJpg(self) method""" L = self.__startInstaloaderInstance() shortcode = self.metadata['photo_url'].split('/')[-2] profile = Profile.from_username(L.context, self.metadata['photographer_name']) post = Post.from_shortcode(L.context, shortcode) if post.is_video: self.postIsVideo = True picture_save_flag = L.download_post( post, target='DB' + profile.username, ) return picture_save_flag
def saveImageFromIG(url, templateName): shortedUrl = url.split('/')[4] print(shortedUrl) print(os.getcwd()) i = instaloader.Instaloader() print(os.getcwd()) post = Post.from_shortcode(i.context, shortedUrl) os.chdir('E:/Animatedtimes/Meme Maker Automation/V2') i.download_post(post, target='postIG') deleteALlTXT() os.chdir('postIG') webImage = os.listdir() for i in range(len(webImage)): os.chdir('../postIG') makeMemeWebImage(webImage[i], templateName) os.chdir('../postIG') os.remove(webImage[i])
def download_insta_picture_from_post(url, download_path): try: shortcode = url.split("/")[-2] L = instaloader.Instaloader() post = Post.from_shortcode(L.context, shortcode) response = requests.get(post.url) filename = shortcode + '.jpg' path = download_path + filename if post.is_video: print('Post skipped because its a video', url) return False with open(path, "wb") as handle: for data in tqdm(response.iter_content()): handle.write(data) return True except: print('Could not download file', sys.exc_info()[0], url) return False
def get_comments(post, skip_author, comment_text): L = Instaloader() post = Post.from_shortcode(L.context, post) owner_username = post.owner_username comments = [] for comment in post.get_comments(): if skip_author and owner_username == comment.owner.username: continue if comment_text: next_word = False for word in comment_text.split(','): if word not in comment.text: next_word = True if next_word: continue comments.append({ 'username': comment.owner.username, 'created_at': str(comment.created_at_utc), 'text': comment.text }) logging.info(f'Downloaded {len(comments)} comments') return comments
def is_shadowbaned(shortcode): L = Instaloader() POST = Post.from_shortcode(L.context, shortcode) DATE = POST.date #TODO regex from Link to get Shortcode DATE = POST.date hashtags_list = gh.get_hashtags(POST) shadow = False print(hashtags_list) for h in hashtags_list: count = 0 #status print('analizando', h) H = Hashtag.from_name(L.context, h) if shadow == True: break #This K is to work with uncronological random posts k = 0 #get the posts from the hashtag posts = H.get_posts() k_list = [] #----debug for p in posts: count += 1 postdate = p.date if p == POST: print(h, 'funded in', count) print('_____________________') break if postdate <= DATE: k += 1 k_list.append(k) #--debug #accept until 300 uncronological random posts if k == 300: shadow = True print(h, 'baneado') break else: continue
def get_post(client: Instaloader, shortcode: str) -> Post: """ returns a post object """ return Post.from_shortcode(client.context, shortcode)
import get_post_hashtags as gh from instaloader import Instaloader, Post, Hashtag def is_top(hashtags_list): for h in hashtags_list: count = 0 #status print('analyzing', h) H = Hashtag.from_name(L.context, h) #get the top posts from the hashtag top_posts = H.get_top_posts() for tp in top_posts: count += 1 if tp == POST: print(h, 'funded in', count) break print('-----------------------------------') if __name__ == '__main__': L = Instaloader() print('Paste the post link here:') SHORTCODE = input() POST = Post.from_shortcode(L.context, SHORTCODE) is_top(gh.get_hashtags(POST))
def get_media(self, context: InstaloaderContext) -> Union[None, Post]: return Post.from_shortcode(context, self.shortcode) if self.shortcode else None
def get_posters_from_shortcodes(hashtag: str, loader: instaloadercontext) -> list: shortcodes = {} posters = [] limited_accounts = [USERNAME] if "#" in hashtag: hashtag = hashtag.replace("#", "") logger.info(f"Finding posts with hashtag '{hashtag}'") if exists(TEMP_SHORTCODES) and exists(TEMP_POSTERS): posters = load_from_file(TEMP_POSTERS) shortcodes = load_from_file(TEMP_SHORTCODES) logger.info(f"Found temp files. Resuming...\ posts found so far: {len(posters)}") else: # post_iterator = instaloader.Hashtag.from_name(loader.context, hashtag).get_posts() post_iterator = NodeIterator( loader.context, "9b498c08113f1e09617a1703c22b2f32", lambda d: d['data']['hashtag']['edge_hashtag_to_media'], lambda n: instaloader.Post(loader.context, n), {'tag_name': hashtag}, f"https://www.instagram.com/explore/tags/{hashtag}/" ) for post in post_iterator: loader.download_post(post, target=hashtag) jsons = os.listdir(DOWNLOAD_PATH) for json_file in jsons: with open(f"{DOWNLOAD_PATH}/{json_file}", "r") as rf: post = json.load(rf) shortcode = post["node"]["shortcode"] shortcodes.setdefault(shortcode, False) not_visited = [x for x, visited in shortcodes.items() if not visited] logger.info( f"'{len(shortcodes)}' posts. not visited = {len(not_visited)}.") for shortcode, visited in shortcodes.items(): if not visited: try: post = Post.from_shortcode(loader.context, shortcode=shortcode) sleep(round(random.uniform(1.000, 2.100), 3)) posters.append(post.owner_username) print(f"{post.owner_username:<30}UTC {post.date}") shortcodes[shortcode] = True if len(posters) % 50 == 0: print(f"{get_time():>50}\tposts found so far: {len(posters)}") # except instaloader.QueryReturnedBadRequestException as e: # remove_file(SESSION_FILE) # dump_to_file(shortcodes, TEMP_SHORTCODES) # dump_to_file(posters, TEMP_POSTERS) # logger.error( # f"Bad Request Exception. Probably the account '{USERNAME}' was limited by instagram.\n\ # To solve this: First try to *(solve captcha)* from instagram web and *(verify phone number)* and change password # if required.\n") # telegram_send(TELEGRAM_ID, "Account limited", # f"Account {USERNAME} was limited, solve captcha and when it was no longer limited, press enter") except KeyError: logger.info(f"KeyError, Post {shortcode} not found.") except Exception as e: remove_file(SESSION_FILE) dump_to_file(shortcodes, TEMP_SHORTCODES) dump_to_file(posters, TEMP_POSTERS) logger.error(f"Exception while fetching posters! Details: {e}") logger.info( "Saved posters and shortcodes. Trying to switch account...") for uname in LOGIN_CREDS.keys(): if uname not in limited_accounts: limited_accounts.append(uname) logger.info( f"Switched to account {uname}. Go to login activity and 'click This Was Me'") loader = instaloader_init( ig_user=uname, ig_passwd=LOGIN_CREDS[uname]) break else: logger.info( "All accounts were limited. 1. solve the captcha 2. change password if needed. Then press ENTER to login interactively") uname = input("enter instagram username: "******"{date_utc:%Y-%m-%d_%H-%M-%S}-{shortcode}", sleep=True, download_pictures=False, post_metadata_txt_pattern="", compress_json=False, download_geotags=False, save_metadata=True, download_comments=False, download_videos=False, download_video_thumbnails=False) loader.interactive_login(uname) except KeyboardInterrupt: dump_to_file(shortcodes, TEMP_SHORTCODES) dump_to_file(posters, TEMP_POSTERS) logger.error("keyboardInterrupt. Saved posters and shortcodes") sys.exit("Exited 1") # Double check shortcodes and remove temporary files if all shortcodes are visited for shortcode, visited in shortcodes.items(): if not visited: print(f"shortcode '{shortcode}' is not visited yet.") remove_file(TEMP_POSTERS) remove_file(TEMP_SHORTCODES) shutil.rmtree(DOWNLOAD_PATH) return posters
def Main_Ting(): import instaloader from instaloader import Post import pandas as pd import csv L = instaloader.Instaloader() USER = str( pd.read_csv("Instagram_accounts.csv")["Leeching_Bot_Username"].iloc[0]) PASSWORD = str( pd.read_csv("Instagram_accounts.csv")["Leeching_Bot_Password"].iloc[0]) L.login(USER, PASSWORD) # --------------------------- Number_Of_Engagment = 0 DX_Number = pd.read_csv("Group_1/Group1_Settings.csv")["DxNum"].iloc[0] Posts_Checked = 0 All_Posts_Leached = 0 Num_Of_Lines_Parsed = 0 # --------------------------- df1 = pd.read_csv( "Group_1/Leeching_Bot/Links_That_Need_To_Give_Engagment.csv") df2 = pd.read_csv( "Group_1/Leeching_Bot/Links_That_Need_To_Get_Engagment.csv") df3 = pd.read_csv("Group_1/Group1_Premium.csv") # ---------------------- for Account_From_File_That_Need_To_Give_Engagment in reversed( df1["Links"].dropna()): for Loop_Over_Chat_IDs in reversed(df1["Link_Chat_Id"]): for Loop_Over_Message_IDs in reversed(df1["Link_Message_Id"]): for Loop_Over_UserID in reversed(df1["Link_User_Id"]): for Loop_Over_UserNames in reversed(df1["User_Name"]): for Loop_Over_Premium_Usernames in reversed( df3["UserNames"]): Num_Of_Lines_Parsed += 1 if Num_Of_Lines_Parsed == len(df3) or str( Loop_Over_Premium_Usernames ).lower()[1:] == str(Loop_Over_UserNames).lower( ): # Allowed to enter the if statment if it has checked ALL the usernames in premium csv file or if a premium username matches the sender's username if str(Loop_Over_Premium_Usernames).lower( )[1:] != str(Loop_Over_UserNames).lower( ): # Runs if they are not a premium user Identify_Post_That_Need_To_Give_Engagment = Post.from_shortcode( L.context, Account_From_File_That_Need_To_Give_Engagment ) Username_Of_Post_That_Need_To_Give_Engagment = Identify_Post_That_Need_To_Give_Engagment.owner_profile # ------------------------------------------------------------ for Each_Post_From_File_That_Need_To_Get_Engagment in df2[ "Links"].tail(DX_Number): Posts_Checked += 1 Number_Likes_Checked = 0 Number_Likes_Matched = 0 Identify_Post_That_Need_Engagment = Post.from_shortcode( L.context, Each_Post_From_File_That_Need_To_Get_Engagment ) Likes_From_Post_That_Need_Engagment = Identify_Post_That_Need_Engagment.get_likes( ) All_Likes_With_Username = [] for Like in Likes_From_Post_That_Need_Engagment: All_Likes_With_Username.append( Like) if All_Likes_With_Username != []: #This runs if the post has likes. for Loop_Over_Usernames in All_Likes_With_Username: Number_Likes_Checked += 1 if Loop_Over_Usernames == Username_Of_Post_That_Need_To_Give_Engagment: Number_Likes_Matched += 1 Number_Of_Engagment += 1 #Do i need this??? elif Number_Likes_Checked == len( All_Likes_With_Username ) and Number_Likes_Matched == 0: df1 = pd.read_csv( "Group_1/Leeching_Bot/Leached_Posts.csv" ) df1.loc[ len(df1), "Leached_Likes"] = Each_Post_From_File_That_Need_To_Get_Engagment df1.to_csv( "Group_1/Leeching_Bot/Leached_Posts.csv", index=False) else: # This else clause runs when the like isnt the users like pass elif All_Likes_With_Username == []: #This runs if the post dosn't have likes. df1 = pd.read_csv( "Group_1/Leeching_Bot/Leached_Posts.csv" ) df1.loc[ len(df1), "Leached_Likes"] = Each_Post_From_File_That_Need_To_Get_Engagment df1.to_csv( "Group_1/Leeching_Bot/Leached_Posts.csv", index=False) else: #I don't know why this is running??? pass else: # Runs when it hasn't loop over all the links or when the sender's username dosnt match a premium user's username. pass
from datetime import time #LOGIN INSTABOT# bot = instabot.Bot() bot.login(username = "******", password = "******") #LOGIN INSTALOADER# L = instaloader.Instaloader() L.login("patagonian_review","Comandos1") #Creo objeto de clase Profile# profile=Profile.from_username(L.context,"igalkej") #Creo objeto de clase Post# post = Post.from_shortcode(L.context, "Bh1wRc9Ha9VwwsHAFcHP-viJuh-favoZw0BB4U0") #Get followees from profile# print("{} follows these profiles:".format(profile.username)) for followee in profile.get_followees(): print(followee.username) #Get usernames for hashtaf def users_list_from_hashtags(hashtags): print("Importing ~ 85 usernames for each hashtag") hashtag_users = [] hashtag_usernames = []
description="Get images from the specified Instagram post.", guild_ids=hkd.get_all_guild_ids(), options=[ create_option(name="url", description="URL of the Instagram post.", option_type=3, required=True) ]) @commands.cooldown(1, 10, BucketType.guild) async def instapics(self, ctx: SlashContext, url: str): await ctx.defer() if not ((shortcode := hkd.get_id_from_url(url, '/p/', '/')) or (shortcode := hkd.get_id_from_url(url, '/reel/', '/'))): return images, videos = [], [] post = Post.from_shortcode(self.insta_api.context, shortcode) if post.typename == 'GraphSidecar': for node in post.get_sidecar_nodes(): if node.is_video: videos.append(node.video_url) else: images.append(node.display_url) elif post.typename == 'GraphImage': images.append(post.url) elif post.typename == 'GraphVideo': videos.append(post.video_url) await hkd.send_content_with_delay(ctx, images) await hkd.send_content_with_delay(ctx, videos) @cog_ext.cog_slash( description="Get images from the specified Ameba blog post.",
def get_post_from_shortcode(self, SHORTCODE: str, MAX_COMMENT: int): post = Post.from_shortcode(self.L.context, SHORTCODE) try: accessibility_caption = str( post._asdict()['accessibility_caption']) except Exception as ex: print(ex) try: location = post.location except Exception as ex: print(ex) location = None #INFORMATION OF THE POST GOING INTO THE CSV post_info_dict = { 'title': post.title, 'owner_username': post.owner_username, 'date_and_time': post.date, 'type_of_post': post.typename, 'mediacount': post.mediacount, 'caption': post.caption, 'n_caption_hashatags': len(post.caption_hashtags), 'caption_hashtags': post.caption_hashtags, 'n_mentions_post': len(post.caption_mentions), 'n_tagged_users': len(post.tagged_users), 'is_video': post.is_video, 'n_likes': post.likes, 'n_comments': post.comments, 'is_sponsored': post.is_sponsored, 'sponsors': post.sponsor_users, 'location': location, 'url_link': post.url, 'url_insta': 'instagram.com/p/{}/'.format(post.shortcode), 'description_of_post': accessibility_caption, } comments_vect = [] # DOWNLOAD AND STORE COMMENT print('Start Comments', end='') comment_count = 0 for comment in post.get_comments(): answer_count = 0 for answer in comment.answers: answer_count += 1 if answer_count == 50: break analisys, score = self.analizer.return_sentiment( str(comment.text).strip()) comment_info_dict = { 'date_and_time': comment.created_at_utc, 'profile': comment.owner.username, 'text': str(comment.text).strip(), 'n_likes': comment.likes_count, 'answer_count': answer_count, 'sentiment_analysis': analisys, 'score': score } comments_vect.append(comment_info_dict) if comment_count == MAX_COMMENT: break comment_count += 1 print('.', end='') print('End Comments') comment_df = pd.DataFrame(comments_vect) post_df = pd.DataFrame([post_info_dict]) return post_df, comment_df
ids_list = f.read() ids_list = ids_list.split('\n') L = Instaloader() for username in ids_list: print("Downloading data for :", username) post_likes = {} data_dir = os.path.join("data", "raw", username) ce_files_lst = glob.glob(os.path.join(data_dir, "*.txt")) for ce_file in tqdm(ce_files_lst): try: post_shortcode = re.sub(data_dir + '/', '', os.path.splitext(ce_file)[0]) post = Post.from_shortcode(L.context, post_shortcode) profiles_that_liked_post = [] for profile in post.get_likes(): profiles_that_liked_post.append(profile.userid) post_likes[post_shortcode] = profiles_that_liked_post except Exception: continue with open(data_dir + "-likes.p", 'wb') as handle: pickle.dump(post_likes, handle, protocol=pickle.HIGHEST_PROTOCOL)