from storysave_api import get_hd_profile_picture
import config , funcs , os , time
known_phashes = { ' e7c51a904b69d366 ' : ' default empty profile picture ' ,
' cb3ce46194c335dc ' : ' default empty profile picture ' ,
}
known_hashes = {
' 09c3cf34d4f117d99fa6285f4bfd3a0d888d7ab2cbca665b16097f6b93ca0de6 ' : ' default empty profile picture ' ,
' 2b9c0914d8f3f0aa6cf86705df70b7b21e9ca2f9013a346463788e7cebd0158f ' : ' default empty profile picture ' ,
}
db , cursor = config . gen_connection ( )
cursor . execute ( " SELECT DISTINCT username, user_id, favorite FROM following WHERE user_id IS NOT NULL AND platform = ' instagram ' ORDER BY favorite DESC; " )
usernames = cursor . fetchall ( )
for username , user_id , favorite in usernames :
profilepicurl = get_hd_profile_picture ( user_id = user_id )
if not profilepicurl :
print ( f ' Failed for { username } ' )
continue
filename = os . path . basename ( profilepicurl ) . split ( ' ? ' ) [ 0 ]
user_dir = os . path . join ( ' media ' , ' instagram ' , ' profile ' , username )
filepath = os . path . join ( user_dir , filename )
filepath = funcs . download_file ( profilepicurl , filepath )
if not filepath :
continue
phash = funcs . generate_phash ( filepath )
if phash in known_phashes :
print ( f " Profile picture for { username } is the default empty profile picture. " )
os . remove ( filepath )
continue
print ( f " Downloaded profile picture for { username } . " )
time . sleep ( 1 )