diff --git a/Dockerfile b/Dockerfile index ff8af73..4bdb66a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM python:3.8 -WORKDIR /facebook +WORKDIR / COPY requirements.txt . @@ -9,7 +9,7 @@ RUN pip install -r requirements.txt ADD . . -ENTRYPOINT [ "python", "__main__.py" ] +ENTRYPOINT [ "python", "facebook/__main__.py" ] CMD ["",""] diff --git a/README.md b/README.md index 62b26d8..38d3055 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,13 @@ $ docker buildx create --use $ docker buildx build --platform linux/arm -t l3224/fb-scraper:pi --push . ### Run -§ docker run -it -v fb-scraper-data:/data l3224/fb-scraper:pi [-s -u user1,user2] +§ docker run -it --rm -v fb-scraper-data:/data l3224/fb-scraper:pi [-s -u user1,user2] + +### Detach container +CTRL-p CTRL-q (in terminal) + +### Attach container +docker container ls +docker attach + +https://docs.docker.com/engine/reference/commandline/container_ls/§ \ No newline at end of file diff --git a/facebook/__main__.py b/facebook/__main__.py index 732b2c9..8989d33 100644 --- a/facebook/__main__.py +++ b/facebook/__main__.py @@ -26,7 +26,7 @@ if __name__ == "__main__": # Argument och alternativ argv = argv[1:] try: - opts, args = getopt(argv, "su:o:", ["single", "users=", "other="]) + opts, args = getopt(argv, "m:u:o:", ["mode=", "users=", "other="]) for o, a in opts: if o in ["-u", "--user"]: users = [ @@ -35,10 +35,16 @@ if __name__ == "__main__": ] if o in ["-o", "--other"]: url_other_picture = a - if o in ["-s", "--single"]: - single = True + # mode_nr används för hur ofta profile ska roteras + if o in ["-m", "--mode"]: + mode = a + if mode == 'single': + mode_nr = 1,7 + elif mode == 'few': + mode_nr = 1,4 else: - single = False + mode_nr = 1 + if "users" not in globals(): users = [ @@ -52,11 +58,10 @@ if __name__ == "__main__": 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 - + mode = input("Söka efter alla, första/sida eller första? (all, few, single)? ").lower().strip() + if mode == '': + mode = 'all' + if "url_other_picture" in globals(): users[0].url_other_picture = url_other_picture[url_other_picture.find('facebook.com') + 12:] @@ -96,7 +101,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_user=True, single=single) + profile_picture_reactions(profile, user, all_pictures, first_user=True, mode=mode) except: print(traceback.format_exc()) if len(users) == 1: @@ -122,8 +127,9 @@ if __name__ == "__main__": sleep_(2) try: profile_picture_reactions( - profile, user, all_pictures, single=single + profile, user, all_pictures, mode=mode ) + if profile.blocked == True: # Ta bort profilen ur databasen arangodb.remove_profile(profile.doc["_key"]) @@ -145,12 +151,12 @@ if __name__ == "__main__": print("Klar med", user.username, "\n") # Rotera fb-profiler - if count_friends == 6: + if count_friends > 5 * mode_nr: 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: + elif count_friends > 9 * mode_nr: profile_nr += 1 count_friends = 0 print("Växlar till", profiles[profile_nr].name) diff --git a/facebook/classes.py b/facebook/classes.py index 01ac478..b04d1cb 100644 --- a/facebook/classes.py +++ b/facebook/classes.py @@ -28,7 +28,6 @@ class User: self.url = '' self.name = '' self.url_other_picture = '' - self.doc def add_to_db(self): # Lägg till profilen till arrango diff --git a/facebook/scrapers.py b/facebook/scrapers.py index 14d5830..4f26b02 100644 --- a/facebook/scrapers.py +++ b/facebook/scrapers.py @@ -7,7 +7,7 @@ from config import * from helpers import sleep_, update_cookie, write_error -def profile_picture_reactions(profile, user, all_pictures, first_user=False, single = False): +def profile_picture_reactions(profile, user, all_pictures, first_user=False, mode = 'all'): # Fixa url:er osv if user.username.isnumeric(): @@ -120,17 +120,19 @@ def profile_picture_reactions(profile, user, all_pictures, first_user=False, sin user.checked() user.add_to_db() return - # Lägg till profilen till arrango + # Lägg till profilen till arrango. user.add_to_db() - # Gå igenom alla profilbilder - if single == True and first_user == False: - url_pics = url_pics[:1] + # 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. 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",) picture = Picture(user.username) @@ -140,9 +142,8 @@ def profile_picture_reactions(profile, user, all_pictures, first_user=False, sin picture.id = str(re.search('\d+', picture.id).group()) except: pass - # if picture.id in all_pictures: - # print('Redan kollat bild', picture.id) - # continue + if picture.id in all_pictures: + continue sleep_(5) try: