예제 #1
0
 def init_database():
     if Path.is_file(Path.db_path):
         DB.set_conn(sqlite3.connect(Path.db_path))
     else:
         DB.set_conn(sqlite3.connect(Path.db_path))
         with open(Path.sql_path) as sql_script:
             DB.cursor.executescript(sql_script.read())
         DB.commit()
예제 #2
0
 def init_database():
     if Path.is_file(Path.db_path):
         DB.set_conn(sqlite3.connect(Path.db_path))
     else:
         DB.set_conn(sqlite3.connect(Path.db_path))
         with open(Path.sql_path) as sql_script:
             DB.cursor.executescript(sql_script.read())
         DB.commit()
예제 #3
0
파일: db.py 프로젝트: HiltonWei/zhihu
 def getAnswerContentFromFile( answertmp = {}):
     if not answertmp:
         return
     filepath_name = Ans2File.filepath(answertmp)
     if Path.is_file(filepath_name):
         with open(filepath_name, 'r') as f:
             fileContent = f.read()
             answertmp['content'] = fileContent
     return
예제 #4
0
 def init_database():
     if Path.is_file(Path.db_path):
         Debug.logger.debug(u"Connect to the database...")
         Debug.logger.debug(u"db_path: " + str(Path.db_path))
         DB.set_conn(sqlite3.connect(Path.db_path))
     else:
         Debug.logger.debug(u"Create db file...")
         DB.set_conn(sqlite3.connect(Path.db_path))
         with open(Path.sql_path) as sql_script:
             DB.cursor.executescript(sql_script.read())
         DB.commit()
예제 #5
0
파일: db.py 프로젝트: HiltonWei/zhihu
    def svContent2File( filepath_name , contentInHttp):
        contentBefore=''
        if Path.is_file(filepath_name):
            with open(filepath_name ,'r') as f:
                contentBefore = f.read()

        def calcContent(contentBefore ,contentSave):#计算内容 是否保存
            strContentSave = contentSave
            contentBefore = unicode(contentBefore, errors='ignore')
            if (contentSave.find(contentBefore[10:]) == -1):
                strContentSave += '\n -----------------------------------------答案更新分割线------------------\n'
                strContentSave += contentBefore
            return strContentSave
            
        content2SV = calcContent(contentBefore , contentInHttp)
        with open(filepath_name ,'w') as f:
            f.write(content2SV)
        return
예제 #6
0
파일: db.py 프로젝트: HiltonWei/zhihu
    def addFileSave(answertmp={}):
        save_content = hashlib.md5(answertmp['content']).hexdigest()
        filepath_name = Ans2File.filepath(answertmp)

        def isUpdateContent( save_content ,questionID , answerID):#是否更答案文本内容
            answerHref = 'http://www.zhihu.com/question/{0}/answer/{1}'.format(questionID, answerID)
            Var = DB.cursor.execute(
                    "select content from Answer  where href = ?", (answerHref,)).fetchone()
            if not Var:
                Debug.logger.debug(u'读答案md5失败')
                return False #初始为空 则默认插入
            return Var[0] == save_content

        bsaved = isUpdateContent(save_content , answertmp['question_id'] , answertmp['answer_id'])
        if not Path.is_file(filepath_name):
            bsaved = False#数据库中有,文件没有
        if not bsaved :
            Ans2File.svContent2File(filepath_name , answertmp['content'])
        answertmp['content'] = str(save_content)
        return
예제 #7
0
파일: main.py 프로젝트: zhejia/ZhihuHelp
    def start(self):
        #   检查更新
        self.check_update()

        #   登录
        login = Login()
        zhihu_client = login.get_login_client()
        Worker.set_zhihu_client(zhihu_client)

        Debug.logger.info(u"开始读取ReadList.txt设置信息")

        if not Path.is_file(u'./ReadList.txt'):
            #  当ReadList不存在的时候自动创建之
            with open(u'./ReadList.txt', u'w') as read_list:
                read_list.close()
            print Debug.logger.info(u"ReadList.txt 内容为空,自动退出")
            return
        book_counter = self.read_list()

        Debug.logger.info(u"所有书籍制作完成。")
        Debug.logger.info(u"本次共制作书籍{0}本".format(book_counter))
        Debug.logger.info(u"感谢您的使用")
        Debug.logger.info(u"点按任意键退出")
        return