-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev_tokens.py
More file actions
executable file
·80 lines (58 loc) · 1.76 KB
/
Copy pathdev_tokens.py
File metadata and controls
executable file
·80 lines (58 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from db_main import app
from shared.data import add_model, delete_model
from website.data.dev import DevToken
import sys
def create_token(name: str, valid_opt: str):
token = DevToken.query.filter_by(name=name).first()
if token:
print(f"Token with name '{name}' already exists.")
return
choices = {
"1": 5, "2": 15, "3": 30, "4": 60,
"5": 90, "6": 180, "7": 365
}
days = choices.get(valid_opt, 30)
token = DevToken(name, days)
add_model(token)
print(f"Token '{name}' created successfully.")
print(f"Token: {token.token}")
def delete_token(name: str):
token = DevToken.query.filter_by(name=name).first()
if not token:
print(f"Token with name '{name}' not found.")
return
delete_model(token)
print(f"Token '{name}' deleted successfully.")
def get_all_tokens():
tokens = DevToken.query.all()
if not tokens:
print("No tokens found.")
return
for token in tokens:
print(f"Name: {token.name}, Created: {token.timestamp.strftime('%d.%m.%Y %H:%M')}, "
f"Valid for: {token.days_valid} days")
def _exec(args):
match args[0]:
case "create_token":
if len(args) < 3:
print("Invalid args")
return
create_token(args[1], args[2])
case "delete_token":
if len(args) < 2:
print("Invalid args")
return
delete_token(args[1])
case "list_tokens":
get_all_tokens()
case _:
print("Invalid command")
def main():
args = sys.argv[1:]
if len(args) < 1:
print("Invalid args")
return
with app.app_context():
_exec(args)
if __name__ == "__main__":
main()