update multi apps
This commit is contained in:
@@ -47,7 +47,8 @@ from .docs import (
|
||||
check_file_exists,
|
||||
check_tabstops,
|
||||
compare_contains_image,
|
||||
compare_docx_images
|
||||
compare_docx_images,
|
||||
compare_image_text
|
||||
)
|
||||
from .general import (
|
||||
check_csv,
|
||||
|
||||
@@ -91,6 +91,17 @@ def is_expected_bookmarks(bookmarks: List[str], rule: Dict[str, Any]) -> float:
|
||||
bookmark_bar_websites_urls = [bookmark['url'] for bookmark in bookmarks['bookmark_bar']['children'] if
|
||||
bookmark['type'] == 'url']
|
||||
return 1. if set(bookmark_bar_websites_urls) == set(rule['urls']) else 0.
|
||||
elif rule['type'] == "liked_authors_websites_urls":
|
||||
# Check if "liked authors" folder exists
|
||||
liked_authors_folder = next((bookmark for bookmark in bookmarks['bookmark_bar']['children'] if
|
||||
bookmark['type'] == 'folder' and bookmark['name'] == 'Liked Authors'), None)
|
||||
if liked_authors_folder:
|
||||
# Check if it contains the specified URLs
|
||||
liked_authors_urls = [bookmark['url'] for bookmark in liked_authors_folder['children'] if
|
||||
bookmark['type'] == 'url']
|
||||
return 1. if set(liked_authors_urls) == set(rule['urls']) else 0.
|
||||
else:
|
||||
return 0.
|
||||
else:
|
||||
raise TypeError(f"{rule['type']} not support yet!")
|
||||
|
||||
|
||||
@@ -183,6 +183,16 @@ def compare_docx_images(docx_file1, docx_file2):
|
||||
return 0
|
||||
return 1
|
||||
|
||||
import pytesseract
|
||||
|
||||
def compare_image_text(image_path, rule):
|
||||
img = Image.open(image_path)
|
||||
img_text = pytesseract.image_to_string(img)
|
||||
if rule['type'] == 'text':
|
||||
return 1 if rule['text'] in img_text else 0
|
||||
else:
|
||||
raise ValueError("Unsupported rule type")
|
||||
|
||||
def compare_line_spacing(docx_file1, docx_file2):
|
||||
if not compare_docx_files(docx_file1, docx_file2):
|
||||
return 0
|
||||
|
||||
@@ -182,7 +182,7 @@ def compare_pptx_files(file1_path, file2_path, **options):
|
||||
else:
|
||||
return None
|
||||
|
||||
if get_slide_notes(slide1) != get_slide_notes(slide2) and examine_note:
|
||||
if get_slide_notes(slide1).strip() != get_slide_notes(slide2).strip() and examine_note:
|
||||
return 0
|
||||
# check if the shapes are the same
|
||||
for shape1, shape2 in zip(slide1.shapes, slide2.shapes):
|
||||
@@ -235,7 +235,7 @@ def compare_pptx_files(file1_path, file2_path, **options):
|
||||
return 0
|
||||
|
||||
if hasattr(shape1, "text") and hasattr(shape2, "text"):
|
||||
if shape1.text != shape2.text and examine_text:
|
||||
if shape1.text.strip() != shape2.text.strip() and examine_text:
|
||||
return 0
|
||||
|
||||
# check if the paragraphs are the same
|
||||
|
||||
Reference in New Issue
Block a user