Skip to content

Instantly share code, notes, and snippets.

@AaryanGamer
Created May 15, 2020 14:13
Show Gist options
  • Save AaryanGamer/093385d3df463282117edf2021b7cbc2 to your computer and use it in GitHub Desktop.
Save AaryanGamer/093385d3df463282117edf2021b7cbc2 to your computer and use it in GitHub Desktop.
# Fayditor
from spellchecker import SpellChecker
import pyperclip, socket, random, re
pokemonList = ['Abra', 'Absol', 'Aerodactyl', 'Aggron', 'Aipom', 'Alakazam', 'Altaria', 'Amaldo', 'Ampharos', 'Anorith', 'Arbok', 'Arcanine', 'Ariados', 'Aron', 'Articuno', 'Azumarill', 'Azurill', 'Bagon', 'Baltoy', 'Banette', 'Barboach', 'Bayleef', 'Beautifly', 'Beedrill', 'Beldum', 'Bellossom', 'Bellsprout', 'Blastoise', 'Blaziken', 'Blissey', 'Breloom', 'Bulbasaur', 'Butterfree', 'Cacnea', 'Cacturne', 'Camerupt', 'Carvanha', 'Cascoon', 'Castform', 'Caterpie', 'Celebi', 'Chansey', 'Charizard', 'Charmander', 'Charmeleon', 'Chikorita', 'Chimecho', 'Chinchou', 'Clamperl', 'Claydol', 'Clefable', 'Clefairy', 'Cleffa', 'Cloyster', 'Combusken', 'Corphish', 'Corsola', 'Cradily', 'Crawdaunt', 'Crobat', 'Croconaw', 'Cubone', 'Cyndaquil', 'Delcatty', 'Delibird', 'Deoxys', 'Dewgong', 'Diglett', 'Ditto', 'Dodrio', 'Doduo', 'Donaphan', 'Dragonair', 'Dragonite', 'Dratini', 'Drowzee', 'Dugtrio', 'Dunsparce', 'Dusclops', 'Duskull', 'Dustox', 'Eevee', 'Ekans', 'Electabuzz', 'Electrike', 'Electrode', 'Elekid', 'Entei', 'Espeon', 'Exeggcute', 'Exeggutor', 'Exploud', "Farfetch'd", 'Fearow', 'Feebas', 'Feraligatr', 'Flaaffy', 'Flareon', 'Flygon', 'Foretress', 'Furret', 'Gardevoir', 'Gastly', 'Gengar', 'Geodude', 'Girafarig', 'Glalie', 'Gligar', 'Gloom', 'Golbat', 'Goldeen', 'Golduck', 'Golem', 'Gorebyss', 'Granbull', 'Graveler', 'Grimer', 'Groundon', 'Grovyle', 'Growlithe', 'Grumpig', 'Gulpin', 'Gyarados', 'Hariyama', 'Haunter', 'Heracross', 'Hitmonchan', 'Hitmonlee', 'Hitmontop', 'Ho-Oh', 'HootHoot', 'Hoppip', 'Horsea', 'Houndoom', 'Houndour', 'Huntail', 'Hypno', 'Igglybuff', 'Illumise', 'Ivysaur', 'Jigglypuff', 'Jirachi', 'Jolteon', 'Jumpluff', 'Jynx', 'Kabuto', 'Kabutops', 'Kadabra', 'Kakuna', 'Kangaskhan', 'Kecleon', 'Kingdra', 'Kingler', 'Kirlia', 'Koffing', 'Krabby', 'Kyogre', 'Lairon', 'Lanturn', 'Lapras', 'Larvitar', 'Latias', 'Latios', 'Ledian', 'Ledyba', 'Lickitung', 'Lileep', 'Linoone', 'Lombre', 'Lotad', 'Loudred', 'Ludicolo', 'Lugia', 'Lunatone', 'Luvdisc', 'Machamp', 'Machoke', 'Machop', 'Magby', 'Magcargo', 'Magikarp', 'Magmar', 'Magnemite', 'Magneton', 'Makuhita', 'Manectric', 'Mankey', 'Mantine', 'Mareep', 'Marill', 'Marowak', 'Marshtomp', 'Masquerain', 'Mawile', 'Medicham', 'Meditite', 'Meganium', 'Meowth', 'Metagross', 'Metang', 'Metapod', 'Mew', 'Mewtwo', 'Mightyena', 'Milotic', 'Miltank', 'Minun', 'Misdreavus', 'Moltres', 'Mr.Mime', 'Mudkip', 'Muk', 'Murkrow', 'Natu', 'Nidoking', 'Nidoqueen', 'Nidorina', 'Nidorino', 'Nincada', 'Ninetales', 'Ninjask', 'Noctowl', 'Nosepass', 'Numel', 'Nuzleaf', 'Octillery', 'Oddish', 'Omanyte', 'Omastar', 'Onix', 'Paras', 'Parasect', 'Pelipper', 'Persian', 'Phanpy', 'Pichu', 'Pidgeot', 'Pidgeotto', 'Pidgey', 'Pikachu', 'Piloswine', 'Pineco', 'Pinsir', 'Plusle', 'Politoed', 'Poliwag', 'Poliwhirl', 'Poliwrath', 'Ponyta', 'Poochyena', 'Porygon', 'Porygon', 'Primeape', 'Psyduck', 'Pupitar', 'Quagsire', 'Quilava', 'Quilfish', 'Raichu', 'Raikou', 'Ralts', 'Rapidash', 'Raticate', 'Rattata', 'Rayquaza', 'Regice', 'Regirock', 'Registeel', 'Relicanth', 'Remoraid', 'Rhydon', 'Rhyhorn', 'Roselia', 'Salamence', 'Sandshrew', 'Sandslash', 'Sapleye', 'Sceptile', 'Schuckle', 'Scizor', 'Scyther', 'Seadra', 'Seaking', 'Sealeo', 'Seedot', 'Seel', 'Sellow', 'Sentret', 'Seviper', 'Sharpedo', 'Shedinja', 'Shelgon', 'Shellder', 'Shiftry', 'Shroomish', 'Shuppet', 'Silcoon', 'Skarmony', 'Skiploom', 'Skitty', 'Slaking', 'Slakoth', 'Slowbro', 'Slowking', 'Slowpoke', 'Slugma', 'Smeargle', 'Smoochum', 'Sneazle', 'Snorlax', 'Snorunt', 'Snubbull', 'Solrock', 'Spearow', 'Spheal', 'Spinarak', 'Spinda', 'Spoink', 'Squirtle', 'Stantler', 'Starmie', 'Staryu', 'Steelix', 'Sudowoodo', 'Suicune', 'Sunflora', 'Sunkern', 'Surskit', 'Swablu', 'Swalot', 'Swampert', 'Swinub', 'Taillow', 'Tangela', 'Tauros', 'Teddiursa', 'Tentacool', 'Tentacruel', 'Togepi', 'Togetic', 'Torchic', 'Torkoal', 'Totodile', 'Trapinch', 'Treecko', 'Tropius', 'Typhlosion', 'Tyranitar', 'Tyrogue', 'Umbreon', 'Unown', 'Ursaring', 'Vaporeon', 'Venomoth', 'Venonat', 'Venusaur', 'Vibrava', 'Victreebel', 'Vigoroth', 'Vileplume', 'Volbeat', 'Voltorb', 'Vulpix', 'Wailmer', 'Wailord', 'Walrein', 'Wartortle', 'Weedle', 'Weepinbell', 'Weezing', 'Whiscash', 'Whismur', 'Wigglytuff', 'Wingull', 'Woobuffet', 'Wooper', 'Wurmple', 'Wynaut', 'Xatu', 'Yanma', 'Zangoose', 'Zapdos', 'Zigzagoon', 'Zubat','Nathen','Chelsea','Hylla','Dust','Dust Wildfire','Fay','Oak','Starly','Looker','Hunter J']
spell = SpellChecker(distance=1)
spell.word_frequency.load_words(pokemonList)
print('''
==================================
FayDitor
Made by Aaryan Pandey for
Captain Moonshine
==================================''')
print('Splash Text:')
intros = ['Hello, Captain Moonshine','Greetings, I am human Aaryan speaking.','I\'m ready to edit the next chapter.','How is life in: Netherlands ?',str(socket.gethostbyname(socket.gethostname() ))+' is your IP Address. (dw lol, that information isn\'t being saved anywhere, im just creeping you out for fun)','Even a broken clock tells the right time twice a day, but a working misaligned clock is never correct. \n-AaryanGamer9','.... --- .-- .-- .- ... -.-- --- ..- .-. -.. .- -.-- ..--.. ','missingno','splash text.txt','Let\'s get editing!','Tristine, I want you to know that I am Kira.','I have been summoned here today for the purpose of editing your chapter, let\'s get started!','It\'s about time I told you, I\'m a junkie... who\'s high on blood!']
print(intros[random.randint(0,len(intros)-1)])
print('-------------------------')
print('[1] Enter Fanfic Chapter')
print('[2] Copy Fanfic Chapter from clipboard')
print('[3] Aaryan is a horrible friend')
print('[4] Quit')
print('--------------------------------------------------------------------------')
while True:
try:
selected = int(input('Enter a number corresponding to the option you would like to select: '))
if selected == 1:
print('-------------------------')
chapter = input('Enter the chapter:\n')
break
elif selected == 2:
chapter = pyperclip.paste()
break
elif selected == 3:
print(':(')
continue
elif selected == 4:
quit()
except ValueError:
print('You\'re supposed to enter a number, dummy.')
##############################################################################
def misSpelledPokemon(words):
suspicious = spell.unknown(words)
correctWordsDictionary = {}
for word in suspicious:
for candidate in spell.candidates(word):
candidate = list(candidate)
candidate[0] = candidate[0].upper()
fixedCandidate =''
for i in candidate:
fixedCandidate += i
candidate = fixedCandidate
if candidate in pokemonList:
correctWordsDictionary[word] = candidate
break
return correctWordsDictionary
chapterWords = re.split(r'[.,?! \+]',chapter)
editedChapter = chapter
while True:
chapterWords = re.split(r'[.,?! \+]',editedChapter)
print('---------------------------------------------')
print(' FayDitor Menu:')
print('---------------------------------------------')
print('[1] Scan Chapter for Misspelt Character Names (Very Useful, pretty much why I made FayDitor)')
print('[2] Scan Chapter for Misspelt Words (Sorta buggy, id rather do this manually when i edit it)')
print('[3] Change Scanning Depth (Unrequired)')
print('[4] Check grammar (Useful)')
print('[5] View Chapter Changes Side-By-Side (Also a bit weird)')
print('[6] Copy Chapter to Clipboard (Useful)')
print('[7] Write Edited Chapter to File (Useful)')
print('[8] Quit ')
print('[420] Notes')
print('-------------------------------------------------------------------------------------------')
while True:
try:
choice = int(input('Enter a number corresponding to the option you would like to select: '))
break
except ValueError:
print('Please enter a number...')
if choice == 1:
print('-----------------------------------------------------------------')
print('Here are the possibly misspelt Pokemon and Character names:')
print('Instructions:\n\'Y\' or \'Yes\' will replace the text.\n\'No\' or \'N\' will keep the text the same.\n\'Skip\' or \'S\' will take you back.\n\'E\' or \'Edit\' will allow you to suggest the correct spelling yourself.')
print('-----------------------------------------------------------------')
exitCode = False
invalidRegex = re.compile(r'^ should be')
for mis, cor in misSpelledPokemon(chapterWords).items():
while True:
x = mis + ' should be '+ cor
if invalidRegex.search(x) != None or '\'' in mis or '"' in mis or '“' in mis or cor == 'a':
break
else:
print('-----------------')
print(x)
confirmation = input('Y/N/S/E: ')
if confirmation[0].upper() == 'Y':
editedChapter = editedChapter.replace(mis,cor)
break
elif confirmation[0].upper() == 'N':
break
elif confirmation[0].upper() == 'S':
exitCode = True
break
elif confirmation[0].upper() == 'E':
correct = input('What will you replace '+mis+' by? (\'back\') to go back.')
if correct == 'back' or correct == '\'back\'':
continue
else:
editedChapter = editedChapter.replace(mis,correct)
break
else:
print('I don\'t know how to '+confirmation)
continue
print('All Done!')
if exitCode == True:
break
elif choice == 2:
suspicious = spell.unknown(chapterWords)
print('-----------------------------------------------')
print('Here are the possibly misspelt words: ')
print('Instructions:\n\'Y\' or \'Yes\' will replace the text.\n\'No\' or \'N\' will keep the text the same.\n\'Skip\' or \'S\' will take you back.\n\'A\' or \'All\' will replace all occurences of text\n\'E\' or \'Edit\' will allow you to suggest your own correction. ')
print('-----------------------------------------------')
exitCode = False
for word in suspicious:
while True:
correct = spell.correction(word)
x = word + ' should be '+ correct
if x == ' should be a':
break
elif word == correct:
break
elif correct == 'arendt':
break
elif word.replace('\'','').replace('’','') == correct or word.replace('\'','').replace('’','') == '':
break
elif word == ' ':
break
elif word == 'isn\'t' or correct == 'a' or word == '“' or '(' in word or ')' in word:
break
else:
print(x)
print('Yes/No/Stop Editing/Change all occurrences/Edit (Set manual correction of text)')
confirmation = input('Y/N/S/A/E: ')
if confirmation[0].upper() == 'Y':
editedChapter = editedChapter.replace(word, correct, 1)
break
elif confirmation[0].upper() == 'N':
break
elif confirmation[0].upper() == 'S':
exitCode = True
break
elif confirmation[0].upper() == 'A':
editedChapter = editedChapter.replace(word, correct)
break
elif confirmation[0].upper() == 'E':
correct = input('What will you replace '+word+' by? (\'back\' to go back): ' )
if correct == 'back' or correct == '\'back\'':
continue
else:
editedChapter = editedChapter.replace(word, correct, 1)
break
else:
print('I don\'t know how to '+confirmation)
continue
if exitCode == True:
break
elif choice == 3:
while True:
try:
print('Enter scanning depth (Default 2, for faster and weaker results enter 1. (Only enter 3+ if you are very sure))')
scanningDepth = int(input(''))
break
except ValueError:
print('Try again.')
spell.distance = scanningDepth
elif choice == 4:
print('---------------------------------------------------')
print('Checking multiple spaces...')
editedChapter = re.sub(r'\s+',' ',editedChapter)
print(editedChapter)
print('Checking space after "," and "." ...')
print(editedChapter)
editedChapter = re.sub(r',(\w)',r', \1',editedChapter)
print(editedChapter)
editedChapter = re.sub(r'\.(\w)',r'. \1',editedChapter)
editedChapter = re.sub(r'.( )(txt|mp3|mp4|mov|exe)',r'.\2',editedChapter)
print(editedChapter)
print('Good to go!')
print('---------------------------------------------------')
continue
elif choice == 6:
pyperclip.copy(editedChapter)
print('Successfully copied to clipboard.')
elif choice == 5:
displayChapter = 'Original Chapter\n'+chapter
displayEditedChapter = 'Edited Chapter\n'+editedChapter
print('----------------------------------')
print(displayChapter)
print('----------------------------------')
print(displayEditedChapter)
elif choice == 7:
f = open('Chapter.txt','w+')
f.write(editedChapter)
f.close()
elif choice == 8:
quit()
elif choice == 420:
print('Thank you for using FayDitor. I made a small little program in a few hours of button mashing to make both my and your job a tad bit easier. I spent several hours working for this, and I certainly learned a lot about Python in its making. Drop by any suggestions in the chat and hopefully you enjoy using FayDitor :D')
elif choice == 666:
print('you found easter egg wow')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment