Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert the clipboard content #731

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ weasyprint = "56.0"
cffi = "1.15.1"
pikepdf = "5.4.0"
zxing-cpp = "1.4.0"
pyperclip = "1.8.2"

[tool.poetry.dev-dependencies]
prospector = { version = "1.7.7", extras = ["with_bandit", "with_mypy", "with_pyroma"] }
Expand Down
28 changes: 28 additions & 0 deletions scan_to_paperless/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import argcomplete
import numpy as np
import pyperclip
from ruamel.yaml.main import YAML
from skimage import io

Expand Down Expand Up @@ -44,6 +45,15 @@ def output(cmd: List[str], cmd2: Optional[List[str]] = None, **kwargs: Any) -> b
sys.exit(1)


def convert_clipboard() -> None:
"""Convert clipboard code from the PDF."""
original = pyperclip.paste()
new = "\n".join(["" if e == "|" else e for e in original.split("\n")])
if new != original:
pyperclip.copy(new)
print(new)


def main() -> None:
"""Scan a new document."""
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -76,10 +86,17 @@ def main() -> None:
parser.add_argument(
"--set-config",
nargs=2,
metavar=("KEY", "VALUE"),
action="append",
default=[],
help="Set a configuration option",
)
parser.add_argument(
"--convert-clipboard",
action="store_true",
help="Wait and convert clipboard content, used to fix the newlines in the copied codes, "
"see requirement: https://pypi.org/project/pyperclip/",
)

argcomplete.autocomplete(parser)
args = parser.parse_args()
Expand All @@ -94,6 +111,17 @@ def main() -> None:
yaml.dump(config, sys.stdout)
sys.exit()

if args.convert_clipboard:
print("Wait for clipboard content to be converted, press Ctrl+C to stop")
convert_clipboard()
try:
while True:
pyperclip.waitForNewPaste()
convert_clipboard()
except KeyboardInterrupt:
print()
sys.exit()

dirty = False
for conf in args.set_config:
config[conf[0]] = conf[1] # type: ignore
Expand Down