Compare commits

..

No commits in common. "bbaf5778effde8197c0ff3336564fcf24b2e9b5a" and "87c57cd34ac1040fc1d2993720b73a0e505534e2" have entirely different histories.

2 changed files with 20 additions and 40 deletions

View File

@ -1,31 +1,15 @@
#!/usr/bin/env python #!/usr/bin/env python
"""
Takes desired PIN length as an argument and generates a PIN code of that
length.
"""
import secrets import secrets
import sys import sys
def main():
"""
This is where the magic happens.
"""
try: try:
desired_length = int(sys.argv[1]) wantedCount = int(sys.argv[1])
except IndexError: except IndexError as noarg:
print("Enter a digit as an argument!") print("Enter a digit as an argument!")
try: try:
for i in range(int(desired_length)): for i in range(int(wantedCount)):
print(secrets.randbelow(10), end="") print(secrets.randbelow(10), end="")
# We satisfy pylint by having the variable here. except NameError as noWantedCount:
# TODO:make this a while loop?
i += 1
except NameError:
print() print()
print() print()
if __name__ == "__main__":
main()

View File

@ -4,7 +4,7 @@ This script asks for a SSID name, counts it and tells whether it's of valid
length length
""" """
# Request input or assume "test" on empty. # Request input or assume "test" on empty.
GIVENSSID = str( givenssid = str(
input( input(
"Please enter the SSID you are thinking of (preferably 26 chars to fit _nomap): ", "Please enter the SSID you are thinking of (preferably 26 chars to fit _nomap): ",
) )
@ -13,32 +13,28 @@ GIVENSSID = str(
# Ensure it's UTF-8 and store the size. E.g. åäö are longer than oao # Ensure it's UTF-8 and store the size. E.g. åäö are longer than oao
# TODO: make this a function too # TODO: make this a function too
GIVENSSIDLEN = len(GIVENSSID.encode("utf8")) givenssidlen = len(givenssid.encode("utf8"))
# Checking the SSID length is done twice, so thus a function # Checking the SSID length is done twice, so thus a function
def checkssidlen(GIVENSSIDLEN): def checkssidlen(givenssidlen):
"""
This function checks that the given string is below 32 characters long and
can thus be used as an SSID.
"""
# 32 bytes should be the maximum SSID length # 32 bytes should be the maximum SSID length
if GIVENSSIDLEN <= 32: if givenssidlen <= 32:
print(GIVENSSID, "is", GIVENSSIDLEN, "long and thus valid length") print(givenssid, "is", givenssidlen, "long and thus valid length")
else: else:
print( print(
GIVENSSID, givenssid,
"is", "is",
GIVENSSIDLEN, givenssidlen,
"to long, please select a different SSID", "to long, please select a different SSID",
) )
# Checking the SSID without _nomap # Checking the SSID without _nomap
checkssidlen(GIVENSSIDLEN) checkssidlen(givenssidlen)
# TODO: make this a function too # TODO: make this a function too
GIVENSSIDLEN = len(GIVENSSID.encode("utf8")) givenssidlen = len(givenssid.encode("utf8"))
# Continuing with _nomap to ensure it also fits # Continuing with _nomap to ensure it also fits
GIVENSSID = GIVENSSID + "_nomap" givenssid = givenssid + "_nomap"
checkssidlen(GIVENSSIDLEN) checkssidlen(givenssidlen)