repl.it
@mat1/

raid shadow legends

Python

No description

fork
loading
Files
  • main.py
  • input.txt
  • stop_words.txt
main.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
import requests
import string

with open('input.txt', 'r') as f:
	inputted = f.read()

with open('stop_words.txt', 'r') as f:
	stop_words = f.read().splitlines()

word_letters = string.ascii_letters + "'-"

def is_stop_word(word):
	return word in stop_words

def convert_word(word):
	if is_stop_word(word): return word
	r = requests.get(
		'https://api.datamuse.com/words?ml=' + word
	)
	data = r.json()
	if not data: return word
	new_word = data[0]['word']
	return new_word

built_word = ''

new_inputted = inputted.replace('’', "''") + '\n'

for char in new_inputted:
	if char in word_letters:
		built_word += char
		continue
	else:
		if built_word:
			new_word = convert_word(built_word)
			if built_word.istitle():
				new_word = new_word.title()
			print(new_word, end='', flush=True)
			built_word = ''

		print(char, end='', flush=True)
		
?