class WOKParser(WOKObject, ServerRequest): def __init__(self, archive, journal=None, author=None, year=None, volume=None, page=None, notes=None, download=False, keywords=None): ServerRequest.__init__(self, ISIServer.REQUEST_PORT, ISIAnswer) self.archive = Archive(archive) self.download = download self.notes = notes self.keywords = keywords self.kwargs = {} if journal: self.kwargs["journal"] = journal if author: self.kwargs["author"] = author if year: self.kwargs["year"] = year if volume: self.kwargs["volume"] = volume if page: self.kwargs["page"] = page self.search = WOKSearch(**self.kwargs) def run(self, method, args=None): cmd = ISIServerCommand(method, args) response = ServerRequest.run(self, cmd) return response def pick_article(self, articles): for article in articles: foundmatch = True for key, value in self.kwargs.items(): if not hasattr(article, key): #don't use this for matching continue match = str(getattr(article, key)) field = WOKField.get(key, value) if not field: field = str(value) if not field == match: foundmatch = False break; if foundmatch: return article def store_article(self): block = self.run("get_text") article = WOKArticle(self.archive, block) if article: article.store(self.download, self.notes, self.keywords) return article def run_citedrefs(self): try: import time void = self.run("isi_search", self.search) articles = self.run("get_articles") title = "" article = self.pick_article(articles) if not article: raise ISIError("Could not find article with given specifications"); self.run("open_article", article.title) nrefs = self.run("open_references") #get all possible refs on this page self.walk_references() #if there are more pages, go through those as well nstart = 31 onclick = 2 while nstart < nrefs: self.run("go_to_next_page", onclick) self.walk_references() nstart += 30 onclick += 1 self.archive.commit() except KeyboardInterrupt, error: raise error except ISIError, error: sys.stderr.write("ERROR: %s\nFailed on block:\n%s\n" % (error, error.block)) raise error