Esempio n. 1
0
    def UpdateEvernotebooks(self, enNotebookList: Sequence[Types.Notebook]):
        '''
            更新印象笔记的 笔记本
        '''
        # 创建session对象:
        session = self.DBSession()

        # 清空表
        session.query(ENDBTypes.Notebook).delete()

        for enNotebook in enNotebookList:
            dbNotebook = ENDBTypes.Notebook(
                guid=enNotebook.guid,
                name=enNotebook.name,
                updateSequenceNum=enNotebook.updateSequenceNum,
                defaultNotebook=enNotebook.defaultNotebook,
                serviceCreated=enNotebook.serviceCreated,
                serviceUpdated=enNotebook.serviceUpdated,
                published=enNotebook.published,
                stack=enNotebook.stack,
            )
            session.add(dbNotebook)

        # 提交修改
        session.commit()

        # 关闭数据库
        session.close()
Esempio n. 2
0
    def UpdateYuqueBooks(self, booklist: Sequence[BookSerializer]):
        '''
            更新印象笔记的 笔记本
        '''
        # 创建session对象:
        session = self.DBSession()

        # 清空表
        session.query(YQDBTypes.YuqueBook).delete()

        for book in booklist:
            dbNotebook = YQDBTypes.YuqueBook(
                id=book.id,
                type=book.type,
                slug=book.slug,
                name=book.name,
                namespace=book.namespace,
                user_id=book.user_id,
                description=book.description,
                creator_id=book.creator_id,
                public=book.public,
                likes_count=book.likes_count,
                watches_count=book.watches_count,
                created_at=book.created_at,
                updated_at=book.updated_at,
            )
            session.add(dbNotebook)

        # 提交修改
        session.commit()

        # 关闭数据库
        session.close()

        return
Esempio n. 3
0
    def UpdateYuqueEvernoteBookMap(
            self, bookmapList: Sequence[SNTypes.SystemConfig.SyncBookMap]):
        # 创建session对象:
        session = self.DBSession()

        # 清空原有的对应关系
        session.query(DBOTyping.YuqueEvernoteBookMap).delete()

        for bookmap in bookmapList:
            res = session.query(ENDBTypes.Notebook) \
                .filter(ENDBTypes.Notebook.name == bookmap.evernoteBook).first()
            evernoteNoteBookGuid = res.guid
            res = session.query(YQDBTypes.YuqueBook) \
                .filter(YQDBTypes.YuqueBook.name == bookmap.yuqueBook).first()
            yuqueBookNamespace = res.namespace

            dbmap = DBOTyping.YuqueEvernoteBookMap(
                evernoteNoteBookGuid=evernoteNoteBookGuid,
                yuqueBookNamespace=yuqueBookNamespace,
            )
            session.add(dbmap)

        # 提交修改
        session.commit()

        # 关闭数据库
        session.close()
Esempio n. 4
0
    def SaveEvernoteLocalUSN(self, localUSN: int):
        session = self.DBSession()
        # 更新USN
        session.query(ENDBTypes.SyncState).delete()
        syncState = ENDBTypes.SyncState(updateCount=localUSN)
        session.add(syncState)

        # 提交修改
        session.commit()
        session.close()
Esempio n. 5
0
    def SetEvernoteUploadState(self, noteGuid: str, state: bool):
        '''
            标记文件的上传状态
        '''
        session = self.DBSession()
        session.query(ENDBTypes.Note).filter(
            ENDBTypes.Note.guid == noteGuid).update({"syncToYuque": state})
        session.commit()
        session.close()

        return
Esempio n. 6
0
    def SetEvernoteDownloadState(self, noteGuid: str, state: bool):
        '''
            标记文件的下载状态
        '''
        session = self.DBSession()
        session.query(ENDBTypes.Note).filter(
            ENDBTypes.Note.guid == noteGuid).update({"downloaded": state})
        session.commit()
        session.close()

        return
Esempio n. 7
0
 def mysql_update(self, data):
     """更新数据库中的数据"""
     key = list(data.keys())[0]
     value = list(data.values())[0]
     new_value = value.replace(self.pdf, self.image)
     stmt = 'update {} set {}="{}" where {}="{}";'.format(
         table_name, key, new_value, key, value)
     # print("stmt:", stmt)
     if not self.update_db:
         self.sql_list.append(stmt + os.linesep)
         return
     session.execute(stmt)
     session.commit()
Esempio n. 8
0
    def SaveEvernoteContent(self, noteGuid: str, enml: str, html: str,
                            markdown: str):
        '''
            标记文件已经上传
        '''
        session = self.DBSession()
        session.query(ENDBTypes.Note) \
            .filter(ENDBTypes.Note.guid == noteGuid) \
            .update({"enml": enml,
                     'html': html,
                     'markdown': markdown})
        session.commit()
        session.close()

        return
Esempio n. 9
0
    def InsertEvernoteData(self, noteList: Sequence[Types.Note]):
        if noteList is None:
            return

        session = self.DBSession()

        for note in noteList:
            # 如果是有效数据 才记录到数据库中,不然就删除
            dbNote = ENDBTypes.Note(
                guid=note.guid,
                title=note.title,
                content=note.content,
                # contentHash=note.contentHash,
                contentLength=note.contentLength,
                created=note.created,
                updated=note.updated,
                deleted=note.deleted,
                active=note.active,
                updateSequenceNum=note.updateSequenceNum,
                notebookGuid=note.notebookGuid,
                # tagGuids=note.tagGuids,
                # resources=note.resources,
                # attributes=note.attributes,
                # tagNames=note.tagNames,
                syncToYuque=False,
                downloaded=False)
            # 删除原有的
            session.query(ENDBTypes.Note).filter(
                ENDBTypes.Note.guid == note.guid).delete()

            # 添加新数据
            session.add(dbNote)

            # 更新USN
            session.query(ENDBTypes.SyncState).delete()
            syncState = ENDBTypes.SyncState(updateCount=note.updateSequenceNum)
            session.add(syncState)

        # 提交修改
        session.commit()
        session.close()