-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyAutoGUI.py
More file actions
67 lines (54 loc) · 2.04 KB
/
Copy pathPyAutoGUI.py
File metadata and controls
67 lines (54 loc) · 2.04 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
import pyautogui
import subprocess
import time
import os
import pytesseract
import logging
from PIL import Image
class Scanner:
def __init__(self):
self.acronis_path = r"C:\Program Files (x86)\Acronis\TrueImageHome\TrueImageLauncher.exe"
self.history = []
logging.basicConfig(
filename="scan_log.txt",
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
)
logging.info("Scanner initialized.")
def extract_text_from_screenshot(self):
try:
image = Image.open("scan_result.png")
text = pytesseract.image_to_string(image)
return text
except Exception as e:
logging.error(f"Error extracting text from screenshot: {e}")
return ""
def scan_file(self, file_path):
try:
logging.info(f"Starting scan for file: {file_path}")
print("Launching Acronis TrueImage for scanning...")
subprocess.Popen(self.acronis_path)
time.sleep(5)
print("Selecting file for scan...")
pyautogui.click(500, 500)
time.sleep(1)
pyautogui.write(file_path)
pyautogui.press('enter')
time.sleep(1)
print("Starting scan...")
pyautogui.click(600, 600)
time.sleep(5)
screenshot = pyautogui.screenshot()
screenshot.save("scan_result.png")
screenshot_text = self.extract_text_from_screenshot()
result = "Infected" if "Infected" in screenshot_text else "Clean"
self.history.append({'file': file_path, 'result': result})
logging.info(f"Scan completed: {file_path} - {result}")
print(f"Scan completed. File is {result}")
return 1 if result == "Infected" else 0
except Exception as e:
logging.error(f"Error during file scan: {e}")
return -1
def load_scan_history(self):
logging.info("Loading scan history.")
return self.history