Lot of changes

pull/5/head
Lasse Edfast 5 years ago
parent 1209aed235
commit 2edad4870c
  1. 175
      facebook/__main__.py
  2. 65
      facebook/arangodb.py
  3. 111
      facebook/classes.py
  4. 92
      facebook/scrapers.py

@ -7,19 +7,52 @@ from subprocess import check_output
from re import split from re import split
from socket import gethostname from socket import gethostname
from arangodb import db, write_report, backup, report_blocked, get_profile, remove_profile, checked_members, friends_of_user from arangodb import *
from classes import Profile, User from classes import Profile, User
from helpers import sleep_, write_error, _print from helpers import sleep_, write_error, _print
from scrapers import profile_picture_reactions from scrapers import profile_picture_reactions
def finish(): def finish(profile, profiles, users):
""" Avslutar: skriver rapport och gör profilerna oanvända """ """ Avslutar: skriver rapport och gör profilerna oanvända """
for profile in profiles: for profile in profiles:
profile.unused() profile.unused()
write_report(users, list(all_pictures.difference(all_pictures_start))) try:
e = traceback.format_exc()
except:
e = 'Unknown traceback.'
_print(profile, None, e.split('\n'))
write_report(users)
exit() exit()
def blocked_profile(profile, profiles):
""" Tar bort profilen från listan med profiles, tar bort ur databasen och returnerar uppdaterad lista. """
report_blocked(profile, users)
remove_profile(profile)
# Ta bort från listan på fb-profiler som används
profiles.remove(profile)
# Försök lägga till en ny fb-profil (om det finns en skapad och ledig i databasen)
try:
doc = get_profile()
profiles.append(Profile(doc, lookingup))
_print(profile, None, f"Laddat ny profil: {profiles[-1].name}")
sleep(3)
except:
_print(profile, None, "Det behövs nya profiler...")
if len(profiles) == 0:
finish(profile, profiles, users)
for s in range(0, int(1600 / len(profiles))):
print(user, f"Sover {600-s} sekunder till... ", end="\r")
_print(profile, None, 'Långsover...')
for s in range (3600, 0, -1):
print(f'Sover {s} sekunder till...', end='\r')
sleep(1)
return profiles
if __name__ == "__main__": if __name__ == "__main__":
print() print()
@ -27,12 +60,12 @@ if __name__ == "__main__":
if gethostname() not in ['macbook.local']: # Lägg till för studiodatorn if gethostname() not in ['macbook.local']: # Lägg till för studiodatorn
# Hämta namn för containern där skriptet körs # Hämta namn för containern där skriptet körs
try: try:
containers = check_output(['docker', 'container', 'ls']).decode() lookingups = check_output(['docker', 'lookingup', 'ls']).decode()
container = split('\W\W+', containers.split('\n')[1])[-1] lookingup = split('\W\W+', lookingups.split('\n')[1])[-1]
except FileNotFoundError: except FileNotFoundError:
pass pass
else: else:
container_name = 'macbook' lookingup_name = 'macbook'
# Argument och alternativ # Argument och alternativ
argv = argv[1:] argv = argv[1:]
@ -41,7 +74,7 @@ if __name__ == "__main__":
for o, a in opts: for o, a in opts:
# mode_nr används för hur ofta profile ska roteras # mode_nr används för hur ofta profile ska roteras
if o in ["-m", "--mode"]: if o in ["-m", "--mode"]:
mode = a mode = a.strip()
if mode == 'single': if mode == 'single':
mode_nr = 1.7 mode_nr = 1.7
elif mode == 'few': elif mode == 'few':
@ -62,7 +95,7 @@ if __name__ == "__main__":
except StopIteration: except StopIteration:
raise Exception raise Exception
if o in ["-o", "--other"]: if o in ["-o", "--other"]:
url_other_picture = a url_other_pictures = a.split(',')
if o in ['-b', '--backup']: if o in ['-b', '--backup']:
while True: while True:
backup(db) backup(db)
@ -85,26 +118,29 @@ if __name__ == "__main__":
if mode == '': if mode == '':
mode = 'all' mode = 'all'
if "url_other_picture" in globals(): if "url_other_pictures" in globals():
users[0].url_other_picture = url_other_picture[url_other_picture.find('facebook.com') + 12:] l = []
for url in url_other_pictures:
l.append(url[url.find('facebook.com') + 12:])
users[0].url_other_pictures = l
print("Kollar profilbilder för:") print("Kollar profilbilder för:")
for user in users: for user in users:
print("-", user.username) print("-", user.username)
print() print()
if 'container' not in globals(): if 'lookingup' not in globals():
usernames = [user.username for user in users] usernames = [user.username for user in users]
if len(usernames) == 1: if len(usernames) == 1:
container = usernames[0] lookingup = usernames[0]
else: else:
container = '-'.join(usernames) lookingup = '-'.join(usernames)
# Skapa tre olika profiler att besöka Facebook med # Skapa tre olika profiler att besöka Facebook med
profiles = [] profiles = []
for i in range(0, 3): for i in range(0, 3):
doc = get_profile() doc = get_profile()
profile = Profile(doc, container) profile = Profile(doc, lookingup)
profile.browser.open("https://api.ipify.org") profile.browser.open("https://api.ipify.org")
print(f"Profil {profile.name} använder IP-adress {profile.viewing().text}." print(f"Profil {profile.name} använder IP-adress {profile.viewing().text}."
) )
@ -116,106 +152,123 @@ if __name__ == "__main__":
print() print()
sleep(3) sleep(3)
profile_nr = 1 profile_nr = 0
profile = profiles[profile_nr] profile = profiles[profile_nr]
_print(profile.container, user.username, f"Börjar med profilen {profile.name}") _print(profile, user, f"Börjar med profilen {profile.name}")
# Gå igenom de användare som efterfrågats # Gå igenom de användare som efterfrågats
try: #try:
while True: while True:
for user in users: for user in users:
profile.users_checked += 1
# Set för kollade bilder och kollade medlemmar # Set för kollade bilder och kollade medlemmar
all_pictures = set([doc["_key"] for doc in db.collection("pictures").all()]) all_pictures = set([doc["_key"] for doc in db.collection("pictures").all()])
all_pictures_start = all_pictures.copy() all_pictures_start = all_pictures.copy()
members_checked = checked_members() members_checked = checked_members()
profile.container = user.username for p in profiles:
p.lookingup = user.username
# Hämta reaktioner för den första användaren # Hämta reaktioner för den första användaren
if any([user.username not in members_checked, mode == 'force']): if any([user.username not in members_checked, mode == 'force']):
try: try:
profile_picture_reactions(profile, user, all_pictures, first_user=True, mode=mode) t = 0
while t < 5:
t += 1
profile = profile_picture_reactions(profile, user, all_pictures, first_user=True, mode=mode)
if profile.blocked == True:
profiles = blocked_profile(profile, profiles)
else:
break
except: except:
_print(profile.container, user.username, traceback.format_exc()) _print(profile, user, traceback.format_exc())
if len(users) == 1: if len(users) == 1:
for profile in profiles: for p in profiles:
profile.unused() p.unused()
friends = friends_of_user(user.username) friends = friends_of_user(user.username)
friends_unchecked = list(set(friends) - set(members_checked)) friends_unchecked = list(set(friends) - set(members_checked))
_print(profile, user, f"\nKlar med, {user.username}\n")
_print(profile.container, user.username, f"\nKlar med, {user.username}\n") _print(profile, user, f"Vänner som reagerat: {len(friends)}")
_print(profile.container, user.username, f"Vänner som reagerat: {len(friends)}") _print(profile, user, "\nVänner att kolla:")
_print(profile.container, user.username, "\nVänner att kolla:")
for friend in friends_unchecked: for friend in friends_unchecked:
print(friend) print(friend)
_print(profile.container, user.username, ', '.join([friend for friend in friends_unchecked]), silent=True) _print(profile, user, [friend for friend in friends_unchecked], silent=True)
print() print()
# Hämta reaktioner för users vänner (som reagerat) # Hämta reaktioner för users vänner (som reagerat)
count_friends = 0 count_friends = 0
for friend in friends_unchecked: for friend in friends_unchecked:
profile.users_checked += 1
if profile.users_checked > 30:
_print(profile, None, 'Långsover...')
for s in range(2600, 0, -1):
print(f'Sover {s} sekunder till...', end='\r')
sleep(1)
for p in profiles:
_print(p, None, f'Långsovit. {p.name} hade kollat {p.users_checked} användare.')
p.users_checked = 0
count_friends += 1 count_friends += 1
user = User(str(friend), mode) user = User(str(friend), mode, other_pictures=[])
sleep_(2) sleep_(2)
try: try:
profile_picture_reactions( p = profile_picture_reactions(
profile, user, all_pictures, mode=mode profile, user, all_pictures, mode=mode
) )
if isinstance(p, Profile):
profile = p
except Exception as e: # Fel4 except Exception as e: # Fel4
write_error( write_error(
4, 4,
e=e, e=e,
user=user.username, user=user,
profile=profile.container, profile=profile,
traceback=traceback.format_exc(), traceback=traceback.format_exc(),
soup=profile.viewing(), soup=profile.viewing(),
) )
_print(profile.container, user.username, f"\nFel: {str(user.username)}\n") _print(profile, user, f"\nFel: {str(user.username)}\n")
sleep_(15) sleep_(15)
if profile.blocked == False: if profile.blocked == False:
_print(profile.container, user.username, f"Klar med {user.username} \n") _print(profile, user, f"Klar med {user.username} \n")
# Rotera fb-profiler # Rotera fb-profiler
if count_friends > 5 * mode_nr: if count_friends > 5 * mode_nr:
if random.randrange(0, 2, 1) == 1: if random.randrange(0, 2, 1) == 1:
profile_nr += 1 profile_nr += 1
if profile_nr >= len(profiles):
profile_nr = 0
count_friends = 0 count_friends = 0
_print(profile.container, user.username, f"Växlar till {profiles[profile_nr].name}") _print(profile, user, f"Växlar till {profiles[profile_nr].name}")
elif count_friends > 9 * mode_nr: elif count_friends > 9 * mode_nr:
profile_nr += 1 profile_nr += 1
count_friends = 0 if profile_nr >= len(profiles):
_print(profile.container, user.username, f"Växlar till {profiles[profile_nr].name}")
if profile_nr > len(profiles) - 1:
profile_nr = 0 profile_nr = 0
count_friends = 0
_print(profile, user, f"Växlar till {profiles[profile_nr].name}")
profile = profiles[profile_nr]
elif profile.blocked == True: elif profile.blocked == True:
# Ta bort profilen ur databasen _print(profile, user, f"Tar bort {profile.name}\n".upper(), sleeptime=1)
report_blocked(profile, users) profiles = blocked_profile(profile, profiles)
remove_profile(profile.doc) profile_nr =len(profiles) -1
# Ta bort från listan på fb-profiler som används
profiles.remove(profile)
# Försök lägga till en ny fb-profil (om det finns en skapad och ledig i databasen)
try:
doc = get_profile()
profiles[profile_nr] = Profile(doc, container)
_print(profile.container, user.username, f"Laddat ny profil: {profiles[profile_nr].name}")
sleep(3)
except e:
_print(profile.container, user.username, "Det behövs nya profiler...")
if len(profiles) == 0:
break
for s in range(0, 1600 / len(profiles)):
print(user, f"Sover {600-s} sekunder till... ", end="\r")
profile_nr += 1
_print(profile.container, user.username, f"Försöker med {profiles[profile_nr].name}.")
profile = profiles[profile_nr] profile = profiles[profile_nr]
_print(profile, None, [p.name for p in profiles])
except: # Hämta ny användare från databasen (lookups) när alla är genomgångna
finish() doc_new_user = get_user()
if doc_new_user == None:
_print(profile, user, 'No more to look up.')
finish(profile, profiles, users)
else:
new_user = User(doc_new_user['_key'], mode, doc_new_user['other'])
for p in profiles:
p.lookingup = new_user.username
users.append(new_user)
# except:
# finish(profile, profiles, users)

@ -32,8 +32,7 @@ except FileNotFoundError:
db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd) db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd)
from helpers import now, _print from helpers import now, _print, nowstamp
def checked_members(): def checked_members():
cursor = db.aql.execute( cursor = db.aql.execute(
@ -59,34 +58,29 @@ def count_docs(col):
return cursor.next() return cursor.next()
def report_blocked(profile, users): def report_blocked(profile, users):
db.insert_document({ db.insert_document('reports', {
'_id':f'reports/{now()}', '_key':now(),
'profile': profile.name, 'profile': profile.name,
'users': [user.username for user in users], 'users': [user.username for user in users],
}) }, overwrite=True)
def write_report(users, pictures): def write_report(users):
db.insert_document({ db.insert_document('reports', {
'_id':f'reports/{now()}', '_key':now(),
'users': [user.username for user in users], 'users': [user.username for user in users]
'members': count_docs('members'), }, overwrite=True)
'total_picture_reactions':count_docs('picture_reactions'),
'pictures':count_docs('pictures'),
'new_pictures': pictures
})
def get_profile(created=True): def get_profile(db=db):
""" Hämtar profil från profiles """ """ Hämtar profil från profiles """
cursor = db.aql.execute( cursor = db.aql.execute(
""" """
FOR doc IN profiles FOR doc IN profiles
FILTER doc.in_use == false FILTER doc.in_use < @inuse
FILTER doc.created == @created
RETURN doc RETURN doc
""", """,
bind_vars={'created': created} bind_vars={'inuse': nowstamp() - 600}
) )
return cursor.next() return cursor.next()
@ -105,12 +99,35 @@ def friends_of_user(user):
def remove_profile(profile): def remove_profile(profile):
db.collection("profiles").delete(profile['_key'], silent=True, ignore_missing=True)
_print(profile.container, f'{profile.name} blockerad och borttagen {now()}.' db.collection("profiles").delete(profile.doc['_key'], silent=True, ignore_missing=True)
_print(profile, None, f'{profile.name} blockerad och borttagen {now()}.'
) )
# TODO #2 Bättre funktion för backup av databasen # TODO #2 Bättre funktion för backup av databasen
def arango_connect(pwd):
return ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd)
def get_user():
""" Hämtar användare att kolla upp från lookups """
cursor = db.aql.execute(
"""
FOR doc IN lookups
RETURN doc
"""
)
try:
doc = cursor.next()
if 'other' not in doc:
doc['other'] = []
db.collection("lookups").delete(doc['_key'])
except StopIteration:
doc = None
return doc
def backup(db): def backup(db):
"""Skapar en json-backup för specificerade collections. """Skapar en json-backup för specificerade collections.
@ -127,5 +144,13 @@ def backup(db):
json.dump(d, f) json.dump(d, f)
print(f'Senaste backup: {now()}') print(f'Senaste backup: {now()}')
def used_servers():
cursor = db.aql.execute(
"""
FOR doc IN profiles
RETURN doc._key
"""
)
return [doc for doc in cursor]
db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd) db = ArangoClient(hosts=host_arango).db(db_arango, username=user_arango, password=pwd)

@ -11,25 +11,30 @@ from robobrowser import RoboBrowser
from arangodb import db from arangodb import db
from config import * from config import *
from helpers import sleep_, update_cookie from helpers import sleep_, update_cookie, write_error, nowstamp
class User: class User:
def __init__(self, username, mode): def __init__(self, username, mode, other_pictures=[]):
self.collection = "members" self.collection = "members"
self.username = str(username) self.username = str(username)
self.mode = mode self.mode = mode
self.fetched = datetime.now().strftime("%Y%m%d") self.fetched = datetime.now().strftime("%Y%m%d")
self.url_coverphotos = '' self.url_coverphotos = ""
self.id = '' self.id = ""
self.url_likes = '' self.url_likes = ""
self.url_about = '' self.url_about = ""
self.url_timeline = '' self.url_timeline = ""
self.profile_pictures = '' self.url_profilepictures = ""
self.url = '' self.profile_pictures = 0
self.name = '' self.pictures = []
self.url_other_picture = '' self.url_friends = ""
self.url = ""
self.name = ""
self.url_other_pictures = other_pictures
self.reactions = 0 self.reactions = 0
self.profile_pictures = 0
self.checked_pictures = []
def add_to_db(self): def add_to_db(self):
# Lägg till profilen till arrango # Lägg till profilen till arrango
@ -47,11 +52,12 @@ class User:
"cover photos": self.url_coverphotos, "cover photos": self.url_coverphotos,
"fetched": self.fetched, "fetched": self.fetched,
"reactions": self.reactions, "reactions": self.reactions,
'mode': self.mode "mode": self.mode,
"pictures": self.pictures,
}, },
overwrite_mode="update", overwrite_mode="update",
silent=True, silent=True,
keep_none=False keep_none=False,
) )
def checked(self): def checked(self):
@ -59,21 +65,22 @@ class User:
{ {
"_id": "members/" + str(self.username), "_id": "members/" + str(self.username),
"checked": True, "checked": True,
"pictures_checked": self.profile_pictures, "pictures_checked": len(self.checked_pictures),
"reaction": self.reactions "checked_pictures": self.checked_pictures,
}) "reactions": self.reactions,
}
)
class Picture: class Picture:
def __init__(self, user): def __init__(self, user):
self.collection = "pictures" self.collection = "pictures"
self.user = user self.user = user
self.id = '' self.id = ""
self.url_full = '' self.url_full = ""
self.date = '' self.date = ""
self.url = '' self.url = ""
self.no_reactions = '' self.no_reactions = ""
self.reactions = [] self.reactions = []
def add_to_db(self): def add_to_db(self):
@ -89,21 +96,22 @@ class Picture:
}, },
overwrite_mode="update", overwrite_mode="update",
silent=True, silent=True,
keep_none=False keep_none=False,
) )
class Profile: class Profile:
def __init__(self, profile, container): def __init__(self, profile, lookingup):
""" Creates a new profile to do searches with. """Creates a new profile to do searches with.
Args: Args:
profile (dict): Document fetched from database. profile (dict): Document fetched from database.
container (string): Container name. lookingup (string): Container name.
""" """
# Uppdatera dokumentet i arango # Uppdatera dokumentet i arango
self.doc = profile self.doc = profile
self.doc['in_use'] = True self.doc["in_use"] = nowstamp()
db.update_document(self.doc, check_rev=False) db.update_document(self.doc, check_rev=False)
# Användaruppgifter # Användaruppgifter
@ -111,9 +119,12 @@ class Profile:
self.email = self.doc["email"] self.email = self.doc["email"]
self.pwd = self.doc["pwd"] self.pwd = self.doc["pwd"]
self.server = self.doc["server"] self.server = self.doc["server"]
self.cookie = self.doc["cookie"]
self.useragent = self.doc["useragent"]
self.blocked = False self.blocked = False
self.container = container self.lookingup = lookingup
self.users_checked = 0
# Ange proxies # Ange proxies
session = requests.Session() session = requests.Session()
@ -123,7 +134,8 @@ class Profile:
} }
# Starta browser # Starta browser
user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1" # user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1"
user_agent = self.useragent
self.browser = RoboBrowser( self.browser = RoboBrowser(
session=session, user_agent=user_agent, history=False, parser="lxml" session=session, user_agent=user_agent, history=False, parser="lxml"
) )
@ -132,6 +144,11 @@ class Profile:
open("data/cookie_{}.pkl".format(self.name), "rb") open("data/cookie_{}.pkl".format(self.name), "rb")
) )
self.logged_in = True self.logged_in = True
except:
try:
self.browser.session.cookies.update(self.cookie)
print(self.browser.session.cookies.values)
self.logged_in = True
except: except:
self.logged_in = False self.logged_in = False
@ -139,12 +156,11 @@ class Profile:
""" Returnerar browser i html-format """ """ Returnerar browser i html-format """
return self.browser.parsed return self.browser.parsed
def accept_cookies(self): def accept_cookies(self):
""" Accepterar cookies """ """ Accepterar cookies """
self.browser.open("https://mbasic.facebook.com") self.browser.open("https://mbasic.facebook.com")
soup = BeautifulSoup(str(self.browser.parsed), "lxml") soup = BeautifulSoup(str(self.browser.parsed), "lxml")
if 'accept all' not in soup.text.lower(): if "accept all" not in soup.text.lower():
sleep_(2) sleep_(2)
cookie_accept_url = "https://mbasic.facebook.com/cookie/consent-page" cookie_accept_url = "https://mbasic.facebook.com/cookie/consent-page"
self.browser.open(cookie_accept_url) self.browser.open(cookie_accept_url)
@ -155,7 +171,8 @@ class Profile:
print(f"Accepterade cookies för {self.name}") print(f"Accepterade cookies för {self.name}")
sleep_(2) sleep_(2)
update_cookie(self.browser.session.cookies, self.name) update_cookie(self.browser.session.cookies, self.name)
except Exception as e: except:
write_error(12, soup=self.browser.parsed, profile=self.name)
print(f"Accepterade inte cookies för {self.name}") print(f"Accepterade inte cookies för {self.name}")
def login(self): def login(self):
@ -168,9 +185,9 @@ class Profile:
# Kolla om browser redan är inloggad # Kolla om browser redan är inloggad
soup = BeautifulSoup(str(self.browser.parsed), "lxml") soup = BeautifulSoup(str(self.browser.parsed), "lxml")
if 'log out' in soup.text.lower(): if "log out" in soup.text.lower():
print("Redan inloggad.") print("Redan inloggad.")
try:
# Hitta och fyll i formulär # Hitta och fyll i formulär
form = self.browser.get_form(id="login_form") form = self.browser.get_form(id="login_form")
form["email"].value = self.email form["email"].value = self.email
@ -179,32 +196,37 @@ class Profile:
# Vänta lite och uppdatera cookie # Vänta lite och uppdatera cookie
print("Loggade in.") print("Loggade in.")
sleep_(2) sleep_(2)
except TypeError:
write_error(11, soup=soup, profile=self.name)
def unused(self): def unused(self):
""" Sätter user till False för valda profiler """ """ Sätter user till False för valda profiler """
self.doc["in_use"] = False self.doc["in_use"] = False
db.update_document(self.doc, silent=True) db.update_document(self.doc, silent=True, check_rev=False)
class Proxies: class Proxies:
def __init__(self): def __init__(self):
self.proxies = [ self.proxies = [
'gb25-wg.socks5.mullvad.net:1080', "gb25-wg.socks5.mullvad.net:1080",
'gb26-wg.socks5.mullvad.net:1080', "gb26-wg.socks5.mullvad.net:1080",
'gb27-wg.socks5.mullvad.net:1080', "gb27-wg.socks5.mullvad.net:1080",
'gb28-wg.socks5.mullvad.net:1080', "gb28-wg.socks5.mullvad.net:1080",
'gb29-wg.socks5.mullvad.net:1080' "gb29-wg.socks5.mullvad.net:1080",
] ]
def get_proxie(self): def get_proxie(self):
return self.proxies.pop(random.randrange(0, len(self.proxies), 1)) return self.proxies.pop(random.randrange(0, len(self.proxies), 1))
class Friend: class Friend:
def __init__(self, user): def __init__(self, user):
self.collection = "members" self.collection = "members"
self.user = user # The friends friend self.user = user # The friends friend
self.username = '' self.username = ""
self.url = '' self.url = ""
self.name = '' self.name = ""
self.single = '' self.single = ""
def add_to_db(self): def add_to_db(self):
db.insert_document( db.insert_document(
@ -237,3 +259,4 @@ class Reaction:
"picture": self.picture_id, "picture": self.picture_id,
"reaction": self.type, "reaction": self.type,
} }

@ -10,7 +10,7 @@ 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, all_pictures, first_user=False, mode="all"
): ):
#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)
@ -22,20 +22,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)
sleep_(4) sleep_(4)
if ( if """You can't use Facebook because your account, or activity on it, doesn't follow our Community Standards.""" in profile.viewing():
"""You can't use Facebook because your account, or activity on it, doesn't follow our Community Standards.""" _print(profile, user, f"{profile.name} blocked\n".upper(), sleeptime=1)
in profile.viewing().text
):
_print(profile.container, user.username, f"{profile.name} blocked\n".upper())
profile.blocked = True profile.blocked = True
return "blocked" return profile
elif 'It looks like you were misusing this feature by going too fast.' in profile.viewing().text:
sleep_(600)
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':
profile.login()
sleep_(5)
profile.browser.open(user.url_photos)
user.name = user.username # Om inte namnet hittas senare user.name = user.username # Om inte namnet hittas senare
try: try:
@ -49,15 +50,15 @@ def profile_picture_reactions(
6, 6,
e=e, e=e,
traceback=traceback.format_exc(), traceback=traceback.format_exc(),
profile=profile.container, profile=profile,
soup=profile.viewing(), soup=profile.viewing(),
user=user, user=user,
url=user.url_photos, url=user.url_photos,
) )
if first_user == True: if first_user == True:
_print(profile.container, user.username, profile.viewing().prettify()) _print(profile, user, profile.viewing().prettify())
exit() exit()
_print(profile.container, user.username, f"Hämtar reaktioner på profilbilder för {user.name} ({user.username})") _print(profile, user, f"Hämtar reaktioner på profilbilder för {user.name} ({user.username})")
# Hitta länk till olika saker hos användarem, inkl facebook-id # Hitta länk till olika saker hos användarem, inkl facebook-id
@ -79,6 +80,8 @@ def profile_picture_reactions(
user.url_timeline = url_bas + a["href"] user.url_timeline = url_bas + a["href"]
if "Cover photos" in a.text: if "Cover photos" in a.text:
user.url_coverphotos = url_bas + a["href"] user.url_coverphotos = url_bas + a["href"]
if a.text == "Friends":
user.url_friends = url_bas + a["href"]
# Om det inte finns något profilalbum # Om det inte finns något profilalbum
# Testa ta bort mellanrum och små bokstäver # Testa ta bort mellanrum och små bokstäver
@ -90,78 +93,79 @@ def profile_picture_reactions(
user.add_to_db() user.add_to_db()
# Gå till profilbilden (den första som kommer upp när man går till profilen) # Gå till profilbilden (den första som kommer upp när man går till profilen)
if not hasattr(user, "url_album"): # Om profilen inte har profilalbum # Om profilen inte har profilalbum
write_error(9, soup=profile.viewing(), user=user, profile=profile.container) if not hasattr(user, "url_album"):
if user.url_other_picture != "": write_error(9, soup=profile.viewing(), user=user, profile=profile)
# Använd eventuell extrabild och ta bort den från användaren if user.url_other_pictures != []:
url_pics = [user.url_other_picture] # Använd eventuella extrabilder och ta bort den från användaren
user.url_other_picture = "" url_pics = user.url_other_pictures
user.url_other_pictures = []
else: else:
# Spara ner profilen till databasen och avsluta sökningen på användaren # Spara ner profilen till databasen och avsluta sökningen på användaren
user.url_album = False user.url_album = False
if first_user == False: if first_user == False:
user.checked() user.checked()
user.add_to_db() user.add_to_db()
_print(profile.container, user.username, "Hittar inget album för profilbilder.") _print(profile, user, "Hittar inget album för profilbilder.")
write_error(#fel7 write_error(#fel7
7, 7,
soup=profile.viewing(), soup=profile.viewing(),
profile=profile.container, profile=profile,
user=user, user=user,
url=user.url_album, url=user.url_album,
url_name="user.url_album", url_name="user.url_album",
) )
return None return profile
# ATT GÖRA Här kan andra bilder väljas istället # ATT GÖRA Här kan andra bilder väljas istället
else: # Normalfallet där användaren har profilbildsalbum # Normalfallet där användaren har profilbildsalbum
else:
profile.browser.open(user.url_album) profile.browser.open(user.url_album)
# Samla alla profilbilder i en lista # Samla alla profilbilder i en lista
url_pics = [] url_pics = user.url_other_pictures
pics = profile.viewing().find("div", {"id": "thumbnail_area"}) pics = profile.viewing().find("div", {"id": "thumbnail_area"})
for i in pics.find_all("a"): for i in pics.find_all("a"):
a = i["href"] a = i["href"]
url_pics.append(a[: a.find("&id")]) url_pics.append(a[: a.find("&id")])
if user.url_other_picture != "":
# Lägg till eventuell extrabild och ta bort den från användaren
url_pics.append(user.url_other_picture)
user.url_other_picture = ""
try: try:
user.profile_pictures = len(url_pics) user.profile_pictures = len(url_pics)
user.pictures = url_pics
except: except:
_print(profile, user, 'Hittade inga profilbilder'.upper())
user.profile_pictures = 0 user.profile_pictures = 0
user.pictures = url_pics
user.checked() user.checked()
user.add_to_db() user.add_to_db()
return return profile
# Lägg till profilen till arrango. # Lägg till profilen till arrango.
user.add_to_db() user.add_to_db()
# Välj vilja bilder som ska kollas.
if first_user == False:
if mode == "single":
url_pics = url_pics[:1]
elif mode == "few" and len(url_pics) > 1:
url_pics = url_pics[:1] + url_pics[-1:]
# Gå igenom valda bilder. # Gå igenom valda bilder.
for pic in url_pics: for pic in url_pics:
# Skriv ut vilken bild som behandlas. # Skriv ut vilken bild som behandlas.
_print(profile.container, user.username, _print(profile, user,
f"Bild {url_pics.index(pic) + 1} av {user.profile_pictures}", f"Bild {url_pics.index(pic) + 1} av {user.profile_pictures}",
end="\r", end="\r",
) )
check_picture(url_bas + pic, user, profile) check_picture(url_bas + pic, user, profile)
user.checked_pictures.append(url_bas + pic)
# Välj vilja bilder som ska kollas. # Välj vilja bilder som ska kollas.
if first_user == False: if first_user == False:
if mode == "single" and user.reactions > 30: if mode == "single" and user.reactions > 30:
break break
elif all([mode == "few", user.reactions > 50, pic != url_pics[-1]]): elif all([mode == "few", user.reactions > 80, pic != url_pics[-1]]):
# Kolla den sista bilder # Kolla den sista bilder
check_picture(url_bas + url_pics[-1], user, profile) check_picture(url_bas + url_pics[-1], user, profile)
user.checked_pictures.append(url_bas + pic)
break break
user.checked() user.checked()
return profile
# except Exception as e:
# _print(profile, None, str(e))
# return profile
def check_picture(url_picture, user, profile): def check_picture(url_picture, user, profile):
@ -184,7 +188,7 @@ def check_picture(url_picture, user, profile):
write_error( write_error(
3, 3,
e=e, e=e,
profile=profile.container, profile=profile,
soup=profile.viewing(), soup=profile.viewing(),
user=user, user=user,
url=picture.url, url=picture.url,
@ -202,7 +206,7 @@ def check_picture(url_picture, user, profile):
8, 8,
e=e, e=e,
soup=profile.viewing(), soup=profile.viewing(),
profile=profile.container, profile=profile,
url=picture.url, url=picture.url,
url_name="picture url", url_name="picture url",
user=user, user=user,
@ -211,7 +215,7 @@ def check_picture(url_picture, user, profile):
# TODO #3 lägg till fler bilder som kan gås igenom om det är få profilbilder. # TODO #3 lägg till fler bilder som kan gås igenom om det är få profilbilder.
# Hämta länkar för bilden att anvrända sen # Hämta länkar för bilden att anvrända sen
# _print(profile.container, user.username, profile.viewing().prettify()) # _print(profile, user, profile.viewing().prettify())
for a in profile.viewing().find_all("a", href=True): for a in profile.viewing().find_all("a", href=True):
if all( if all(
[ [
@ -256,14 +260,14 @@ def check_picture(url_picture, user, profile):
write_error( write_error(
9, 9,
user=user, user=user,
profile=profile.container, profile=profile,
soup=profile.viewing(), soup=profile.viewing(),
traceback=traceback.format_exc(), traceback=traceback.format_exc(),
url=url_reactions, url=url_reactions,
url_name="url_reactions", url_name="url_reactions",
) )
# Bilder med väldigt många likes går inte att visa så här? # Bilder med väldigt många likes går inte att visa så här?
return None return profile
# Addera bilden till arrango # Addera bilden till arrango
picture.add_to_db() picture.add_to_db()
@ -306,7 +310,7 @@ def check_picture(url_picture, user, profile):
e=e, e=e,
soup=str(li), soup=str(li),
user=user, user=user,
profile=profile.container, profile=profile,
traceback=traceback.format_exc(), traceback=traceback.format_exc(),
) )
pass pass
@ -326,7 +330,7 @@ def check_picture(url_picture, user, profile):
2, 2,
e=e, e=e,
soup=profile.viewing(), soup=profile.viewing(),
profile=profile.container, profile=profile,
user=user, user=user,
url=url_limit, url=url_limit,
url_name="url_limit", url_name="url_limit",

Loading…
Cancel
Save