|
|
|
|
@ -7,7 +7,7 @@ from config import * |
|
|
|
|
from helpers import sleep_, update_cookie, write_error |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def profile_picture_reactions(profile, user, all_pictures, first=False, single = False): |
|
|
|
|
def profile_picture_reactions(profile, user, all_pictures, first_user=False, single = False): |
|
|
|
|
|
|
|
|
|
# Fixa url:er osv |
|
|
|
|
if user.username.isnumeric(): |
|
|
|
|
@ -51,7 +51,7 @@ def profile_picture_reactions(profile, user, all_pictures, first=False, single = |
|
|
|
|
user=user.username, |
|
|
|
|
url=user.url_photos, |
|
|
|
|
) |
|
|
|
|
if first == True: |
|
|
|
|
if first_user == True: |
|
|
|
|
print(profile.viewing().prettify()) |
|
|
|
|
exit() |
|
|
|
|
print( |
|
|
|
|
@ -61,13 +61,17 @@ def profile_picture_reactions(profile, user, all_pictures, first=False, single = |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# Hitta länk till olika saker hos användarem, inkl facebook-id |
|
|
|
|
user.id = "" |
|
|
|
|
|
|
|
|
|
for a in profile.viewing().find_all("a", href=True): |
|
|
|
|
if "Profile pictures" in a.text: |
|
|
|
|
user.url_album = url_bas + a["href"] # Länk till album för profilbulder |
|
|
|
|
if "profile_id" in a["href"]: |
|
|
|
|
l = a["href"] |
|
|
|
|
try: |
|
|
|
|
user.id = re.search("\d+", l[l.find("id=") + 3 :]).group(0) |
|
|
|
|
except: |
|
|
|
|
user.id = False |
|
|
|
|
|
|
|
|
|
if "Likes" in a.text: |
|
|
|
|
user.url_likes = url_bas + a["href"] |
|
|
|
|
if "About" in a.text: |
|
|
|
|
@ -88,8 +92,8 @@ def profile_picture_reactions(profile, user, all_pictures, first=False, single = |
|
|
|
|
else: |
|
|
|
|
# Spara ner profilen till databasen och avsluta sökningen på användaren |
|
|
|
|
user.url_album = False |
|
|
|
|
if first == False: |
|
|
|
|
user.doc['checked'] = True |
|
|
|
|
if first_user == False: |
|
|
|
|
user.checked() |
|
|
|
|
user.add_to_db() |
|
|
|
|
print('Hittar inget album för profilbilder.') |
|
|
|
|
write_error(7, soup=profile.viewing(), user=user.username, url=user.url_album, url_name='user.url_album') |
|
|
|
|
@ -113,23 +117,29 @@ def profile_picture_reactions(profile, user, all_pictures, first=False, single = |
|
|
|
|
user.profile_pictures = len(url_pics) |
|
|
|
|
except: |
|
|
|
|
user.profile_pictures = 0 |
|
|
|
|
user.doc['checked'] = True |
|
|
|
|
user.checked() |
|
|
|
|
user.add_to_db() |
|
|
|
|
return |
|
|
|
|
# Lägg till profilen till arrango |
|
|
|
|
user.add_to_db() |
|
|
|
|
|
|
|
|
|
# Gå igenom alla profilbilder |
|
|
|
|
if single == True and first == False: |
|
|
|
|
url_pics = url_pics[0] |
|
|
|
|
if single == True and first_user == False: |
|
|
|
|
url_pics = url_pics[:1] |
|
|
|
|
|
|
|
|
|
for pic in url_pics: |
|
|
|
|
if pic in all_pictures: |
|
|
|
|
return None |
|
|
|
|
# Skriv ut vilken bild som behandlas |
|
|
|
|
print(f"Bild {url_pics.index(pic) + 1} av {user.profile_pictures}", end="\r",) |
|
|
|
|
|
|
|
|
|
picture = Picture(user.username) |
|
|
|
|
picture.url = url_bas + pic |
|
|
|
|
picture.id = str(picture.url[picture.url.find("fbid=") + 5 :]) |
|
|
|
|
try: |
|
|
|
|
picture.id = str(re.search('\d+', picture.id).group()) |
|
|
|
|
except: |
|
|
|
|
pass |
|
|
|
|
# if picture.id in all_pictures: |
|
|
|
|
# print('Redan kollat bild', picture.id) |
|
|
|
|
# continue |
|
|
|
|
@ -185,7 +195,9 @@ def profile_picture_reactions(profile, user, all_pictures, first=False, single = |
|
|
|
|
|
|
|
|
|
# Hämta reaktioner för bilden |
|
|
|
|
sleep_(3) |
|
|
|
|
|
|
|
|
|
profile.browser.open(url_reactions) |
|
|
|
|
|
|
|
|
|
update_cookie(profile.browser.session.cookies, profile.name) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
@ -195,7 +207,7 @@ def profile_picture_reactions(profile, user, all_pictures, first=False, single = |
|
|
|
|
picture.no_reactions = re.search(r"total_count=(\d+)", url_limit).group(1) |
|
|
|
|
limit = re.search(r"limit=(\d+)", url_limit).group(1) |
|
|
|
|
except UnboundLocalError: #fel9 |
|
|
|
|
write_error(9, soup=profile.viewing(), traceback=traceback.format_exc()) |
|
|
|
|
write_error(9, soup=profile.viewing(), traceback=traceback.format_exc(), url=url_reactions, url_name='url_reactions') |
|
|
|
|
# Bilder med väldigt många likes går inte att visa så här? |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
@ -209,6 +221,7 @@ def profile_picture_reactions(profile, user, all_pictures, first=False, single = |
|
|
|
|
try: |
|
|
|
|
sleep_(4) |
|
|
|
|
profile.browser.open(url_limit) |
|
|
|
|
url_limit = '' |
|
|
|
|
update_cookie(profile.browser.session.cookies, profile.name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|