adjsuted pw gen

This commit is contained in:
Paul Wilde 2023-10-28 21:59:00 +01:00
parent b866811ab8
commit 0f8b325246
2 changed files with 33 additions and 3 deletions

View file

@ -0,0 +1,4 @@
{
"version": 1,
"reverseDeps": {}
}

View file

@ -1,11 +1,16 @@
import ../../globurrl
#import ../../globurrl
import httpclient import httpclient
import json import json
import strutils import strutils
import random import random
import parseopt
import os
var length = 4 var length = 4
var number = 10
var word_len = 5
proc getNumber(size: int = 4): string = proc getNumber(size: int = 4): string =
var num = "" var num = ""
@ -22,16 +27,37 @@ proc parsePw(body: string) =
p &= getNumber(length) p &= getNumber(length)
echo p echo p
proc getPW() = proc getPW() =
var c = newHttpClient() var c = newHttpClient()
try: try:
let resp = c.get("https://random-word-api.herokuapp.com/word?length=5") let resp = c.get("https://random-word-api.herokuapp.com/word?number=" & $number & "&length=" & $word_len)
if resp.status == $Http200: if resp.status == $Http200:
parsePw(resp.body) parsePw(resp.body)
except: except:
echo getCurrentExceptionMsg() echo getCurrentExceptionMsg()
proc parseArgs() =
var p = initOptParser(commandLineParams())
while true:
p.next()
case p.kind
of cmdEnd: break
of cmdShortOption, cmdLongOption:
if p.val == "":
#echo "Option: ", p.key
discard
else:
#echo "Option and value: ", p.key, ", ", p.val
case p.key
of "length":
word_len = parseInt(p.val)
of "number":
number = parseInt(p.val)
of cmdArgument:
#echo "Argument: ", p.key
discard
if isMainModule: if isMainModule:
parseArgs()
getPW() getPW()