list tokens
This commit is contained in:
27
manager.py
27
manager.py
@@ -28,10 +28,26 @@ def insert_token(db, name, token):
|
||||
db.commit()
|
||||
|
||||
|
||||
def add_token(options):
|
||||
def manage_tokens(options):
|
||||
if not is_key(options.name, options):
|
||||
raise Exception("%s does not exist, or is not a valid question set name"%( options.name, ))
|
||||
db = open_db(options.db)
|
||||
if options.list:
|
||||
cur = db.cursor()
|
||||
cur.execute(
|
||||
"SELECT token, answered FROM tokens WHERE question_set = ?",
|
||||
(
|
||||
options.name,
|
||||
)
|
||||
)
|
||||
for row in cur:
|
||||
print("%s/vote/%s/%s (%s)"%(
|
||||
options.prefix,
|
||||
options.name,
|
||||
row[0],
|
||||
"used" if row[1] == "true" else "unused"
|
||||
))
|
||||
return
|
||||
for i in range(options.number):
|
||||
N = 32
|
||||
token = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(N))
|
||||
@@ -80,6 +96,13 @@ def parse_options(database, questions):
|
||||
default = "",
|
||||
help = "Prefix tokens with the server URL to automate emails etc.."
|
||||
)
|
||||
parser_token.add_argument(
|
||||
'--list', '-l',
|
||||
action="store_true",
|
||||
dest="list",
|
||||
default = False,
|
||||
help = "List existing tokens, instead of generating more"
|
||||
)
|
||||
parser_token.add_argument(
|
||||
dest = "name",
|
||||
help = "Name of the question set"
|
||||
@@ -249,7 +272,7 @@ def main(database, questions):
|
||||
if options.subparser_name == "list":
|
||||
list_question_sets(options)
|
||||
if options.subparser_name == "token":
|
||||
add_token(options)
|
||||
manage_tokens(options)
|
||||
if options.subparser_name == "summary":
|
||||
summary(options)
|
||||
if options.subparser_name == "clear_votes":
|
||||
|
||||
Reference in New Issue
Block a user