diff options
Diffstat (limited to 'cupinder.py')
-rw-r--r-- | cupinder.py | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/cupinder.py b/cupinder.py new file mode 100644 index 0000000..e26c4f7 --- /dev/null +++ b/cupinder.py @@ -0,0 +1,159 @@ + +import argparse +from time import sleep + +import config +from db import HumanKind +from facebook import FacebookAPI +from nl import LanguageIdentifier +from tinder import TinderAPI + + +def connect(): + """Establish a connection to Facebook/Tinder.""" + + fb = FacebookAPI(config.facebook_email, config.facebook_password) + + fb_id = fb.get_user_id() + + print('[i] Facebook ID: ' + fb_id) + + fb_token = fb.get_tinder_token() + + print('[i] Tinder token: ' + fb_token) + + tinder = TinderAPI(fb_id, fb_token) + + print('[i] Tinder auth token: ' + tinder.get_auth_token()) + + print('[i] Remaining likes: %d' % tinder.get_remaining_likes()) + + return tinder + + +if __name__=='__main__': + + parser = argparse.ArgumentParser() + parser.add_argument('-g', '--grab', help='Grab profiles from Tinder', action='store_true') + parser.add_argument('-p', '--process', help='Process stored Tinder profiles', action='store_true') + parser.add_argument('--dump-new', help='Extract newly stored Tinder profiles', action='store_true') + parser.add_argument('--dump-all', help='Extract all stored Tinder profiles', action='store_true') + + args = parser.parse_args() + + + db = HumanKind() + + + if args.grab: + + tinder = connect() + + extra = 0 + + while True: + + profiles = tinder.get_recommendations(1) + + for p in profiles: + + if not(db.has_profile_id(p)): + + extra += 1 + + print(p) + db.store_profile(p) + + if extra == 0: + print('[!] No new profiles to grab! Exiting...') + break + + print('[i] Loaded ' + config.COLOR_LIKE + '%d' % extra + config.COLOR_RESET \ + + ' new profile%s... Taking some rest now!' % ('s' if extra > 2 else '')) + + sleep(5 * 60) + + + elif args.process: + + tinder = connect() + + lid = LanguageIdentifier() + + profiles = db.load_new_profiles() + + remaining = tinder.get_remaining_likes() + + for p in profiles: + + like = True + + age = p.compute_age() + + if not(age is None): + if age < config.MIN_AGE or age > config.MAX_AGE: + like = False + + if p._distance_mi > config.MAX_DISTANCE_IN_MI: + like = False + + if like and not(p._bio is None): + + language = lid.detect_language(p._bio) + + like = (language == config.TARGET_LANGUAGE) + + if like and not(p._bio is None): + + text = p._bio.lower() + + for kwd in config.BLACK_LIST_KEYWORDS: + if kwd in text: + like = False + break + + if like: + + if remaining == 0: + print('[!] No more likes available. Exiting...') + break + + remaining -= 1 + + print('[*] %s: ' % p._name + config.COLOR_LIKE + 'like!' + config.COLOR_RESET) + + tinder.like(p._id) + db.mark_profile_as_liked(p) + + else: + + print('[*] %s: ' % p._name + config.COLOR_PASS + 'pass' + config.COLOR_RESET) + + tinder.dislike(p._id) + db.mark_profile_as_passed(p) + + sleep(5) + + + elif args.dump_new: + + profiles = db.load_new_profiles() + + for p in profiles: + + print('[i] Extracting information about %s (id=%s)...' % (p._name, p._id)) + + p.output() + db.mark_profile_as_extracted(p) + + + elif args.dump_all: + + profiles = db.load_all_profiles() + + for p in profiles: + + print('[i] Extracting information about %s (id=%s)...' % (p._name, p._id)) + + p.output() + db.mark_profile_as_extracted(p) |