コード例 #1
0
ファイル: update_db.py プロジェクト: Likbjorn/instamonitor
def update_followings(profile: Profile):
    # TODO: use batches to update
    """
    Scrape profile followings (profiles that are followed by profile) and update db
    :param profile: instaloader.Profile - whose followings to scrape
    :return:
    """
    with sqlite3.connect(DB_LOCATION) as conn:
        cursor = conn.cursor()
        # add user profile to profiles
        sql_main_user = "******" \
                        "VALUES (?, ?, ?);"
        row = (profile.userid, profile.username, profile.full_name)
        cursor.execute(sql_main_user, row)

        sql_profiles = "REPLACE INTO profiles (userid, username, full_name) " \
                       "VALUES (?, ?, ?);"
        sql_followers = "REPLACE INTO followers (userid, follower_id) " \
                        "VALUES (?, ?);"
        for following in profile.get_followees():
            logging.debug(
                f"Scraped {profile.username}'s following {following.username}")
            # update profiles table
            row_profiles = (following.userid, following.username,
                            following.full_name)
            cursor.execute(sql_profiles, row_profiles)

            # update followers table
            row_followers = (following.userid, profile.userid)
            cursor.execute(sql_followers, row_followers)
    logging.info("Tables 'profiles' and 'followers' are updated")
コード例 #2
0
 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