def retrieve(self, keywords): savepath, kwpath = self.savepath, self.kwpath path = self.query(keywords, kwpath) for i, doc in enumerate(path): if not doc: oldname = os.path.join(config.unMatch_path, config.unMatch_name) newname = os.path.join(savepath, str(i) + '+' + config.unMatch_name) FileUtil.copyfile(oldname, newname) elif len(doc) > 1: filepath = os.path.join(savepath, str(i)) if not os.path.exists(filepath): os.mkdir(filepath) for d in doc: name = d.get('title') oldname = d.get('path') newname = os.path.join(filepath, str(i) + '+' + name) FileUtil.copyfile(oldname, newname) else: name = doc[0].get('title') oldname = doc[0].get('path') newname = os.path.join(savepath, str(i) + '+' + name) FileUtil.copyfile(oldname, newname) return path