from storysave_api import get_hd_profile_picture import config, funcs, os db, cursor = config.gen_connection() cursor.execute(f"SELECT DISTINCT username, user_id FROM media WHERE user_id IS NOT NULL AND username IN (SELECT username FROM following WHERE platform = 'instagram');") usernames = cursor.fetchall() for username, user_id in usernames: profilepicurl = get_hd_profile_picture(user_id=user_id) if not profilepicurl: continue filename = os.path.basename(profilepicurl).split('?')[0] user_dir = os.path.join('media', 'instagram', 'profile', username) filepath = os.path.join(user_dir, filename) funcs.download_file(profilepicurl, filepath) print(f"Downloaded profile picture for {username}.")