Commit b54b07ca authored by Erik Malone's avatar Erik Malone

Improved working of PyAutoGUI automation; now requires only a minimum 67%...

Improved working of PyAutoGUI automation; now requires only a minimum 67% match for an image for elements to be found instead of 100%.  Also added Itachirumon.  Thanks to github.com/drov0 for some of the code that was used to improve the automation process.
parent 8a0ae057
from bs4 import BeautifulSoup
from pathlib import Path
from os.path import abspath
from os import mkdir
from bs4 import BeautifulSoup
from pathlib import Path
from os.path import abspath
from os import mkdir
import markovify, json, time
import markovify, json, time, cv2
import pyautogui as pyag
import pygetwindow as pygw
import numpy as np
addends = { 'davedan': 'suck my salty balls cracker' }
def centresearch( img, precision = 0.67 ):
im = pyag.screenshot()
im_gray = cv2.cvtColor( np.array( im ), cv2.COLOR_BGR2GRAY )
template = cv2.imread( img, 0 )
template.shape[::-1]
res = cv2.matchTemplate( im_gray,
template,
cv2.TM_CCOEFF_NORMED )
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc( res )
if ( max_val < precision ):
return [-1,-1]
height, width = template.shape
return ( max_loc[0] + ( width // 2 ),
max_loc[1] + ( height // 2 ) )
def centresearch_loop( img, precision = 0.67, rate = 0.1 ):
x, y = centresearch( img, precision )
while x == -1:
time.sleep( rate )
x, y = centresearch( img, precision )
return x, y
def focus_on_firefox():
ffox = pygw.getWindowsWithTitle( 'Mozilla Firefox' )[0]
ffox.activate()
......@@ -28,25 +53,23 @@ def save_source( folder, n = 0 ):
pyag.hotkey( 'ctrl', 'u' )
pyag.hotkey( 'ctrl', 's' )
time.sleep( 1.0 ) # Wait for Save As... window.
x, y = pyag.locateCenterOnScreen( 'save-as-fldr.png' )
x, y = centresearch_loop( 'save-as-fldr.png' )
pyag.moveTo( x + 50, y, duration = 0.1 )
pyag.click()
path = abspath( f'./{folder}' )
pyag.typewrite( path )
pyag.press( 'enter' )
time.sleep( 1.0 ) # Wait for navigation to folder.
try:
x, y = pyag.locateCenterOnScreen( 'save-as-fname.png' )
except:
x, y = pyag.locateCenterOnScreen( 'save-as-fname-alt.png' )
x, y = centresearch_loop( 'save-as-fname.png' )
pyag.moveTo( x + 50, y, duration = 0.1 )
pyag.click()
pyag.hotkey( 'ctrl', 'a' )
pyag.press( 'delete' )
pyag.typewrite( f'posts{n}.txt' )
try:
x, y = pyag.locateCenterOnScreen( 'save-as-btn.png' )
except:
x, y = pyag.locateCenterOnScreen( 'save-as-btn-alt.png' )
pyag.moveTo( x, y, duration = 0.1 )
x, y = centresearch_loop( 'save-as-btn.png' )
pyag.moveTo( x + 10, y + 10, duration = 0.1 )
pyag.click()
def mine_user( folder, uid, n = 10 ):
......@@ -152,4 +175,4 @@ def gen_sentences_for_all( n = 5,
# for some reason, it refuses to run with the
# elevated permissions that PyAutoGUI needs to work.
#if __name__ == '__main__':
# mine_user( 'the illusive man', 704, n = 10 )
# mine_user( 'itachirumon', 17, n = 10 )
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment