Added optparse -> --min and --max for specifying range
This commit is contained in:
parent
c5f82a156b
commit
1ba3c75714
1 changed files with 24 additions and 10 deletions
34
rfpquery.py
34
rfpquery.py
|
@ -1,21 +1,35 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# Author: Stefan Ritter <xeno@thehappy.de>
|
||||
# Description: Query Debian WNPP Page (RFP)
|
||||
|
||||
import urllib2, sys, re
|
||||
from optparse import OptionParser
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print 'Syntax:', sys.argv[0], '[max_days_old]'
|
||||
sys.exit()
|
||||
# Parse commandline arguments
|
||||
parser = OptionParser()
|
||||
parser.add_option('--min', dest='min_days_old', type="int", help='Minimum age of reports (in days)')
|
||||
parser.add_option('--max', dest='max_days_old', type="int", help='Maximum age of reports (in days)')
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
try:
|
||||
max_days_old = int(sys.argv[1])
|
||||
except:
|
||||
print 'Not an integer!'
|
||||
sys.exit()
|
||||
if not options.min_days_old and not options.max_days_old:
|
||||
parser.error('You have to give at least one of --min or --max')
|
||||
sys.exit
|
||||
|
||||
if not options.min_days_old: options.min_days_old = 0
|
||||
if not options.max_days_old: options.max_days_old = 9999
|
||||
|
||||
# Here we go...
|
||||
print 'Output reports that are older then', options.min_days_old, 'days and younger then', options.max_days_old, 'days:\n'
|
||||
|
||||
reports = []
|
||||
item = []
|
||||
|
||||
rfpurl = urllib2.urlopen('http://www.debian.org/devel/wnpp/requested')
|
||||
|
||||
for line in rfpurl:
|
||||
|
@ -44,5 +58,5 @@ for line in rfpurl:
|
|||
item = []
|
||||
|
||||
for entry in reports:
|
||||
if int(entry[2]) <= max_days_old:
|
||||
if int(entry[2]) <= options.max_days_old and int(entry[2]) >= options.min_days_old:
|
||||
print entry[1] + ': ' + entry[2] + ' days old (' + entry[0] + ')'
|
||||
|
|
Loading…
Reference in a new issue