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. 31
      facebook/scrapers.py

@ -1,17 +1,15 @@
FROM python:3.8 FROM python:3.8
WORKDIR / WORKDIR /facebook
COPY requirements.txt . COPY requirements.txt .
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
ADD data /data ADD . .
COPY main.py . ENTRYPOINT [ "python", "__main__.py" ]
ENTRYPOINT [ "python", "./main.py" ]
CMD ["",""] 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:] argv = argv[1:]
try: try:
opts, args = getopt(argv, "su:o:", ["single", "users=", "other="]) 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: for o, a in opts:
if o in ["-u", "--user"]: if o in ["-u", "--user"]:
users = [ users = [
@ -36,6 +35,10 @@ if __name__ == "__main__":
] ]
if o in ["-o", "--other"]: if o in ["-o", "--other"]:
url_other_picture = a url_other_picture = a
if o in ["-s", "--single"]:
single = True
else:
single = False
if "users" not in globals(): if "users" not in globals():
users = [ users = [
@ -48,11 +51,11 @@ if __name__ == "__main__":
User(str(i).strip()) User(str(i).strip())
for i in input("Vem/vilka vill du kolla bilder för? ").split(",") for i in input("Vem/vilka vill du kolla bilder för? ").split(",")
] ]
single = (
True if input("Söka bara en bild (single)? ") in ["ja, yes, j, y"]:
if input("Söka bara en bild (single)?").lower() in ["ja, yes, j, y"] single = True
else False else:
) single = False
if "url_other_picture" in globals(): if "url_other_picture" in globals():
users[0].url_other_picture = url_other_picture[url_other_picture.find('facebook.com') + 12:] 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 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: 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: except:
print(traceback.format_exc()) print(traceback.format_exc())
if len(users) == 1: if len(users) == 1:
@ -111,7 +114,7 @@ if __name__ == "__main__":
print(friend) print(friend)
print() 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 count_friends = 0
for friend in friends_unchecked: for friend in friends_unchecked:
count_friends += 1 count_friends += 1
@ -119,7 +122,7 @@ if __name__ == "__main__":
sleep_(2) sleep_(2)
try: try:
profile_picture_reactions( profile_picture_reactions(
profile, user, members_checked, all_pictures profile, user, all_pictures, single=single
) )
if profile.blocked == True: if profile.blocked == True:
# Ta bort profilen ur databasen # Ta bort profilen ur databasen

@ -28,6 +28,7 @@ class User:
self.url = '' self.url = ''
self.name = '' self.name = ''
self.url_other_picture = '' self.url_other_picture = ''
self.doc
def add_to_db(self): def add_to_db(self):
# Lägg till profilen till arrango # 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 variation = 4 # Testa olika sovlängder för att inte få användaren blockerad
sleep(t * variation * random.randrange(85, 115, 1) / 100) sleep(t * variation * random.randrange(85, 115, 1) / 100)
if random.randrange(0, 60, 1) == 1: if random.randrange(0, 60, 1) == 1:
for s in range(0, 300): longsleep = random.randrange(200, 300)
print(f"Sover {300 - s} sekunder till... ", end="\r") for s in range(0, longsleep):
print(f"Sover {longsleep - s} sekunder till... ", end="\r")
sleep(1) sleep(1)
print() print()
sleep(random.randrange(0, 10, 1) / 4) sleep(random.randrange(0, 10, 1) / 4)

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

Loading…
Cancel
Save