Skip to content

Commit e5bc705

Browse files
committed
Update formatting
1 parent 352b8ca commit e5bc705

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

getBitstreams.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
# begin: argument parsing
1616
parser = argparse.ArgumentParser()
1717

18-
parser.add_argument("-v", "--verbose", action="store_true",
19-
help="increase output verbosity")
18+
parser.add_argument('-v', '--verbose', action='store_true',
19+
help='increase output verbosity')
2020

21-
parser.add_argument("-i", "--handle",
22-
help="handle of the object to retreive. optional - if not provided, the script will ask for input")
21+
parser.add_argument('-i', '--handle',
22+
help='handle of the object to retreive. optional - if not provided, the script will ask for input')
2323

2424
# bitstream formats:
2525
# REM: set number of args
@@ -28,16 +28,16 @@
2828
# '?' == 0 or 1.
2929
# An int is an explicit number of arguments to accept.
3030
parser.add_argument('-f', '--formats', nargs='*',
31-
help="optional list of bitstream formats. will return all formats if not provided")
31+
help='optional list of bitstream formats. will return all formats if not provided')
3232

33-
parser.add_argument("-dl", "--download", action="store_true",
34-
help="download bitstreams (rather than just retreive metadata about them). default: false")
33+
parser.add_argument('-dl', '--download', action='store_true',
34+
help='download bitstreams (rather than just retreive metadata about them). default: false')
3535

36-
parser.add_argument("-rt", "--rtimeout", type=int,
37-
help="response timeout - number of seconds to wait for a response. not a timeout for a download or run of the entire script. default: " + str(response_timeout))
36+
parser.add_argument('-rt', '--rtimeout', type=int,
37+
help='response timeout - number of seconds to wait for a response. not a timeout for a download or run of the entire script. default: ' + str(response_timeout))
3838

39-
parser.add_argument("-l", "--limit", type=int,
40-
help="limit to the number of objects to return in a given request. default = " + str(limit))
39+
parser.add_argument('-l', '--limit', type=int,
40+
help='limit to the number of objects to return in a given request. default = ' + str(limit))
4141

4242
args = parser.parse_args()
4343

@@ -48,21 +48,21 @@
4848
limit = args.limit
4949

5050
if args.verbose:
51-
print "verbosity turned on"
51+
print('verbosity turned on')
5252

5353
if args.handle:
54-
print("retreiving object with handle {}").format(args.handle)
54+
print('retreiving object with handle {}').format(args.handle)
5555

5656
if args.formats:
57-
print('filtering results to the following bitstream formats: %s' % str(args.formats))
57+
print('filtering results to the following bitstream formats: {}').format(args.formats)
5858
else:
59-
print 'returning bitstreams of any format'
59+
print('returning bitstreams of any format')
6060

6161
if args.download:
62-
print "downloading bitstreams"
62+
print('downloading bitstreams')
6363

6464
if args.rtimeout:
65-
print 'response_timeout set to ' + str(response_timeout)
65+
print('response_timeout set to {}').format(response_timeout)
6666

6767
# end: argument parsing
6868

@@ -72,11 +72,11 @@
7272
if secretsVersion != '':
7373
try:
7474
secrets = __import__(secretsVersion)
75-
print 'Editing Production'
75+
print('Accessing Production')
7676
except ImportError:
77-
print 'Editing Stage'
77+
print('Accessing Stage')
7878
else:
79-
print 'Editing Stage'
79+
print('Accessing Stage')
8080

8181
baseURL = secrets.baseURL
8282
email = secrets.email
@@ -136,7 +136,7 @@
136136
f.writerow([fileName]+[itemHandle])
137137

138138
elif dsObject['type'] == 'item':
139-
if args.verbose: print dsObject['type']
139+
if args.verbose: print(dsObject['type'])
140140

141141
itemHandle = dsObject['handle']
142142

@@ -157,7 +157,7 @@
157157
bitstreams = bitstreams.json()
158158
for bitstream in bitstreams:
159159
if args.formats and bitstream['format'] in args.formats or not args.formats:
160-
if args.verbose: print bitstream
160+
if args.verbose: print(bitstream)
161161
sequenceId = str(bitstream['sequenceId'])
162162
fileName = bitstream['name']
163163
fileFormat = bitstream['format']
@@ -172,16 +172,16 @@
172172
for dlBitstream in dlBitstreams:
173173
response = requests.get(baseURL + str(dlBitstream['retrieveLink']), headers=header, cookies=cookies, verify=verify, timeout=response_timeout)
174174
response.raise_for_status() # ensure we notice bad responses
175-
file = open(filePath + dlBitstream['name'], "wb")
175+
file = open(filePath + dlBitstream['name'], 'wb')
176176
file.write(response.content)
177177
file.close()
178178
else:
179-
print 'object is of an invalid type for this script (' + dsObject['type'] + '). please enter the handle of an item or a collection.'
179+
print('object is of an invalid type for this script ({}). please enter the handle of an item or a collection.').format(dsObject['type'])
180180

181181

182182
logout = requests.post(baseURL+'/rest/logout', headers=header, cookies=cookies, verify=verify, timeout=response_timeout)
183183

184184
elapsedTime = time.time() - startTime
185185
m, s = divmod(elapsedTime, 60)
186186
h, m = divmod(m, 60)
187-
print 'Total script run time: ', '%d:%02d:%02d' % (h, m, s)
187+
print('Total script run time: {:01.0f}:{:02.0f}:{:02.0f}').format(h, m, s)

0 commit comments

Comments
 (0)