# HG changeset patch # User Peter Sanchez # Date 1467579524 25200 # Sun Jul 03 13:58:44 2016 -0700 # Node ID c026562018ebb6bab88ac14e4ae17dc1e5020893 # Parent e74f6d1c8bd2c5cb19bd737f450e02dde9720b3e Adding get_token helper script diff --git a/get_token.py b/get_token.py new file mode 100644 --- /dev/null +++ b/get_token.py @@ -0,0 +1,82 @@ +''' Simple CLI tool to grab the FB access token needed + to get authorize with Tinder and receive an API + token. +''' +from __future__ import unicode_literals + +import getpass +import argparse +from tinder.utils import get_tinder_access_token + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + '-e', '--email', + dest='email_address', + default=None, + help='Facebook Email Address.', + ) + parser.add_argument( + '-p', '--password', + dest='password', + default=None, + help='Facebook Password.', + ) + parser.add_argument( + '-c', '--cookie-file', + dest='cookie_file', + default=None, + help='Cookie File.', + ) + parser.add_argument( + '-a', '--ask', + dest='should_ask', + action='store_true', + default=False, + help='Signtal to prompt for credentials if not given on CLI.', + ) + parser.add_argument( + '-d', '--die', + dest='should_die', + action='store_true', + default=False, + help=('If we run into an error, should we die ' + 'hard and print traceback? Useful for debugging'), + ) + args = vars(parser.parse_args()) + + email = args.get('email_address') + password = args.get('password') + cookie_file = args.get('cookie_file') + should_ask = args.get('should_ask') + should_die = args.get('should_die') + + if should_ask: + if email is None: + email = raw_input('Facebook Email Address? ') + + if password is None: + password = getpass.getpass('Facebook Password? ') + + if cookie_file is None: + cookie_file = '~/.fb_cookie_file' + + try: + token = get_tinder_access_token( + username=email, + password=password, + cookie_file=cookie_file, + ) + except ValueError as e: + if should_die: + raise + else: + print('Unable to get token: {0}'.format(e)) + return + + print(token) + + +if __name__ == '__main__': + main()