Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91621
| Path | csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ethan@stoneleaf.us> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; '"""': 0.05; 'main()': 0.07; 'option,': 0.07; 'rewrite': 0.07; '__future__': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'input,': 0.09; 'message-id:@stoneleaf.us': 0.09; 'script,': 0.09; 'threshold': 0.09; 'def': 0.14; 'output': 0.15; "'convert": 0.16; '--verbose': 0.16; 'commandline': 0.16; 'count,': 0.16; 'mine.': 0.16; 'skipped': 0.16; 'true:': 0.16; 'writer': 0.16; 'processor': 0.18; 'skip:{ 20': 0.18; 'usability': 0.18; 'input': 0.18; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'raise': 0.24; 'script': 0.25; 'header:User-Agent:1': 0.26; 'skip:# 10': 0.27; 'skip:e 30': 0.27; 'looks': 0.29; 'command-line': 0.29; 'prints': 0.29; '~ethan~': 0.29; 'convert': 0.29; "skip:' 10": 0.30; 'writes': 0.31; 'print': 0.31; 'skip:s 30': 0.31; '[1]': 0.32; 'scanned': 0.32; 'everyone': 0.34; 'running': 0.34; 'needed': 0.34; 'changed': 0.35; 'to:addr:python-list': 0.35; 'attempt': 0.35; 'list': 0.35; 'skip:{ 10': 0.36; 'received:10': 0.37; 'subject:: ': 0.37; 'skip:i 20': 0.37; "skip:' 20": 0.37; 'manual': 0.38; 'skip:v 20': 0.38; 'to:addr:python.org': 0.39; 'skip:t 20': 0.40; 'viewing': 0.61; 'user,': 0.67; 'opinions': 0.69; 'verification': 0.73; 'received:10.1.10': 0.84; 'subject:Using': 0.84; 'type=int,': 0.84; 'good,': 0.93 |
| Date | Sun, 31 May 2015 22:08:06 -0700 |
| From | Ethan Furman <ethan@stoneleaf.us> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Using Python instead of Bash |
| References | <87h9qsnckl.fsf@Equus.decebal.nl> |
| In-Reply-To | <87h9qsnckl.fsf@Equus.decebal.nl> |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.265.1433136649.5151.python-list@python.org> (permalink) |
| Lines | 60 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1433136649 news.xs4all.nl 2825 [2001:888:2000:d::a6]:38360 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:91621 |
Show key headers only | View raw
Just for funsies, I did a slight rewrite using my scription[1] library:
--8<------------------------------------------------------------------------------
#!/usr/bin/python3
"""
Convert scanned images: contrast is increased, size is enlarged,
format is changed from jpeg to png.
"""
from __future__ import print_function # only needed if running in 2
from glob import glob
from scription import *
@Command(
threshold=Spec('cutoff value for white vs black', OPTION, type=int, default=66),
verify=Spec('confirm conversion by viewing on screen', FLAG),
)
def image_convert(verify, threshold):
for count, input in enumerate(sorted(glob('*.JPG')), start=1):
output = '{0:02d}.png'.format(count)
# only prints if --verbose on commandline
print('Going to convert {} to {}'.format(input, output))
while True:
# Execute automatically parses into a list
attempt = Execute(
'convert -threshold {}% {} {}'.format(threshold, input, output),
interactive='echo',
)
if attempt.returncode:
raise SystemExit(attempt.returncode)
if not verify:
break
attempt = Execute(
'display_the_png {}'.format(output),
interactive='echo',
)
if attempt.returncode:
raise SystemExit(attempt.returncode)
if get_response('Does the image look good?'):
break
threshold = get_response("New threshold value:", type=int)
# conversion looks good, or manual verification skipped
print('going to print {0}'.format(output))
attempt = Execute(
'lpr -o fit-to-page -o media=A4 {}'.format(output),
interactive='echo',
)
if attempt.returncode:
raise SystemExit(attempt.returncode)
Main()
--8<------------------------------------------------------------------------------
Opinions about the usability of the above script, both as the script writer and as the user, welcomed.
--
~Ethan~
[1] yes, everyone apparently writes their own command-line processor -- this one is mine. ;)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-05-31 14:42 +0200
Re: Using Python instead of Bash Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2015-05-31 16:02 +0200
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-05-31 18:36 +0200
Re: Using Python instead of Bash Cem Karan <cfkaran2@gmail.com> - 2015-05-31 10:14 -0400
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-05-31 18:58 +0200
Re: Using Python instead of Bash Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-31 11:05 -0400
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-05-31 19:06 +0200
Re: Using Python instead of Bash Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-31 20:53 -0400
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 11:25 +0200
Re: Using Python instead of Bash Laura Creighton <lac@openend.se> - 2015-06-01 09:11 +0200
Re: Using Python instead of Bash Ethan Furman <ethan@stoneleaf.us> - 2015-05-31 22:08 -0700
Re: Using Python instead of Bash Larry Hudson <orgnut@yahoo.com> - 2015-06-01 00:56 -0700
Re: Using Python instead of Bash Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-06-01 11:06 +0300
Re: Using Python instead of Bash alister <alister.nospam.ware@ntlworld.com> - 2015-06-01 09:07 +0000
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 12:44 +0200
Re: Using Python instead of Bash Laura Creighton <lac@openend.se> - 2015-06-01 17:44 +0200
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 18:44 +0200
Re: Using Python instead of Bash Laura Creighton <lac@openend.se> - 2015-06-01 20:42 +0200
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 21:57 +0200
Re: Using Python instead of Bash Laura Creighton <lac@openend.se> - 2015-06-01 22:42 +0200
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 23:04 +0200
Re: Using Python instead of Bash Cecil Westerhof <Cecil@decebal.nl> - 2015-06-01 11:11 +0200
Re: Using Python instead of Bash Marko Rauhamaa <marko@pacujo.net> - 2015-06-01 12:38 +0300
Re: Using Python instead of Bash Grant Edwards <invalid@invalid.invalid> - 2015-06-01 14:51 +0000
csiph-web