Example #1
0
    def __init__(self, args, auth):
        folder = BibFolder(folderurl=args.folderurl, decode_output=False,
                           mimetype=args.mimetype, **auth)
        simula_author_usernames = args.simula_author_username or []
        if args.mine:
            simula_author_usernames.append(auth['username'])

        paramcount = 0
        for param in (simula_author_usernames, args.author_name, args.search, args.itemid):
            if param:
                paramcount += 1
            if paramcount > 1:
                raise SystemExit('Supplying more than one of (--simula_author_username/--mine), --author_name, --search or --itemid makes no sense, since only the first one is used in the liste order.')

        response = folder.search(simula_author_usernames=simula_author_usernames,
                                 author_names=args.author_name,
                                 search=args.search,
                                 itemids=args.itemid)
        print response
auth = dict(username='******', password='******')
folder = BibFolder(decode_output=True, **auth)

# Add as many items as you like to this list. We only use a single item here
# (we used example.py to create it).
items = [{'portal_type': 'ArticleReference',
          'attributes': {'id': 'grandma-example',
                   'title': 'Super bulk updated example'}}]


# Lets start with getting the current values for our items,
# just to have values to compare with when asking the 
# user to confirm the changes (below)
itemids = [item['attributes']['id'] for item in items]
current_values = folder.search(itemids=itemids)
#pprint(current_values) # pretty-print response


# Then pretend to update to get the changes that will be applied when we update
# for real
pretend_response = folder.bulk_update(pretend=True,
                                      items=items)
#pprint(pretend_response) # pretty-print response


# Ask the user to confirm before bulk updating
print 'Are you sure you want to make the following changes:'
print create_diff(current_values['items'], pretend_response['items'])
if raw_input('Confirm changes (y|N): ') == 'y':
    response = folder.bulk_update(items=items)
Example #3
0
exampleitemid = auth['username'] + '-example'



##################################################
# Work with the folder API
# - search/list
# - create new items in the folder
# - bulk update (update many items in one request)
##################################################

folder = BibFolder(decode_output=True, **auth)

# We can use search() to get bibliography items. If we do not use any
# parameters, ALL simula publications are returned
search_reponse = folder.search(simula_author_usernames=['griff', 'hpl'])
print 'Search for {!r}:'.format(search_reponse['parameters'])
print '    returned {0} items'.format(len(search_reponse['items']))
print '    parameters as they appear to the server:'
print '       ', repr(search_reponse['parameters'])
#pprint(search_reponse) # Pretty-print the entire response


# We can use create_item() to create a new item in the folder
create_response = folder.create_item(exampleitemid, 'ArticleReference',
                                     attributes={'title': 'Example',
                                                 'publication_year': '2012',
                                                 'simula_pdf_file': create_pdf()})
print 'Created {title}'.format(**create_response['attributes'])
print '   View it here: {url}'.format(**create_response)
#pprint(create_response) # Pretty-print the entire response