def fetchAllTags(self, params): """Fetch all tags, even over multiple requests, present in the library.""" aparams = {'target': 'tags', 'content': 'json', 'limit': 50} aparams.update(params) reqUrl = self.apiRequestString(aparams) while True: response = self._request(reqUrl, 'GET') if response.status_code != 200: return False feed = zotero.Feed(response.text) entries = feed.entries tags = [] for entry in entries: tag = zotero.Tag(entry) tags.append(tag) if 'next' in feed.links: nextUrl = feed.links['next']['href'] #Add the apikey to the reqUrl querystring since feeds leave it out parsedNextUrl = urlparse.urlparse(nextUrl) parsedNextQuery = urlparse.parse_qs(parsedNextUrl.query) parsedNextQuery = self.apiQueryString( parsedNextQuery.update({'key': self._apiKey})) reqUrl = parsedNextUrl['scheme'] + '://' + parsedNextUrl[ 'host'] + parsedNextUrl['path'] + parsedNextQuery else: break return tags
def fetchTrashedItems(self, params={}): """Fetch a set of items marked for deletion.""" fetchedItems = [] aparams = {'target': 'trash', 'content': 'json'} aparams.update(params) reqUrl = self.apiRequestString(aparams) response = self._request(reqUrl) if response.status_code != 200: raise zotero.ZoteroApiError("Error fetching items" + str(response.status_code)) body = response.text feed = zotero.Feed(body) self._lastFeed = feed fetchedItems = self.items.addItemsFromFeed(feed) return fetchedItems
def fetchTags(self, params): """Make a single request to get a set of tags.""" aparams = {'target': 'tags', 'content': 'json', 'limit': 50} aparams.update(params) reqUrl = self.apiRequestString(aparams) response = self._request(reqUrl, 'GET') if response.status_code != 200: return False feed = zotero.Feed(response.text) entries = feed.entries tags = [] for entry in entries: tag = zotero.Tag(entry) tags.append(tag) return tags
def fetchItems(self, params={}): """Fetch a set of items.""" fetchedItems = [] aparams = {'target': 'items', 'content': 'json', 'key': self._apiKey} aparams.update(params) reqUrl = self.apiRequestString(aparams) logging.info(reqUrl) response = self._request(reqUrl) if (response.status_code != 200): raise zotero.ZoteroApiError("Error fetching items. " + str(response.status_code)) body = response.text feed = zotero.Feed(body) self._lastFeed = feed fetchedItems = self.items.addItemsFromFeed(feed) return fetchedItems
def fetchItemBib(self, itemKey, style=None): """Fetch a bibliography entry for an item.""" #TODO:parse correctly and return just bib aparams = {'target': 'item', 'content': 'bib', 'itemKey': itemKey} if style != None: aparams['style'] = style reqUrl = self.apiRequestString(aparams) response = self._request(reqUrl, 'GET') if response.status_code != 200: raise zotero.ZoteroApiError("Error fetching items") body = response.text feed = zotero.Feed(body) if len(feed.entries) == 0: return False else: item = zotero.Item(feed.entries[0]) self.items.addItem(item) return item
def fetchCollections(self, params={}): """Fetch a set of collections.""" aparams = {'target': 'collections', 'content': 'json', 'limit': 100} aparams.update(params) reqUrl = self.apiRequestString(aparams) response = self._request(reqUrl) if response.status_code != 200: raise zotero.ZoteroApiError("Error fetching collections") feed = zotero.Feed(response.text) self._lastFeed = feed addedCollections = self.collections.addCollectionsFromFeed(feed) if 'next' in feed.links: nextUrl = feed.links['next']['href'] parsedNextUrl = urlparse.urlparse(nextUrl) parsedNextQuery = urlparse.parse_qs(parsedNextUrl.query) parsedNextQuery = self.apiQueryString( parsedNextQuery.update({'key': self._apiKey})) reqUrl = parsedNextUrl['scheme'] + '://' + parsedNextUrl[ 'host'] + parsedNextUrl['path'] + parsedNextQuery else: reqUrl = False return addedCollections
def getChildren(self): #short circuit if has item has no children if self.numChildren == 0 or self.parentItemKey != False: return [] config = { 'target': 'children', 'libraryType': self.owningLibrary.libraryType, 'libraryID': self.owningLibrary.libraryID, 'itemKey': self.itemKey, 'content': 'json' } requestUrl = self.owningLibrary.apiRequestString(config) response = self.owningLibrary._request(requestUrl, 'GET') #load response into item objects fetchedItems = [] if responseIsError(response): return False feed = zotero.Feed(response.text) fetchedItems = self.owningLibrary.items.addItemsFromFeed(feed) return fetchedItems