Пример #1
0
    def test_templates(self):
        #zlib = zotero.Library('user', '475425', 'z_public_library', '')

        #create a new item of type book
        newItem = zotero.getTemplateItem('book')
        newItem.set('title', 'This is a book ---')
        newItem.set('abstractNote', 'Created using a zotero python library and the write api')

        self.assertEqual(newItem.get('title'), 'This is a book ---')
        self.assertEqual(newItem.get('abstractNote'), "Created using a zotero python library and the write api")
Пример #2
0
    def test_templates(self):
        #zlib = zotero.Library('user', '475425', 'z_public_library', '')

        #create a new item of type book
        newItem = zotero.getTemplateItem('book')
        newItem.set('title', 'This is a book ---')
        newItem.set('abstractNote',
                    'Created using a zotero python library and the write api')

        self.assertEqual(newItem.get('title'), 'This is a book ---')
        self.assertEqual(
            newItem.get('abstractNote'),
            "Created using a zotero python library and the write api")
Пример #3
0
    def test_modifications(self):
        #log = logging.getLogger("TestItemFunctions.test_modifications")
        item = zotero.getTemplateItem('book')
        item.set('title', 'test book')
        item.addToCollection("ASDF1234")
        item.addToCollection("LKJH0987")

        itemCollections = item.get('collections')
        self.assertTrue('ASDF1234' in itemCollections)
        self.assertTrue('LKJH0987' in itemCollections)
        self.assertEqual(len(itemCollections), 2)

        itemTags = item.get('tags')
        self.assertEqual(len(itemTags), 0)

        item.addTag('Unread')
        item.addTag('purple')
        item.addTag('useless tripe')
        item.removeFromCollection(
            'YUOI8765')  # remove from collection it doesn't belong to
        item.removeFromCollection('ASDF1234')

        itemCollections = item.get('collections')
        itemTags = item.get('tags')
        self.assertEqual(len(itemCollections), 1)
        self.assertEqual(len(itemTags), 3)
        self.assertIn('LKJH0987', itemCollections)
        self.assertNotIn('ASDF1234', itemCollections)
        self.assertIn('Unread', itemTags)
        self.assertIn('purple', itemTags)
        self.assertIn('useless tripe', itemTags)
        self.assertNotIn('Green', itemTags)

        item.removeTag('Unread')
        itemTags = item.get('tags')
        self.assertEqual(len(itemTags), 2)
        self.assertNotIn('Unread', itemTags)
Пример #4
0
    def test_modifications(self):
        #log = logging.getLogger("TestItemFunctions.test_modifications")
        item = zotero.getTemplateItem('book')
        item.set('title', 'test book')
        item.addToCollection("ASDF1234")
        item.addToCollection("LKJH0987")

        itemCollections = item.get('collections')
        self.assertTrue('ASDF1234' in itemCollections)
        self.assertTrue('LKJH0987' in itemCollections)
        self.assertEqual(len(itemCollections), 2)

        itemTags = item.get('tags')
        self.assertEqual(len(itemTags), 0)

        item.addTag('Unread')
        item.addTag('purple')
        item.addTag('useless tripe')
        item.removeFromCollection('YUOI8765')  # remove from collection it doesn't belong to
        item.removeFromCollection('ASDF1234')

        itemCollections = item.get('collections')
        itemTags = item.get('tags')
        self.assertEqual(len(itemCollections), 1)
        self.assertEqual(len(itemTags), 3)
        self.assertIn('LKJH0987', itemCollections)
        self.assertNotIn('ASDF1234', itemCollections)
        self.assertIn('Unread', itemTags)
        self.assertIn('purple', itemTags)
        self.assertIn('useless tripe', itemTags)
        self.assertNotIn('Green', itemTags)

        item.removeTag('Unread')
        itemTags = item.get('tags')
        self.assertEqual(len(itemTags), 2)
        self.assertNotIn('Unread', itemTags)
Пример #5
0
#items = zlib.fetchItemsTop({'limit': 6, 'content': 'json,bib,coins'})
#for item in items:
# print 'Item Type: %s | Key: %s | Title: %s ' % (item.itemType,item.itemKey, item.title)

term = "Blinded_experiment"
url = "https://en.wikipedia.org/wiki/" + term
req = urlopen(url)  #.readlines()
filename = os.getcwd() + "/urlcontent.html"
file = open(filename, "w")
file.write(req.read())

item_type = 'encyclopediaArticle'
item_title = term
abstract_note = wikiparser.getAbstractNote(filename)
#create a new item of type document
newItem = zotero.getTemplateItem(item_type)
#sets the title of the item to Python Lesson Document
newItem.set('title', term)
newItem.set('encyclopediaTitle', term)
#adds a new abstract note
newItem.set('abstractNote', abstract_note)
#sets date to current date
now = datetime.datetime.today().strftime("%Y-%m-%dT%H:%m:%s")
newItem.set('date', now)
newItem.set('accessDate', now)
newItem.set('edition', now)
#sets url
url = wikiparser.getFooterUrl(filename)
print "url is: %s" % url
pageVersionID = url.split("=")[-1]
print pageVersionID
Пример #6
0
digest = m.hexdigest()

finfo = {
    'md5': digest,
    'filename': os.path.basename(filepath),
    'filesize': filestat.st_size,
    'mtime': filestat.
    st_mtime  # the zotero api accepts mtime in ms, os.stat may return seconds depending on operating system
}

#guess mimetype info
finfo['contentType'], finfo['charset'] = mimetypes.guess_type(filepath)
print(finfo)

#create a new item of type book
newItem = zotero.getTemplateItem(args.type)
newItem.set('title', args.title)
createdItem = zlib.createItem(newItem)
if createdItem.writeFailure != False:
    print(createdItem.writeFailure['code'])
    print(createdItem.writeFailure['message'])
    sys.exit(1)

#add child attachment
#create attachment item
logging.info("Calling createAttachmentItem")
attachmentItem = zlib.createAttachmentItem(createdItem,
                                           {'filename': finfo['filename']})
if attachmentItem.writeFailure != False:
    print(attachmentItem.writeFailure)
    print(attachmentItem.writeFailure['code'])
Пример #7
0
m = hashlib.md5()
m.update(nfdata)
digest = m.hexdigest()

finfo = {'md5': digest,
         'filename': os.path.basename(filepath),
         'filesize': filestat.st_size,
         'mtime': filestat.st_mtime  # the zotero api accepts mtime in ms, os.stat may return seconds depending on operating system
         }

#guess mimetype info
finfo['contentType'], finfo['charset'] = mimetypes.guess_type(filepath)
print(finfo)

#create a new item of type book
newItem = zotero.getTemplateItem(args.type)
newItem.set('title', args.title)
createdItem = zlib.createItem(newItem)
if createdItem.writeFailure != False:
    print("Created item has non-false writeFailure")
    print(createdItem.writeFailure['code'])
    print(createdItem.writeFailure['message'])
    sys.exit(1)

#add child attachment
#create attachment item
logging.info("Calling createAttachmentItem")
attachmentItem = zlib.createAttachmentItem(createdItem, {'filename': finfo['filename']})
if attachmentItem.writeFailure != False:
    print(attachmentItem.writeFailure)
    print(attachmentItem.writeFailure['code'])
Пример #8
0
#!/usr/bin/python

import sys
sys.path.append('../lib/py')
import json
from libZotero import zotero

creds = json.loads(open('./user_writing_config.json').read())  # library credentials
print(creds)
zlib = zotero.Library(creds['libraryType'], creds['libraryID'], creds['librarySlug'], creds['apiKey'])

#create a new item of type book
newItem = zotero.getTemplateItem('book')
newItem.set('title', 'This is a book ---')
newItem.set('abstractNote', 'Created using a zotero php library and the write api')
createItemResponse = zlib.createItem(newItem)
print(createItemResponse)
if createItemResponse.status_code != 201:
    print(createItemResponse.status_code)
    print(createItemResponse.text)
    sys.exit(1)
else:
    #load the item into the library so it is included and has the itemKey and etag
    #and anything else the api populates that we didn't set in our item
    createItemFeed = zotero.Feed(createItemResponse.text)
    createdItem = zlib.items.addItemsFromFeed(createItemFeed)
    createdItem = createdItem[0]
    print("Item created")
existingItem = zotero.Item(createItemResponse.text)

#add child note