Fixed "single" and other things

pull/5/head
Lasse Edfast 5 years ago
parent eeac187e15
commit ab362d5caf
  1. 8
      Dockerfile
  2. 9
      facebook/.dockerignore
  3. 21
      facebook/__main__.py
  4. BIN
      facebook/__pycache__/classes.cpython-37.pyc
  5. BIN
      facebook/__pycache__/scrapers.cpython-37.pyc
  6. 1
      facebook/classes.py
  7. 5
      facebook/helpers.py
  8. 35
      facebook/scrapers.py

@ -1,17 +1,15 @@
FROM python:3.8
WORKDIR /
WORKDIR /facebook
COPY requirements.txt .
RUN pip install -r requirements.txt
ADD data /data
ADD . .
COPY main.py .
ENTRYPOINT [ "python", "./main.py" ]
ENTRYPOINT [ "python", "__main__.py" ]
CMD ["",""]

@ -0,0 +1,9 @@
/.DS_Store
/.venv
/.vscode
/__pycache__
*.json
*.pkl
/facebook/test.py
/data/*
*.html

@ -27,7 +27,6 @@ if __name__ == "__main__":
argv = argv[1:]
try:
opts, args = getopt(argv, "su:o:", ["single", "users=", "other="])
single = True if "-s" in [o[0] for o in opts] else False
for o, a in opts:
if o in ["-u", "--user"]:
users = [
@ -36,6 +35,10 @@ if __name__ == "__main__":
]
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 = [
@ -48,11 +51,11 @@ if __name__ == "__main__":
User(str(i).strip())
for i in input("Vem/vilka vill du kolla bilder för? ").split(",")
]
single = (
True
if input("Söka bara en bild (single)?").lower() in ["ja, yes, j, y"]
else False
)
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:]
@ -93,7 +96,7 @@ if __name__ == "__main__":
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=True, single=single)
profile_picture_reactions(profile, user, all_pictures, first_user=True, single=single)
except:
print(traceback.format_exc())
if len(users) == 1:
@ -111,7 +114,7 @@ if __name__ == "__main__":
print(friend)
print()
# Hämta reaktioner för den första användarens vänner (som reagerat)
# Hämta reaktioner för users vänner (som reagerat)
count_friends = 0
for friend in friends_unchecked:
count_friends += 1
@ -119,7 +122,7 @@ if __name__ == "__main__":
sleep_(2)
try:
profile_picture_reactions(
profile, user, members_checked, all_pictures
profile, user, all_pictures, single=single
)
if profile.blocked == True:
# Ta bort profilen ur databasen

@ -28,6 +28,7 @@ class User:
self.url = ''
self.name = ''
self.url_other_picture = ''
self.doc
def add_to_db(self):
# Lägg till profilen till arrango

@ -13,8 +13,9 @@ def sleep_(t):
variation = 4 # Testa olika sovlängder för att inte få användaren blockerad
sleep(t * variation * random.randrange(85, 115, 1) / 100)
if random.randrange(0, 60, 1) == 1:
for s in range(0, 300):
print(f"Sover {300 - s} sekunder till... ", end="\r")
longsleep = random.randrange(200, 300)
for s in range(0, longsleep):
print(f"Sover {longsleep - s} sekunder till... ", end="\r")
sleep(1)
print()
sleep(random.randrange(0, 10, 1) / 4)

@ -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"]
user.id = re.search("\d+", l[l.find("id=") + 3 :]).group(0)
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 :])
picture.id = str(re.search('\d+', picture.id).group())
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)

Loading…
Cancel
Save