-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordGen.py
46 lines (37 loc) · 1.08 KB
/
WordGen.py
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
import random
import os
import logging
# Generates random 3-word phrases, "-" delimited
def createKey(__location__):
"""
Creates guest key to set on WLANS
### Returns
Randomly generated key
### Depends on
None
### Parameters
- __location__: str
- Static location of main.py used for reliable file opening
"""
# Open file 'wordList.txt'
file = open(os.path.join(__location__,'wordList.txt'), 'r')
# Read file line by line
wordList = file.readlines()
# Initialize list of words
words = []
# Add each word from wordlist into the 'words' list
for line in wordList:
words.append("{}".format(line.strip()))
# Close the file
file.close()
# Number of words to be placed in phrase
phraseSize = 2
# Initialize list to place the phrase in
phrase = []
for i in range(phraseSize):
phrase.append(words[random.randrange(1,len(words))])
# Create key and store in variable
key = '-'.join(str(x) for x in phrase)
logging.info("Key generated")
logging.debug(key)
return(key)