Added run mode and some minor fixes

pull/5/head
Lasse Edfast 5 years ago
parent b63a5466ca
commit b6f79fa620
  1. 4
      Dockerfile
  2. 11
      README.md
  3. 32
      facebook/__main__.py
  4. 1
      facebook/classes.py
  5. 23
      facebook/scrapers.py

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

@ -8,4 +8,13 @@ $ docker buildx create --use
$ docker buildx build --platform linux/arm -t l3224/fb-scraper:pi --push . $ docker buildx build --platform linux/arm -t l3224/fb-scraper:pi --push .
### Run ### 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/§

@ -26,7 +26,7 @@ if __name__ == "__main__":
# Argument och alternativ # Argument och alternativ
argv = argv[1:] argv = argv[1:]
try: 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: for o, a in opts:
if o in ["-u", "--user"]: if o in ["-u", "--user"]:
users = [ users = [
@ -35,10 +35,16 @@ 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"]: # mode_nr används för hur ofta profile ska roteras
single = True if o in ["-m", "--mode"]:
mode = a
if mode == 'single':
mode_nr = 1,7
elif mode == 'few':
mode_nr = 1,4
else: else:
single = False mode_nr = 1
if "users" not in globals(): if "users" not in globals():
users = [ users = [
@ -52,11 +58,10 @@ if __name__ == "__main__":
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(",")
] ]
if input("Söka bara en bild (single)? ") in ["ja, yes, j, y"]: mode = input("Söka efter alla, första/sida eller första? (all, few, single)? ").lower().strip()
single = True if mode == '':
else: mode = 'all'
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:]
@ -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 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_user=True, single=single) profile_picture_reactions(profile, user, all_pictures, first_user=True, mode=mode)
except: except:
print(traceback.format_exc()) print(traceback.format_exc())
if len(users) == 1: if len(users) == 1:
@ -122,8 +127,9 @@ if __name__ == "__main__":
sleep_(2) sleep_(2)
try: try:
profile_picture_reactions( profile_picture_reactions(
profile, user, all_pictures, single=single profile, user, all_pictures, mode=mode
) )
if profile.blocked == True: if profile.blocked == True:
# Ta bort profilen ur databasen # Ta bort profilen ur databasen
arangodb.remove_profile(profile.doc["_key"]) arangodb.remove_profile(profile.doc["_key"])
@ -145,12 +151,12 @@ if __name__ == "__main__":
print("Klar med", user.username, "\n") print("Klar med", user.username, "\n")
# Rotera fb-profiler # Rotera fb-profiler
if count_friends == 6: 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
count_friends = 0 count_friends = 0
print("Växlar till", profiles[profile_nr].name) print("Växlar till", profiles[profile_nr].name)
elif count_friends == 10: elif count_friends > 9 * mode_nr:
profile_nr += 1 profile_nr += 1
count_friends = 0 count_friends = 0
print("Växlar till", profiles[profile_nr].name) print("Växlar till", profiles[profile_nr].name)

@ -28,7 +28,6 @@ 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

@ -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_user=False, single = False): def profile_picture_reactions(profile, user, all_pictures, first_user=False, mode = 'all'):
# Fixa url:er osv # Fixa url:er osv
if user.username.isnumeric(): if user.username.isnumeric():
@ -120,17 +120,19 @@ def profile_picture_reactions(profile, user, all_pictures, first_user=False, sin
user.checked() 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 # Välj vilja bilder som ska kollas.
if single == True and first_user == False: if first_user== False:
url_pics = url_pics[:1] 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: for pic in url_pics:
if pic in all_pictures: # Skriv ut vilken bild som behandlas.
return None
# 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)
@ -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()) picture.id = str(re.search('\d+', picture.id).group())
except: except:
pass pass
# if picture.id in all_pictures: if picture.id in all_pictures:
# print('Redan kollat bild', picture.id) continue
# continue
sleep_(5) sleep_(5)
try: try:

Loading…
Cancel
Save