diff --git a/helpers.py b/helpers.py index 626b167..810c9f7 100644 --- a/helpers.py +++ b/helpers.py @@ -26,7 +26,7 @@ def get_access_token(email, password): def get_login_credentials(): print("Checking for credentials..") if os.path.exists('auth.json'): - print("Auth.json existed..") + print("Auth.json exists..") with open('auth.json') as data_file: data = json.load(data_file) if "email" in data and "password" in data and "FBID" in data: @@ -35,4 +35,4 @@ def get_login_credentials(): print("Invalid auth.json file.") print("Auth.json missing or invalid. Please enter your credentials.") - return (input("Enter email..\n"), input("Enter password..\n")) + return (input("Enter email..\n"), input("Enter password..\n"), input("Enter FBID...\n")) diff --git a/io_helpers.py b/io_helpers.py index fc4d49a..fa41cdb 100644 --- a/io_helpers.py +++ b/io_helpers.py @@ -1,19 +1,31 @@ +import errno +import os from skimage.io import imsave -base_folder = "data" +base_folder = os.path.dirname(os.path.abspath(__file__)) + "/data" -def save_image(image, name, liked): - - filename = base_folder +LIKE_FOLDER = base_folder + "/likes/" +DISLIKE_FOLDER = base_folder + "/dislikes/" - if liked: - filename += "/likes/" - else: - filename += "/dislikes/" +def save_image(image, name, liked): + filename = LIKE_FOLDER if liked else DISLIKE_FOLDER file_url_list = name.split("/") filename += file_url_list[-1] print(filename) imsave(filename, image) + +def init(): + mkdir_p(LIKE_FOLDER) + mkdir_p(DISLIKE_FOLDER) + +def mkdir_p(path): + try: + os.makedirs(path) + except OSError as exc: # Python >2.5 + if exc.errno == errno.EEXIST and os.path.isdir(path): + pass + else: + raise diff --git a/main.py b/main.py old mode 100644 new mode 100755 index 541b08b..c6b199e --- a/main.py +++ b/main.py @@ -1,8 +1,10 @@ +#! /usr/bin/env python + from skimage.io import imread, imsave, imshow, show +from matplotlib.pyplot import subplots import pynder -import matplotlib.pyplot as plt from helpers import get_access_token, get_login_credentials -from io_helpers import save_image +from io_helpers import save_image, init as init_io email, password, FBID = get_login_credentials() FBTOKEN = get_access_token(email, password) @@ -11,18 +13,20 @@ while True: users = session.nearby_users() + init_io() for user in users: photos = user.get_photos() print("Fetched user photos..") for photo in photos: image = imread(photo) + fig, ax = subplots(figsize=(10, 10)) imshow(image) show() - input_string = "Write 1 to like. Write 2 to dislike" + input_string = "Write 1 to like. Write 2 to dislike. Any other character if you don't know." ans = input(input_string).lower() if ans == "1": save_image(image, photo, True) - else: + elif ans == '2': save_image(image, photo, False) diff --git a/pynder b/pynder deleted file mode 160000 index 058c3e5..0000000 --- a/pynder +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 058c3e59d5d6a98a6fa6108cecfcb8dfc958fde9 diff --git a/requirements.txt b/requirements.txt index 40da8b9..5b295e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ networkx==1.11 numpy==1.13.0 olefile==0.44 Pillow==4.1.1 -pynder==0.0.13 +git+https://github.com/charliewolf/pynder.git@6b6827b pyparsing==2.2.0 python-dateutil==2.6.0 pytz==2017.2