-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (38 loc) · 1.58 KB
/
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
43
44
45
46
47
48
49
50
51
import keyboard
import pyautogui
from mouse import starting_coords, move_right, move_down, calculate_movement_auto
from screen_grab import crop_item, is_cell_empty
from utils import on_press, delete_existing_pngs
def main():
print("Press F2 to start script...")
# Wait indefinitely for the F2 key to be pressed
keyboard.wait('F2')
# Press 'F3' to stop the script
keyboard.on_press(callback=on_press('f3'))
delete_existing_pngs()
init_coords = starting_coords()
item_number = 1
right_px, down_px = calculate_movement_auto()
for row in range(3): # 3 rows
for col in range(11): # 11 columns
# Step 2: Check if the grid cell has an item
if is_cell_empty() == 0:
try:
crop_item(280, 450, 300, 900, item_number)
item_number += 1
except TypeError:
print(f"Failed to find item, row {row}, col {col}")
continue
# If this is not the last column in the row, move right
if col != 10:
move_right(right_px)
# After going through each cell in a row, return to initial coordinates
pyautogui.moveTo(init_coords.x, init_coords.y, 0.5) # Move back to initial coords
# If this is not the last row, move down once / twice
if row != 2:
for i in range(row + 1):
move_down(down_px)
# We have now gone through all 33 cells, the script is finished
print(f"Total non-empty items: {item_number - 1}")
if __name__ == "__main__":
main()