Created
August 13, 2022 01:22
-
-
Save Normanras/284f9f133e6f7c629483911313f3b8fd to your computer and use it in GitHub Desktop.
Python Script to pull 5-letter words from txt files for a wordle clone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a good beginner script for those learning python and want to learn about opening, reading, writing, and closing | |
# files. I commented out print statements that were used for debugging. If you're learning, I recommend uncommenting those | |
# print statements to get a good understanding of what's happening in each function. | |
# | |
# I wrote this python script to pull out 5 letter words from a directory full of txt files with Italian words. There were no | |
# accents in the plain text wordlists except for some words with an apostraphe at the end, such as "cioe'" Row 29 and 30 were | |
# added to ignore those words. | |
# | |
# One big advantage I had was that these txt files had a new word on each line, making it really easy to extract the correct | |
# length words. You could easily reuse this with password text files used for bruteforce dictionaries. | |
# | |
# The script will look through all files in a directory with .txt as the extension, look through each line, ensure the word is | |
# five letters and doesn't contain an apostraphe, and then write those words to a new file, in a different directory. The | |
# final file is also .txt so placed in a results directory so the script doesn't read the new file too. | |
# | |
# Good luck and let me know if you have any quesitons! | |
import re | |
import os | |
from os import listdir | |
def findfiles(): | |
path = "script_dir/" | |
files = os.listdir(path) | |
for file in files: | |
match = re.search("\.txt$", file) | |
if match: | |
#print(file) | |
readfile(file) | |
def readfile(file): | |
file = open("script_dir/" + file, encoding='ISO-8859-1') | |
for words in file: | |
words = file.readline() | |
letters = words.strip() | |
#print(letters) | |
eachword(letters) | |
def eachword(letters): | |
#print(len(letters)) | |
length = len(letters) | |
regex = re.compile("'") | |
if (regex.search(letters) == None) and length == 5: | |
writeresults(letters) | |
#print(letters) | |
def writeresults(letters): | |
write = open("script_dir/results/final_words.txt", 'a') | |
write.write("'"+letters+"'"+","+"\n") | |
write.close | |
if __name__ == "__main__": | |
findfiles() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment