Minor things

pull/5/head
Lasse Edfast 5 years ago
parent 388e8c71e9
commit ef6fe686da
  1. 35
      facebook/scrapers.py

@ -8,13 +8,17 @@ from helpers import sleep_, update_cookie, write_error, _print
def profile_picture_reactions( def profile_picture_reactions(
profile, user, all_pictures, first_user=False, mode="all" profile, user, first_user=False, mode="all"
): ):
#try: #try:
# Fixa url:er osv # Fixa url:er osv
if user.username.isnumeric(): if user.username.isnumeric():
user.url = url_bas + "/profile.php?id=" + str(user.username) user.url = url_bas + "/profile.php?id=" + str(user.username)
user.url_photos = user.url + "&v=photos" user.url_photos = user.url + "&v=photos"
user.id = user.username
else: else:
user.username = user.username.replace("/", "") user.username = user.username.replace("/", "")
user.url = url_bas + "/" + user.username user.url = url_bas + "/" + user.username
@ -22,18 +26,21 @@ def profile_picture_reactions(
# Gå till sidan för profilbilder # Gå till sidan för profilbilder
profile.browser.open(user.url_photos) profile.browser.open(user.url_photos)
#print(profile.viewing())
sleep_(4) sleep_(4)
if """You can't use Facebook because your account, or activity on it, doesn't follow our Community Standards.""" in profile.viewing(): if "Your Account Has Been Disabled." in profile.viewing():
_print(profile, user, f"{profile.name} blocked\n".upper(), sleeptime=1) _print(profile, user, f"{profile.name} blocked\n".upper(), sleeptime=1)
profile.blocked = True profile.blocked = True
return profile return profile
elif 'It looks like you were misusing this feature by going too fast.' in profile.viewing().text: elif 'It looks like you were misusing this feature by going too fast.' in profile.viewing().text:
sleep_(600) profile.blocked = True # Nu tar jag bort dem, kan göras på annat sätt kanske?
return profile
elif "accept all" in profile.viewing().text.lower(): elif "accept all" in profile.viewing().text.lower():
profile.accept_cookies() profile.accept_cookies()
profile.browser.open(user.url_photos) profile.browser.open(user.url_photos)
elif profile.viewing().find('title').text.strip() == 'Log in to Facebook | Facebook': elif profile.viewing().find('title').text.strip() == 'Log in to Facebook | Facebook':
sleep_(5)
profile.login() profile.login()
sleep_(5) sleep_(5)
profile.browser.open(user.url_photos) profile.browser.open(user.url_photos)
@ -48,9 +55,9 @@ def profile_picture_reactions(
except Exception as e: except Exception as e:
write_error( write_error(
6, 6,
profile,
e=e, e=e,
traceback=traceback.format_exc(), traceback=traceback.format_exc(),
profile=profile,
soup=profile.viewing(), soup=profile.viewing(),
user=user, user=user,
url=user.url_photos, url=user.url_photos,
@ -95,7 +102,7 @@ def profile_picture_reactions(
# Om profilen inte har profilalbum # Om profilen inte har profilalbum
if not hasattr(user, "url_album"): if not hasattr(user, "url_album"):
write_error(9, soup=profile.viewing(), user=user, profile=profile) write_error(9, profile, soup=profile.viewing(), user=user)
if user.url_other_pictures != []: if user.url_other_pictures != []:
# Använd eventuella extrabilder och ta bort den från användaren # Använd eventuella extrabilder och ta bort den från användaren
url_pics = user.url_other_pictures url_pics = user.url_other_pictures
@ -109,8 +116,8 @@ def profile_picture_reactions(
_print(profile, user, "Hittar inget album för profilbilder.") _print(profile, user, "Hittar inget album för profilbilder.")
write_error(#fel7 write_error(#fel7
7, 7,
profile,
soup=profile.viewing(), soup=profile.viewing(),
profile=profile,
user=user, user=user,
url=user.url_album, url=user.url_album,
url_name="user.url_album", url_name="user.url_album",
@ -164,7 +171,7 @@ def profile_picture_reactions(
return profile return profile
# except Exception as e: # except Exception as e:
# _print(profile, None, str(e)) # _print(None, str(e))
# return profile # return profile
@ -187,8 +194,8 @@ def check_picture(url_picture, user, profile):
except Exception as e: # Fel3 except Exception as e: # Fel3
write_error( write_error(
3, 3,
profile,
e=e, e=e,
profile=profile,
soup=profile.viewing(), soup=profile.viewing(),
user=user, user=user,
url=picture.url, url=picture.url,
@ -196,7 +203,7 @@ def check_picture(url_picture, user, profile):
traceback=traceback.format_exc(), traceback=traceback.format_exc(),
) )
update_cookie(profile.browser.session.cookies, profile.name) update_cookie(profile.browser.session.cookies, profile)
# Hitta info om bilden # Hitta info om bilden
try: try:
@ -246,7 +253,7 @@ def check_picture(url_picture, user, profile):
profile.browser.open(url_reactions) profile.browser.open(url_reactions)
update_cookie(profile.browser.session.cookies, profile.name) update_cookie(profile.browser.session.cookies, profile)
try: try:
for a in profile.viewing().find_all("a", {"class": "z ba"}, href=True): for a in profile.viewing().find_all("a", {"class": "z ba"}, href=True):
@ -259,8 +266,8 @@ def check_picture(url_picture, user, profile):
except UnboundLocalError: # fel9 except UnboundLocalError: # fel9
write_error( write_error(
9, 9,
profile,
user=user, user=user,
profile=profile,
soup=profile.viewing(), soup=profile.viewing(),
traceback=traceback.format_exc(), traceback=traceback.format_exc(),
url=url_reactions, url=url_reactions,
@ -280,7 +287,7 @@ def check_picture(url_picture, user, profile):
sleep_(4) sleep_(4)
profile.browser.open(url_limit) profile.browser.open(url_limit)
url_limit = "" url_limit = ""
update_cookie(profile.browser.session.cookies, profile.name) update_cookie(profile.browser.session.cookies, profile)
# Gå igenom alla som reagerat och för in i arango # Gå igenom alla som reagerat och för in i arango
for li in profile.viewing().find_all("li"): for li in profile.viewing().find_all("li"):
@ -307,10 +314,10 @@ def check_picture(url_picture, user, profile):
except AttributeError as e: # Fel1 except AttributeError as e: # Fel1
write_error( write_error(
1, 1,
profile,
e=e, e=e,
soup=str(li), soup=str(li),
user=user, user=user,
profile=profile,
traceback=traceback.format_exc(), traceback=traceback.format_exc(),
) )
pass pass
@ -328,9 +335,9 @@ def check_picture(url_picture, user, profile):
except Exception as e: # Fel2 except Exception as e: # Fel2
write_error( write_error(
2, 2,
profile,
e=e, e=e,
soup=profile.viewing(), soup=profile.viewing(),
profile=profile,
user=user, user=user,
url=url_limit, url=url_limit,
url_name="url_limit", url_name="url_limit",

Loading…
Cancel
Save