You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

182 lines
6.6 KiB

import os
import random
import traceback
from datetime import datetime
from getopt import GetoptError, getopt
from sys import argv
from time import sleep
import arangodb
from arangodb import db
from classes import Profile, User
from helpers import sleep_, write_error
from scrapers import profile_picture_reactions
# import werkzeug
# werkzeug.cached_property = werkzeug.utils.cached_property
# from arango import ArangoClient
if __name__ == "__main__":
print()
# Säkerställ att arbetsmappen är samma som den där scriptet ligger
os.chdir(os.path.dirname(__file__))
# Argument och alternativ
argv = argv[1:]
try:
opts, args = getopt(argv, "su:o:", ["single", "users=", "other="])
for o, a in opts:
if o in ["-u", "--user"]:
users = [
User(str(i).strip())
for i in [(str(i).strip()) for i in a.split(",")]
]
if o in ["-o", "--other"]:
url_other_picture = a
if o in ["-s", "--single"]:
single = True
else:
single = False
if "users" not in globals():
users = [
User(str(i).strip())
for i in input("Vem/vilka vill du kolla bilder för? ").split(",")
]
except GetoptError:
users = [
User(str(i).strip())
for i in input("Vem/vilka vill du kolla bilder för? ").split(",")
]
if input("Söka bara en bild (single)? ") in ["ja, yes, j, y"]:
single = True
else:
single = False
if "url_other_picture" in globals():
users[0].url_other_picture = url_other_picture[url_other_picture.find('facebook.com') + 12:]
print("Kollar profilbilder för:")
for user in users:
print("-", user.username)
print()
# Skapa tre olika profiler att besöka Facebook med
profiles = []
for i in range(0, 3):
doc = arangodb.get_profile()
profile = Profile(doc)
profile.browser.open("https://api.ipify.org")
print(
f"Profil {profile.name} använder IP-adress {profile.viewing().text}."
)
if profile.logged_in == False:
profile.accept_cookies()
sleep_(2)
profile.login()
profiles.append(profile)
print()
sleep(3)
profile_nr = 1
profile = profiles[profile_nr]
print("Börjar med profilen", profile.name)
# Gå igenom de användare som efterfrågats
while True:
for user in users:
# Set för kollade bilder och kollade medlemmar
all_pictures = set([doc["_key"] for doc in db.collection("pictures").all()])
members_checked = arangodb.checked_members()
if user.username not in members_checked:# Hämta reaktioner för den första användaren LÄGG TILL NOT IN MEMBERS_CHECKED
try:
profile_picture_reactions(profile, user, all_pictures, first_user=True, single=single)
except:
print(traceback.format_exc())
if len(users) == 1:
for profile in profiles:
profile.unused()
friends = arangodb.friends_of_user(user.username)
friends_unchecked = list(set(friends) - set(members_checked))
# Här följer cookien med så att vi fortfarnade är inloggade
print("\nKlar med", user.username, "\n")
print("Vänner som reagerat:", len(friends))
print("Vänner att kolla:")
for friend in friends_unchecked:
print(friend)
print()
# Hämta reaktioner för users vänner (som reagerat)
count_friends = 0
for friend in friends_unchecked:
count_friends += 1
user = User(str(friend))
sleep_(2)
try:
profile_picture_reactions(
profile, user, all_pictures, single=single
)
if profile.blocked == True:
# Ta bort profilen ur databasen
arangodb.remove_profile(profile.doc["_key"])
# 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:
profiles[profile_nr] = Profile(new=True)
print("Laddat ny profil:", profiles[profile_nr].name)
sleep(3)
except e:
print("Det behövs nya profiler...")
for s in range(0, 1600 / len(profiles)):
print(f"Sover {600-s} sekunder till... ", end="\r")
profile_nr += 1
print(f"Försöker med {profiles[profile_nr].name}.")
else:
print("Klar med", user.username, "\n")
# Rotera fb-profiler
if count_friends == 6:
if random.randrange(0, 2, 1) == 1:
profile_nr += 1
count_friends = 0
print("Växlar till", profiles[profile_nr].name)
elif count_friends == 10:
profile_nr += 1
count_friends = 0
print("Växlar till", profiles[profile_nr].name)
if profile_nr > len(profiles) - 1:
profile_nr = 0
profile = profiles[profile_nr]
except Exception as e: # Fel4
write_error(
4,
e=e,
user=user.username,
traceback=traceback.format_exc(),
soup=profile.viewing(),
)
print("\nFel: ", str(user.username), "\n")
sleep_(15)
pass
# Ladda in nya användare att kolla
print("\nVem vill du kolla upp?")
user_input = input(">>> ")
if user_input in ['exit', '', 'ingen']:
for profile in profiles:
profile.unused()
break
else:
users = [User(str(i).strip()) for i in user_input.split(",")]