-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.py
More file actions
155 lines (130 loc) · 4.01 KB
/
convert.py
File metadata and controls
155 lines (130 loc) · 4.01 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from tkinter import PhotoImage
def create_img(blockdata,filename,n):
try:
img = (PhotoImage(file = f"screenshot/{filename}/{n}.png"))
img = img.subsample(3,3)
blockdata.append(img)
except:
blockdata.append(None)
def process(command,filename,xylst):
blockdata = [0]
if command[0] == 0:
z,x,y,tp,s,n,t = command
create_img(blockdata,filename,n)
blockdata.append([z,x,y,tp,s,n,t])
blockdata.append(0)
blockdata.append(
f"""
x,y = {x},{y}
gen = pyautogui.locateAllOnScreen(\"screenshot/{filename}/{n}.png\")
try:
g = next(gen)
a,b,c,d = g
x = a+c//2
y = b+d//2
try:
next(gen)
x,y = {x},{y}
except:
pass
except:
pass
pyautogui.moveTo(x,y)
"""
)
if type(tp) == str:
if s:
blockdata.insert(2,f"Pressed {tp} click")
else:
blockdata.insert(2,f"Released {tp} click")
blockdata[5] += f"pyautogui.mouseDown(button = \"{tp}\")\n"
else:
if tp == 120:
blockdata.insert(2,"Scroll up")
else:
blockdata.insert(2,"Scroll down")
blockdata[5] += f"pyautogui.scroll({tp},{x},{y})\n"
blockdata[5] += f"time.sleep({t})\n\n"
elif command[0] == 1:
z,s,k,n,t = command
create_img(blockdata,filename,n)
blockdata.append([z,s,k,n,t])
blockdata.append(0)
blockdata.append("")
if s:
blockdata.insert(2,f"Pressed {k}")
blockdata[5] += f"pyautogui.keyDown(\"{k}\")\n"
else:
blockdata.insert(2,f"Released {k}")
blockdata[5] += f"pyautogui.keyUp(\"{k}\")\n"
blockdata[5] += f"time.sleep({t})\n"
blockdata[5] += f"\n"
elif command[0] == 2:
z,x,y,s,n,t = command
if s == 1:
blockdata = 0
xylst[0] = x
xylst[1] = y
elif s == 2:
try:
img = (PhotoImage(file = f"screenshot/{filename}/img_extraction_{n}.png"))
img = img.subsample(3,3) ###
blockdata.append(img)
except:
blockdata.append(None)
blockdata.append([z,x,y,s,n,t])
blockdata.append(0)
blockdata.insert(2,"img_extraction")
blockdata.append(
f"""
try:
os.mkdir(\"img_extraction/{filename}\")
except:
pass
i = 0
while True:
if f"{{i}}.png" not in os.listdir("img_extraction/{filename}"):
break
i+=1
pyautogui.screenshot(f\"img_extraction/{filename}/{{i}}.png\",region=({min(xylst[0],x)}, {min(xylst[1],y)}, {max(xylst[0],x)-min(xylst[0],x)}, {max(xylst[1],y)-min(xylst[1],y)}))
time.sleep({t})
"""
)
elif command[0] == 3:
z,x,y,s,n,t = command
if s == 1:
blockdata = 0
xylst[0] = x
xylst[1] = y
elif s == 2:
try:
img = (PhotoImage(file = f"screenshot/{filename}/text_extraction_{n}.png"))
img = img.subsample(3,3) ###
blockdata.append(img)
except:
blockdata.append(None)
blockdata.append([z,x,y,s,n,t])
blockdata.append(0)
blockdata.insert(2,"text_extraction")
blockdata.append(
f"""
img = pyautogui.screenshot(region = ({min(xylst[0],x)}, {min(xylst[1],y)}, {max(xylst[0],x)-min(xylst[0],x)}, {max(xylst[1],y)-min(xylst[1],y)}))
pytesseract.tesseract_cmd = path_to_tesseract
text = pytesseract.image_to_string(img)
with open(f\"text_extraction/{filename}.txt\",\"a\") as f:
f.write(text)
time.sleep({t})
"""
)
return blockdata
if __name__ == "__main__":
a = process( [
0,
805,
507,
-120,
2,
8,
0.08033037185668945
], "record_1",[0,0])
print(a)