This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsword1cli.py
63 lines (54 loc) · 2.03 KB
/
sword1cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Command line client using SWORD version 1 to push content to
Connexions.
"""
from __future__ import division
import sword1cnx
import os
PARAMS = {
'username': raw_input("Enter Connexions username: "),
'password': raw_input("Enter Connexions password: "),
}
print 'Retrieving service document...'
conn = sword1cnx.Connection("http://cnx.org/sword",
user_name=PARAMS['username'],
user_pass=PARAMS['password'],
download_service_document=True)
swordCollections = sword1cnx.parse_service_document(conn.sd)
formFields = {
"url": None,
"title": None,
"abstract": None,
"keywords": None,
"language": "en",
"keepUrl": True,
"keepTitle": False,
"keepAbstract": False,
"keepKeywords": True,
}
print 'Deposit location:'
for i in range(len(swordCollections)):
print ' %i. %s [%s]'%(i+1, swordCollections[i]['title'],
swordCollections[i]['url'])
formFields['url'] = swordCollections[int(raw_input())-1]['url']
formFields['title'] = raw_input('Title: ').strip()
formFields['abstract'] = raw_input('Summary: ').strip()
formFields['keywords'] = raw_input('Keywords (comma-separated): ')
formFields['language'] = raw_input('Language code: ').strip()
filenames = []
while True:
filenames.append(raw_input('Files to upload (empty to stop): '))
if filenames[-1] == '':
del filenames[-1]
break
# Send zip file to SWORD interface
print 'Posting new module to Connexions...'
conn = sword1cnx.Connection(formFields['url'],
user_name=PARAMS['username'],
user_pass=PARAMS['password'],
download_service_document=False)
response = sword1cnx.upload_multipart(
conn, formFields['title'], formFields['abstract'], formFields['language'],
",".split(formFields['keywords']), [{os.path.basename(filename): open(filename,'rb')} for filename in filenames])
print 'Response:'
print response