Created
April 24, 2022 07:44
-
-
Save spaskalev/36259a2ca27f63ff5e1100704cefb1bc to your computer and use it in GitHub Desktop.
Duplex printing aid for non-duplex printers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Duplex printing aid for non-duplex printers | |
# | |
# This tool splits page ranges into odd and even page numbers. | |
# Print the first set in one go, feed the paper back and print the second set. | |
import os | |
import sys | |
if len(sys.argv) == 1: | |
print("Enter page ranges, separated by commas or spaces.") | |
sys.exit(0) | |
pages = set() | |
for page_range in ",".join(sys.argv[1:]).split(","): | |
if "-" in page_range: | |
start, end = [int(x) for x in page_range.split("-")] | |
for page in range(start, end + 1): | |
pages.add(page) | |
else: | |
pages.add(int(page_range)) | |
pages = list(pages) | |
pages.sort() | |
split = [[], []] # even, odds | |
for page in pages: | |
split[(page % 2)].append(str(page)) | |
if (pages[0] % 2) == 1: | |
split.reverse() | |
print(",".join(split[0])) | |
print(",".join(split[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment