From 44bfbf80e85caacc3680e57376cf8e3de587d14d Mon Sep 17 00:00:00 2001 From: joseph <82421938+PilgrimSpark@users.noreply.github.com> Date: Tue, 13 Apr 2021 21:49:01 -0500 Subject: [PATCH 1/5] Rewritten to use pyautogui instead of autopy --- README.md | 7 +++++-- requirements.txt | 2 +- app.py => vitalsource-printer.py | 11 +++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) rename app.py => vitalsource-printer.py (84%) diff --git a/README.md b/README.md index aff4f20..b1969ea 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ # Print a book from VitalSource Bookshelf to PDF -This script simulates mouse click in the next page button and takes screenshot of -current page in the opened book. +This script simulates mouse click in the next page button and takes screenshot +of current page in the opened book. +This script depends on pyautogui for automating mouse clicks and screenshots. +pyautogui uses the Pillow module for screenshots. OS X uses the "screencapture" +command. Linux uses the "scrot" command, which you may need to install. ## Usage diff --git a/requirements.txt b/requirements.txt index c9dd2eb..efe58f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -autopy +pyautogui img2pdf diff --git a/app.py b/vitalsource-printer.py similarity index 84% rename from app.py rename to vitalsource-printer.py index 8fc0877..4743b28 100644 --- a/app.py +++ b/vitalsource-printer.py @@ -1,8 +1,9 @@ import argparse import os import tempfile +import time -import autopy +import pyautogui import img2pdf @@ -15,9 +16,11 @@ def screenshot(top_left, right_bottom, next_page, total_page): file_name = os.path.join(temp_dir, 'book-page-{}.png'.format(page_num)) images.append(file_name) - autopy.mouse.move(*next_page) - autopy.mouse.click(delay=1) - autopy.bitmap.capture_screen((top_left, rect_size)).save(file_name) + pyautogui.click(x=next_page[0], y=next_page[1]) + time.sleep(1) + pyautogui.screenshot(file_name, + region=(top_left[0], top_left[1], rect_size[0], + rect_size[1])) return images From 44be78ad09b96609e7d28b0877962cee9d317950 Mon Sep 17 00:00:00 2001 From: joseph <82421938+PilgrimSpark@users.noreply.github.com> Date: Tue, 13 Apr 2021 22:01:34 -0500 Subject: [PATCH 2/5] Fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1969ea..68e0a23 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,6 @@ command. Linux uses the "scrot" command, which you may need to install. ```bash pip install -r requirements.txt -python app.py top_left right_bottom next_button total_page +python vitalsource-printer.py top_left right_bottom next_button total_page # Ex: python app.py 153,78 892,990 941,537 785 ``` From be515ced4985c183a8ffd4f2cb2d94c4c756b620 Mon Sep 17 00:00:00 2001 From: joseph <82421938+PilgrimSpark@users.noreply.github.com> Date: Mon, 26 Apr 2021 21:19:39 -0500 Subject: [PATCH 3/5] take screenshot before click --- vitalsource-printer.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vitalsource-printer.py b/vitalsource-printer.py index 4743b28..b4e5922 100644 --- a/vitalsource-printer.py +++ b/vitalsource-printer.py @@ -16,11 +16,13 @@ def screenshot(top_left, right_bottom, next_page, total_page): file_name = os.path.join(temp_dir, 'book-page-{}.png'.format(page_num)) images.append(file_name) - pyautogui.click(x=next_page[0], y=next_page[1]) - time.sleep(1) + # Take a screenshot pyautogui.screenshot(file_name, region=(top_left[0], top_left[1], rect_size[0], rect_size[1])) + # click the next button + pyautogui.click(x=next_page[0], y=next_page[1]) + time.sleep(1) # wait a second return images From 8cbe846261e68785489df37afe9b6672b9c16add Mon Sep 17 00:00:00 2001 From: joseph <82421938+PilgrimSpark@users.noreply.github.com> Date: Mon, 26 Apr 2021 21:40:35 -0500 Subject: [PATCH 4/5] Added instructions for finding coordinates --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 68e0a23..a72d1f1 100644 --- a/README.md +++ b/README.md @@ -12,5 +12,16 @@ command. Linux uses the "scrot" command, which you may need to install. ```bash pip install -r requirements.txt python vitalsource-printer.py top_left right_bottom next_button total_page -# Ex: python app.py 153,78 892,990 941,537 785 +# Ex: python vitalsource-printer.py 153,78 892,990 941,537 785 +``` + +## Finding Cursor Coordinates + +To find the coordinates you will need to supply as inputs for the +script, you may use "position()" function of the pyautogui module. + +```bash +python +>>> import pyautogui +>>> pyautogui.position() # while cursor is on desired location ``` From 6281a8680699d8ad20c073b2540ec6cfaa6bb989 Mon Sep 17 00:00:00 2001 From: joseph <82421938+PilgrimSpark@users.noreply.github.com> Date: Sun, 2 May 2021 17:50:36 -0500 Subject: [PATCH 5/5] added shebang --- vitalsource-printer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vitalsource-printer.py b/vitalsource-printer.py index b4e5922..5e19415 100644 --- a/vitalsource-printer.py +++ b/vitalsource-printer.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + import argparse import os import tempfile