mirror of
https://gitea.blesmrt.net/mikaela/scripts.git
synced 2025-08-21 05:47:20 +02:00
Compare commits
No commits in common. "bbaf5778effde8197c0ff3336564fcf24b2e9b5a" and "87c57cd34ac1040fc1d2993720b73a0e505534e2" have entirely different histories.
bbaf5778ef
...
87c57cd34a
@ -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
|
||||||
|
|
||||||
|
try:
|
||||||
|
wantedCount = int(sys.argv[1])
|
||||||
|
except IndexError as noarg:
|
||||||
|
print("Enter a digit as an argument!")
|
||||||
|
|
||||||
def main():
|
try:
|
||||||
"""
|
for i in range(int(wantedCount)):
|
||||||
This is where the magic happens.
|
print(secrets.randbelow(10), end="")
|
||||||
"""
|
except NameError as noWantedCount:
|
||||||
try:
|
|
||||||
desired_length = int(sys.argv[1])
|
|
||||||
except IndexError:
|
|
||||||
print("Enter a digit as an argument!")
|
|
||||||
|
|
||||||
try:
|
|
||||||
for i in range(int(desired_length)):
|
|
||||||
print(secrets.randbelow(10), end="")
|
|
||||||
# We satisfy pylint by having the variable here.
|
|
||||||
# TODO:make this a while loop?
|
|
||||||
i += 1
|
|
||||||
except NameError:
|
|
||||||
print()
|
|
||||||
print()
|
print()
|
||||||
|
print()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
@ -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)
|
Loading…
x
Reference in New Issue
Block a user