91 lines
2.1 KiB
Python
91 lines
2.1 KiB
Python
import subprocess
|
|
|
|
import os, time
|
|
|
|
from os.path import expanduser
|
|
home = expanduser("~")
|
|
|
|
mainCategory = ""
|
|
|
|
subCategory = ""
|
|
|
|
numberOfPages = -1
|
|
|
|
print("")
|
|
|
|
#Try to get the URI of the printer at the file in ~/.local/share/scan-auto/printer_uri
|
|
|
|
try:
|
|
|
|
f = open(home+"/.local/share/scan-auto/printer_uri", "r")
|
|
|
|
print("Printer URI is:")
|
|
|
|
printerURI = f.readline()
|
|
|
|
print(printerURI)
|
|
except:
|
|
print("Please create a file at " + home + "/.local/share/scan-auto/printer_uri")
|
|
|
|
print("And populate it with the hp-probe URI of your printer, e.g: escl:https://192.168.X.XX:443")
|
|
|
|
exit()
|
|
|
|
while mainCategory == "":
|
|
try:
|
|
mainCategory = str(input("Main category of document: "))
|
|
|
|
except:
|
|
|
|
mainCategory = ""
|
|
|
|
if mainCategory == "":
|
|
#Not best way to do this, but it's a small script, so idc :shrug:
|
|
os.system("clear")
|
|
print("Invalid input, please try again:")
|
|
|
|
#Keep the terminal clean :)
|
|
|
|
print("")
|
|
|
|
while subCategory == "":
|
|
try:
|
|
subCategory = str(input("Subcategory of document: "))
|
|
|
|
except:
|
|
|
|
subCategory = ""
|
|
|
|
if subCategory == "":
|
|
#Not best way to do this, but it's a small script, so idc :shrug:
|
|
os.system("clear")
|
|
print("Invalid input, please try again:")
|
|
|
|
print("")
|
|
|
|
while numberOfPages <= 0:
|
|
try:
|
|
numberOfPages = int(input("Number of pages for document: "))
|
|
|
|
except:
|
|
|
|
numberOfPages = -1
|
|
|
|
if numberOfPages <= 0:
|
|
#Not best way to do this, but it's a small script, so idc :shrug:
|
|
os.system("clear")
|
|
print("Invalid input, please try again:")
|
|
|
|
|
|
#The inputs have passed validation - onto the fun part :)
|
|
|
|
finalCommand = ""
|
|
|
|
def putCommandTogether(pageNumber=int()):
|
|
|
|
#Final command looks like this: hp-scan -d escl:https://192.168.0.XX:443 -o <mainCategory>-<subCategory>-pg<pageNumber>.jpg -mcolor; magick convert <mainCategory>-<subCategory>-<pageNumber>.jpg img.pdf
|
|
|
|
finalCommand = "hp-scan -d " + printerURI
|
|
|
|
finalCommand = finalCommand + "-o " + mainCategory + "-" + subCategory + "-pg" + pageNumber
|