def insert(self): if self.validate(): extensions.set_max_id(extensions.get_max_id() + 1) self.id = extensions.get_max_id() self.date = datetime.now() data = { "type": self.type, "desc": self.desc, "title": str(self.title), "date": self.date.strftime("%x").replace("/", "-"), "tags": self.tags, "id": self.id, "path": self.path } if self.type == "bookmarks" or self.type == "pocket_bookmarks": data["url"] = self.url # convert to markdown file dataobj = frontmatter.Post(self.content) dataobj.metadata = data self.fullpath = create( frontmatter.dumps(dataobj), str(self.id) + "-" + dataobj["date"] + "-" + dataobj["title"], path=self.path, ) add_to_index(current_app.config['INDEX_NAME'], self) return self.id return False
def insert(self): if self.validate(): self.id = extensions.get_max_id() data = { "type": self.type, "desc": self.desc, "title": str(self.title), "date": self.date.strftime("%x").replace("/", "-"), "tags": self.tags, "id": self.id, "path": self.path } if self.type == "bookmarks" or self.type == "pocket_bookmarks": data["url"] = self.url extensions.set_max_id(self.id + 1) # convert to markdown dataobj = frontmatter.Post(self.content) dataobj.metadata = data create(frontmatter.dumps(dataobj), str(self.id) + "-" + dataobj["date"] + "-" + dataobj["title"], path=self.path) add_to_index(Config.INDEX_NAME, self) return self.id return False
DIRNAME = app.config["APP_PATH"] + "/data/" Path(DIRNAME).mkdir(parents=True, exist_ok=True) if app.config["ELASTICSEARCH_ENABLED"]: elastic_running = subprocess.run("service elasticsearch status", shell=True, stdout=subprocess.DEVNULL).returncode if elastic_running != 0: print("Enter password to enable elasticsearch") subprocess.run("sudo service elasticsearch restart", shell=True) try: print(extensions.elastic_client().indices.create( index=app.config["INDEX_NAME"], body=app.config["ELASTIC_CONF"])) except elasticsearch.ElasticsearchException: print("Elasticsearch index already created") Thread(target=run_watcher).start() app.jinja_options["extensions"].append("jinja2.ext.do") Scss(app) # get max id cur_id = 1 for dataobj in data.get_items(structured=False): cur_id = max(cur_id, dataobj["id"]) extensions.set_max_id(cur_id + 1) from archivy import routes # noqa: