Skip to content

Commit 32be555

Browse files
authored
Merge pull request #4 from MITLibraries/code-refactoring
Code refactoring
2 parents 767e97f + 876203a commit 32be555

File tree

53 files changed

+358
-256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+358
-256
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ $RECYCLE.BIN/
4545
Network Trash Folder
4646
Temporary Items
4747
.apdisk
48-
secrets.py
49-
secretsProd.py
48+
secrets*
5049
*.pyc
5150
data/*
5251
local/*

Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ verify_ssl = true
77

88
[packages]
99
requests = "*"
10+
click = "*"
11+
attrs = "*"
1012

1113
[requires]
1214
python_version = "3.7"

Pipfile.lock

Lines changed: 26 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

addKeyValuePairOnHandleCSV.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
session = requests.post(baseURL + '/rest/login', headers=header,
2525
verify=verify, params=data).cookies['JSESSIONID']
2626
cookies = {'JSESSIONID': session}
27-
headerFileUpload = {'accept': 'application/json'}
27+
2828

2929
status = requests.get(baseURL + '/rest/status', headers=header,
3030
cookies=cookies, verify=verify).json()

addKeyValuePairToCollection.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
skipColl = secrets.skipColl
1919

2020
parser = argparse.ArgumentParser()
21-
parser.add_argument('-k', '--key', help='the key to be added. optional - if \
22-
not provided, the script will ask for input')
23-
parser.add_argument('-v', '--value', help='the value to be added. optional - \
24-
if not provided, the script will ask for input')
25-
parser.add_argument('-l', '--language', help='the language tag to be added. \
26-
optional - if not provided, the script will ask for input')
27-
parser.add_argument('-i', '--handle', help='handle of the collection. optional \
28-
- if not provided, the script will ask for input')
21+
parser.add_argument('-k', '--key', help='the key to be added. optional - if '
22+
'not provided, the script will ask for input')
23+
parser.add_argument('-v', '--value', help='the value to be added. optional - '
24+
'if not provided, the script will ask for input')
25+
parser.add_argument('-l', '--language', help='the language tag to be added. '
26+
'optional - if not provided, the script will ask for '
27+
'input')
28+
parser.add_argument('-i', '--handle', help='handle of the collection. '
29+
'optional - if not provided, the script will ask for '
30+
'input')
2931
args = parser.parse_args()
3032

3133
if args.key:
@@ -53,7 +55,7 @@
5355
session = requests.post(baseURL + '/rest/login', headers=header,
5456
verify=verify, params=data).cookies['JSESSIONID']
5557
cookies = {'JSESSIONID': session}
56-
headerFileUpload = {'accept': 'application/json'}
58+
5759

5860
status = requests.get(baseURL + '/rest/status', headers=header,
5961
cookies=cookies, verify=verify).json()
@@ -105,8 +107,9 @@
105107
addedMetadataElement['value'] = addedValue
106108
addedMetadataElement['language'] = addedLanguage
107109
itemMetadataProcessed.append(addedMetadataElement)
108-
provNote = '\'' + addedKey + ': ' + addedValue + '\' was added through a \
109-
batch process on ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S') + '.'
110+
provNote = ('\'' + addedKey + ': ' + addedValue + '\' was added through a '
111+
+ 'batch process on '
112+
+ datetime.now().strftime('%Y-%m-%d %H:%M:%S') + '.')
110113
provNoteElement = {}
111114
provNoteElement['key'] = 'dc.description.provenance'
112115
provNoteElement['value'] = provNote

addKeyValuePairToCommunity.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
skipColl = secrets.skipColl
1919

2020
parser = argparse.ArgumentParser()
21-
parser.add_argument('-k', '--key', help='the key to be added. optional - if \
22-
not provided, the script will ask for input')
23-
parser.add_argument('-v', '--value', help='the value to be added. optional - \
24-
if not provided, the script will ask for input')
25-
parser.add_argument('-l', '--language', help='the language tag to be added. \
26-
optional - if not provided, the script will ask for input')
27-
parser.add_argument('-i', '--handle', help='handle of the community. optional \
28-
- if not provided, the script will ask for input')
21+
parser.add_argument('-k', '--key', help='the key to be added. optional - if '
22+
'not provided, the script will ask for input')
23+
parser.add_argument('-v', '--value', help='the value to be added. optional - '
24+
'if not provided, the script will ask for input')
25+
parser.add_argument('-l', '--language', help='the language tag to be added. '
26+
'optional - if not provided, the script will ask for '
27+
'input')
28+
parser.add_argument('-i', '--handle', help='handle of the community. optional '
29+
'- if not provided, the script will ask for input')
2930
args = parser.parse_args()
3031

3132
if args.key:
@@ -53,7 +54,7 @@
5354
session = requests.post(baseURL + '/rest/login', headers=header, verify=verify,
5455
params=data).cookies['JSESSIONID']
5556
cookies = {'JSESSIONID': session}
56-
headerFileUpload = {'accept': 'application/json'}
57+
5758

5859
status = requests.get(baseURL + '/rest/status', headers=header,
5960
cookies=cookies, verify=verify).json()

addNewItemsToCollection.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
skipColl = secrets.skipColl
2121

2222
parser = argparse.ArgumentParser()
23-
parser.add_argument('-d', '--directory', help='the directory of files to be \
24-
ingested. optional - if not provided, the script will ask for input')
25-
parser.add_argument('-e', '--fileExtension', help='the extension of files to \
26-
be ingested. optional - if not provided, the script will ask for input')
27-
parser.add_argument('-i', '--handle', help='handle of the object to retreive. \
28-
optional - if not provided, the script will ask for input')
23+
parser.add_argument('-d', '--directory', help='the directory of files to be '
24+
'ingested. optional - if not provided, the script will '
25+
'ask for input')
26+
parser.add_argument('-e', '--fileExtension', help='the extension of files to '
27+
'be ingested. optional - if not provided, the script will '
28+
'ask for input')
29+
parser.add_argument('-i', '--handle', help='handle of the object to retreive. '
30+
'optional - if not provided, the script will ask for '
31+
'input')
2932
args = parser.parse_args()
3033

3134
if args.directory:
@@ -68,11 +71,12 @@
6871
session = requests.post(baseURL + '/rest/login', headers=header, verify=verify,
6972
params=data).cookies['JSESSIONID']
7073
cookies = {'JSESSIONID': session}
71-
headerFileUpload = {'accept': 'application/json'}
74+
7275
status = requests.get(baseURL + '/rest/status', headers=header,
7376
cookies=cookies, verify=verify).json()
7477
userFullName = status['fullname']
7578
print('authenticated', userFullName)
79+
headerFileUpload = {'accept': 'application/json'}
7680

7781
# Get collection ID
7882
endpoint = baseURL + '/rest/handle/' + handle

checkInventory.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ def main():
99
parser = argparse.ArgumentParser()
1010

1111
parser.add_argument('-i', '--inventory', required=True,
12-
help='csv file containing the inventory. the path, if \
13-
given, can be absolute or relative to this script')
12+
help='csv file containing the inventory. the path, if '
13+
'given, can be absolute or relative to this script')
1414

1515
parser.add_argument('-d', '--dataDir',
16-
help='directory containing the data. if omitted, data \
17-
will be read from the directory containing the \
18-
inventory file')
16+
help='directory containing the data. if omitted, data '
17+
'will be read from the directory containing the '
18+
'inventory file')
1919

2020
parser.add_argument('-f', '--field',
21-
help='field in the csv containing the fileNames. \
22-
default: name')
21+
help='field in the csv containing the fileNames. '
22+
'default: name')
2323

2424
parser.add_argument('-v', '--verbose', action='store_true',
2525
help='increase output verbosity')

compareTwoKeysInCommunity.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
skipColl = secrets.skipColl
1717

1818
parser = argparse.ArgumentParser()
19-
parser.add_argument('-1', '--key', help='the first key to be output. \
20-
optional - if not provided, the script will ask for input')
21-
parser.add_argument('-2', '--key2', help='the second key to be output. \
22-
optional - if not provided, the script will ask for input')
23-
parser.add_argument('-i', '--handle', help='handle of the community to \
24-
retreive. optional - if not provided, the script will ask for input')
19+
parser.add_argument('-1', '--key', help='the first key to be output. '
20+
'optional - if not provided, the script will ask for '
21+
'input')
22+
parser.add_argument('-2', '--key2', help='the second key to be output. '
23+
'optional - if not provided, the script will ask for '
24+
'input')
25+
parser.add_argument('-i', '--handle', help='handle of the community to '
26+
'retreive. optional - if not provided, the script will '
27+
'ask for input')
2528
args = parser.parse_args()
2629

2730
if args.key:
@@ -45,7 +48,7 @@
4548
session = requests.post(baseURL + '/rest/login', headers=header, verify=verify,
4649
params=data).cookies['JSESSIONID']
4750
cookies = {'JSESSIONID': session}
48-
headerFileUpload = {'accept': 'application/json'}
51+
4952

5053
status = requests.get(baseURL + '/rest/status', headers=header,
5154
cookies=cookies, verify=verify).json()

countInitialedNamesByCollection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
session = requests.post(baseURL + '/rest/login', headers=header, verify=verify,
2424
params=data).cookies['JSESSIONID']
2525
cookies = {'JSESSIONID': session}
26-
headerFileUpload = {'accept': 'application/json'}
26+
2727

2828
status = requests.get(baseURL + '/rest/status', headers=header,
2929
cookies=cookies, verify=verify).json()

0 commit comments

Comments
 (0)