def __init__(self, user_profile: instaloader.Profile, old=False) -> None: self.username = user_profile.username self.unghosted_users = [] self.ghoster_users = [] self.follower_likes = {} self.unfollower_likes = {} self.sus = [] self.weishenmefollow = [] if old: print("Loading from file...") self.username += "_old" self.load_from_file() self.loaded_from_file = True print("Load from old successful") self.ghoster_init() self.follower_likes_init() self.why_following() self.sus_check() return if self.username in os.listdir(): check = input('Local copy ' 'of information available use that? y/n:\n') if check in ['y', 'Y']: print("Loading from file...") self.load_from_file() self.loaded_from_file = True print("Load successful") self.ghoster_init() self.follower_likes_init() self.why_following() self.sus_check() return print("Getting posts...") self.posts = list(user_profile.get_posts()) print("Done posts") print("Getting followers...") self.followers = list(user_profile.get_followers()) print("Done followers") print("Getting following...") self.following = list(user_profile.get_followees()) print("Done following") self.follower_amounts = {} # print("Getting following followers") # for following in self.following: # self.follower_amounts[following] = following.mediacount # print("Got following followers") self.likes = {} for i in self.posts: print(f"Getting likes:" f" {self.posts.index(i)}/{len(self.posts)} posts", end='\r') self.likes[i] = list(i.get_likes()) print(f"Getting likes: {len(self.posts)}/{len(self.posts)} posts") print("Done likes") self.ghoster_init() self.follower_likes_init() self.why_following() self.sus_check() self.loaded_from_file = False
def set_date_user(self, profile: Profile) -> datetime: """Obtains the latest post of the profile given and returns the date stamp of the post in UTC Args: profile (Profile): The profile to find the latest post of Returns: datetime: The UTC date stamp of the profiles latest post """ date_stamp = next(profile.get_posts()).date_utc return date_stamp
def update_posts(profile: Profile, limit: int = 10): """ Scrape last posts (limited by 'limit') and put into db table 'posts' """ sql = "REPLACE INTO posts (mediaid, userid) VALUES (?, ?);" with sqlite3.connect(DB_LOCATION) as conn: cursor = conn.cursor() for i, post in enumerate(profile.get_posts()): logging.debug( f"Scraped {profile.username}'s post with id {post.mediaid}") if i >= limit: break cursor.execute(sql, (post.mediaid, profile.userid)) logging.info("Table 'posts' is updated")
def save_data(instance: object, profile: Profile): """Saves profile and posts of the given profile Args: instance (object): An Instaloader object instance profile (instaloader.Profile): The user's profile data """ if not instance: raise TypeError('Instaloader instance is missing here!') if not profile: raise TypeError('Please, check whether profile is getting' 'the appropriate value before trying to save data') _create_local_directory(profile) instance.download_profiles([profile], posts=False) posts = profile.get_posts() for post in islice(posts, 0, 9): instance.download_post(post, target=profile.username)
def get_profile_posts(profile: Profile) -> NodeIterator[Post]: """ returns a iterable Post object """ return profile.get_posts()
def download_all_posts_by_profile(self, profile: Profile): for post in profile.get_posts(): self.download_post(post, profile.username)
def get_last_user_posts(self, username: str, count: int = 10) -> [Post]: self.logger.debug(f'Getting last posts for {username}') profile = Profile(self.c, {'username': username}) return [x for _, x in zip(range(count), profile.get_posts())]