-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasyCorrect.py
71 lines (52 loc) · 1.93 KB
/
easyCorrect.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import json
import webbrowser
import pyperclip
from pynput import keyboard
import pyautogui
import os
class Feeder:
def __init__(self):
with open('config.json', 'r') as file:
config = json.load(file)
if not os.path.isfile('input.txt'):
with open('input.txt', 'w', encoding='UTF-8') as file:
file.write('')
with open('input.txt', 'r', encoding='UTF-8') as file:
inputContent = file.read()
with open('output.txt', 'w', encoding='UTF-8') as file:
file.write('')
self.iterator = self.split(inputContent, config['separator'], config['maxCharacterCount'])
self.firstIteration = True
webbrowser.open(config['url'])
def split(self, text:str, sep:str, maxCharacterCount:int):
content = ''
for sentence in text.split(sep):
if len(content) + len(sentence) > maxCharacterCount:
yield content
content = ''
content += sentence + sep
yield content
def step(self):
# append corrected text to output
if not self.firstIteration:
pyautogui.hotkey('ctrl', 'x')
with open('output.txt', 'a', encoding='UTF-8') as file:
file.write(pyperclip.paste())
else:
self.firstIteration = False
# paste following content into text field
content = next(self.iterator)
pyperclip.copy(content)
pyautogui.hotkey('ctrl', 'v')
def main():
feeder = Feeder()
def for_canonical(f):
return lambda k: f(listener.canonical(k))
hotkey = keyboard.HotKey(keyboard.HotKey.parse('<ctrl>+a'), feeder.step)
with keyboard.Listener(on_press=for_canonical(hotkey.press), on_release=for_canonical(hotkey.release)) as listener:
try:
listener.join()
except StopIteration:
pass
if __name__ == '__main__':
main()