authenticator/authenticator.py
2025-07-06 23:36:05 +07:00

40 lines
985 B
Python

import pyotp
import time
import os
def clear_screen():
os.system("cls" if os.name == "nt" else "clear")
def show_otp(issuer, account, secret):
totp = pyotp.TOTP(secret)
try:
while True:
clear_screen()
current_otp = totp.now()
time_remaining = totp.interval - (int(time.time()) % totp.interval)
print("TOTP Authenticator\n")
print(f"{issuer}\n{account}\n")
print(current_otp)
print(f"\nRemaining: {time_remaining:2} sec")
for i in range(time_remaining, 0, -1):
print(f"\rRefresh in: {i:2} sec", end="")
time.sleep(1)
if i == 1:
break
except KeyboardInterrupt:
pass
print("\nEND")
def app():
issuer = None
account = None
secret = None
try:
show_otp(issuer, account, secret)
except KeyboardInterrupt:
pass
if __name__ == "__main__":
app()