import argparse import os import itsdangerous def generate(secret_key, username, expiration): s = itsdangerous.TimedJSONWebSignatureSerializer(secret_key, expires_in=expiration) return s.dumps(username) def main(): parser = argparse.ArgumentParser() parser.add_argument('username', metavar='USERNAME', help='user name') parser.add_argument('expiration', metavar='EXPIRATION', type=int, help='expiration time in seconds') args = parser.parse_args() secret_key = os.getenv('SECRET_KEY') api_key = generate(secret_key, args.username, args.expiration) print(api_key.decode('utf-8')) if __name__ == '__main__': main()