COSCUP-ap-demo/misc.py

39 lines
728 B
Python
Raw Permalink Normal View History

2023-07-11 18:12:00 +02:00
#!/usr/bin/env python3
"""Something misc."""
import sys
import click
2023-07-11 18:12:00 +02:00
from Crypto.PublicKey import RSA
from demo import config
2023-07-27 19:22:08 +02:00
from demo.boxes import send_note
@click.group()
def misc():
pass
2023-07-11 18:12:00 +02:00
@click.command()
2023-07-27 19:22:08 +02:00
def gen_key(self):
2023-07-11 18:12:00 +02:00
"""Generate key."""
if config.KEY_PATH.exists():
print("Key is existing!")
sys.exit(2)
else:
k = RSA.generate(2048)
privkey_pem = k.exportKey("PEM").decode("utf-8")
config.KEY_PATH.write_text(privkey_pem)
print("Done!")
2023-07-27 19:22:08 +02:00
@click.command()
@click.option("--content", prompt="Note content")
def creat_note(content):
send_note(content)
misc.add_command(gen_key)
misc.add_command(creat_note)
2023-07-11 18:12:00 +02:00
if __name__ == "__main__":
2023-07-27 19:22:08 +02:00
misc()