Created
February 21, 2020 09:18
-
-
Save cathay4t/bb646c0860f93e49ba0ffef8f0aaacde to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys | |
import toml | |
import pyotp | |
from pathlib import Path | |
CONF_PATH = f"{Path.home()}/.config/token.conf" | |
KEY = "key" | |
DEFAULT = "default" | |
def get_key(cfg, name): | |
return cfg.get(name, {}).get(KEY) | |
def get_token(key): | |
return "{:06}".format(int(pyotp.TOTP(key).now())) | |
def main(): | |
cfg = toml.load(CONF_PATH) | |
name = sys.argv[1] if len(sys.argv) > 1 else DEFAULT | |
key = get_key(cfg, name) | |
if not key: | |
print(f"No key found in config {CONF_PATH}") | |
exit(1) | |
print(get_token(key)) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment