|
4 | 4 |
|
5 | 5 | logging.basicConfig(
|
6 | 6 | level=logging.DEBUG, format=' %(asctime)s - %(levelname)s- %(message)s')
|
7 |
| -""" |
8 |
| -There is also an optional region keyword argument, if you do not want a screenshot of the entire screen. You can pass a four-integer tuple of the left, top, width, and height of the region to capture: |
9 |
| ->>> im = pyautogui.screenshot(region=(0,0, 300, 400)) |
10 |
| -
|
11 |
| -These "locate" functions are fairly expensive; they can take a full second to run. The best way to speed them up is to pass a region argument (a 4-integer tuple of (left, top, width, height)) to only search a smaller region of the screen instead of the full screen: |
12 |
| ->>> pyautogui.locateOnScreen('someButton.png', region=(0,0, 300, 400)) |
13 |
| -
|
14 |
| ->>> button7location = pyautogui.locateOnScreen('calc7key.png', grayscale=True) |
15 |
| -
|
16 |
| -
|
17 |
| -left = 459, |
18 |
| -top = 124, |
19 |
| -width = 986, |
20 |
| -height = 913 |
21 |
| -
|
22 |
| -left side In [2]: pyautogui.position() |
23 |
| -Out[2]: Point(x=459, y=412) x left |
24 |
| -
|
25 |
| -In [3]: pyautogui.position() |
26 |
| -Out[3]: Point(x=1443, y=416) 986 width |
27 |
| -
|
28 |
| -In [4]: pyautogui.position() top panel |
29 |
| -Out[4]: Point(x=466, y=128) height |
30 |
| -
|
31 |
| -In [5]: pyautogui.position() |
32 |
| -Out[5]: Point(x=462, y=125) y top |
33 |
| -
|
34 |
| -In [6]: pyautogui.position() bottom panel |
35 |
| -Out[6]: Point(x=439, y=1037) |
36 |
| -
|
37 |
| -Distance between close buttons horizontally 160 |
38 |
| -
|
39 |
| -In [7]: pyautogui.position() |
40 |
| -Out[7]: Point(x=605, y=389) |
41 |
| -
|
42 |
| -In [8]: pyautogui.position() |
43 |
| -Out[8]: Point(x=765, y=385) |
44 |
| -
|
45 |
| -Distance between close buttons vertically 204 |
46 | 7 |
|
47 |
| -In [10]: pyautogui.position() |
48 |
| -Out[10]: Point(x=605, y=448) |
49 |
| -
|
50 |
| -In [11]: pyautogui.position() |
51 |
| -Out[11]: Point(x=605, y=652) |
52 |
| -
|
53 |
| -close button size region overapproximation: 40, 40 |
54 |
| -In [20]: pyautogui.position() |
55 |
| -Out[20]: Point(x=591, y=546) |
56 |
| -
|
57 |
| -In [21]: pyautogui.position() |
58 |
| -Out[21]: Point(x=620, y=545) |
59 |
| -
|
60 |
| -
|
61 |
| -""" |
62 |
| - |
63 |
| -pyautogui.PAUSE = 1 |
| 8 | +pyautogui.PAUSE = 0.5 |
64 | 9 | # pyautogui.FAILSAFE = True
|
65 | 10 | numbers = ''
|
66 | 11 | """
|
| 12 | +Caution: Experimental Code. Most probably won't work in your machine due to a myriad of unobservable factors. |
67 | 13 |
|
68 |
| -algo: |
| 14 | +basic form of algo - written before implementation; so I kind of wrote based on this - but also deviated from here. But you will get a good idea about how I approached it from here. : |
69 | 15 | - run program with delay of 5 seconds,
|
70 | 16 | - visit https://www.facebook.com/ads/preferences/?entry_product=ad_settings_screen
|
71 | 17 | - hover mouse on first advertiser name, but not on close button
|
|
84 | 30 | time.sleep(5)
|
85 | 31 |
|
86 | 32 | logging.debug('starting')
|
| 33 | +scroll_value = -4.7 |
87 | 34 |
|
88 |
| -try: |
89 | 35 |
|
90 |
| - firstCloseButton = pyautogui.locateOnScreen( |
91 |
| - 'close.png', region=(459, 124, 986, 913), grayscale=True) |
92 |
| - firstCloseButtonPosition = pyautogui.center(firstCloseButton) |
| 36 | +def click_two_rows(firstCloseButtonPosition: tuple) -> tuple: |
| 37 | + |
93 | 38 | for j in range(2):
|
94 | 39 | logging.debug("clicking at " + str(firstCloseButtonPosition))
|
95 | 40 | pyautogui.moveTo(firstCloseButtonPosition)
|
96 |
| - # pyautogui.click(firstCloseButtonPosition) |
97 |
| - logging.debug("clicking at: " + str(firstCloseButtonPosition)) |
| 41 | + pyautogui.click(firstCloseButtonPosition) |
98 | 42 |
|
99 | 43 | for i in range(5):
|
100 | 44 | logging.debug("i = " + str(i))
|
|
107 | 51 | grayscale=True)
|
108 | 52 | current_position = pyautogui.center(current_position_location)
|
109 | 53 | pyautogui.moveTo(current_position)
|
110 |
| - # pyautogui.click() |
| 54 | + pyautogui.click(current_position) |
111 | 55 | logging.debug("clicking at " + str(current_position))
|
112 | 56 |
|
113 | 57 | logging.debug("horiontal done, returning at position: " +
|
|
118 | 62 | logging.debug("vertical adjustment done, returning at position: " +
|
119 | 63 | str(firstCloseButtonPosition))
|
120 | 64 | pyautogui.moveTo(firstCloseButtonPosition)
|
121 |
| - pyautogui.locateOnScreen('seemore.png') |
| 65 | + return firstCloseButtonPosition |
| 66 | + |
| 67 | + |
| 68 | +try: |
| 69 | + for i in range(10): |
| 70 | + firstCloseButton = pyautogui.locateOnScreen( |
| 71 | + 'close.png', region=(459, 124, 986, 913), grayscale=True) |
| 72 | + firstCloseButtonPosition = pyautogui.center(firstCloseButton) |
| 73 | + firstCloseButtonPosition = click_two_rows(firstCloseButtonPosition) |
| 74 | + logging.debug("looking for seemore button") |
| 75 | + seemore_loc = pyautogui.locateOnScreen( |
| 76 | + 'seemore.png', region=(800, 200, 200, 800), grayscale=True) |
| 77 | + seemore_position = pyautogui.center(seemore_loc) |
| 78 | + pyautogui.moveTo(seemore_position) |
| 79 | + pyautogui.click(seemore_position) |
| 80 | + logging.debug("seemore position clicked at : " + str(seemore_position)) |
| 81 | + logging.debug( |
| 82 | + "moving back to first position: " + str(firstCloseButtonPosition)) |
| 83 | + # input() |
| 84 | + pyautogui.moveTo(firstCloseButtonPosition[0], |
| 85 | + firstCloseButtonPosition[1] - 204) |
| 86 | + # input() |
| 87 | + pyautogui.move(-70, 0) |
| 88 | + # input() |
| 89 | + pyautogui.scroll(scroll_value) |
| 90 | + logging.debug("scrolled by " + str(scroll_value)) |
| 91 | + |
122 | 92 | except Exception as e:
|
123 | 93 |
|
124 | 94 | print(e)
|
0 commit comments