def annalysisChapterSourceInfo(self, raw):
        Log.info("annalysisChapterSourceInfo  [%s] " % (raw))
        ##<dd> <a style="" href="/167_167729/8536723.html">23 樱花的忍者</a></dd>
        if '<dd> <a' in raw:
            ####<dd> <a style="" href="/167_167729/8536723.html">23 樱花的忍者</a></dd>
            #<dd> <a style=""
            #/167_167729/8536723.html">23 樱花的忍者</a></dd>
            tmp = raw.split('href="')
            ##/167_167729/8536723.html">23 樱花的忍者</a></dd>
            #/167_167729/8536723.html
            # 23 樱花的忍者</a></dd>
            tmp1 = tmp[1].split('">')
            link = tmp1[0]
            titleName = tmp1[1].replace('</a></dd>', '')
            chapterSourceUrl = self.url + link
            chapterSourceUrl = chapterSourceUrl.replace('//', '/')
            chapterSourceUrl = chapterSourceUrl.replace(':/', '://')
            chapterSourceInfo = chapterSourceUrl + systemCode.fileContentSplit + titleName

            Log.info(chapterSourceInfo)

            fileTools = FileTools(systemCode.baseFolder + u'/SourceUrlFile/' +
                                  self.novelNo + u'/' +
                                  systemCode.oneNovelAllChaptersSourceInfo)
            allChaptersSource = fileTools.readFile()
            # if allNovels != "":
            if chapterSourceInfo not in allChaptersSource:
                fileTools1 = FileTools(
                    systemCode.baseFolder + u'/SourceUrlFile/' + self.novelNo +
                    u'/' + systemCode.oneNovelAllChaptersSourceInfo)
                fileTools1.fileWriteAppend(chapterSourceInfo)
            else:
                Log.info("annalysisChapterSourceInfo [%s]  is already exist!" %
                         (chapterSourceInfo))
 def analysisChapterInfo(self, no='', title='', chapterSourceUrl=''):
     Log.info("analysisChapterInfo start")
     fileTools = FileTools(self.localFolder + '/' +
                           systemCode.oneNovelAllChaptersInfoFile)
     split = systemCode.fileContentSplit
     info = no + split + title + split + chapterSourceUrl + '\r\n'
     fileTools.fileWriteAppend(info)
     Log.info("analysisChapterInfo end")
    def analysisNovelInfo(self, content, novel):
        Log.info("analysisNovelInfo start")
        split= str(systemCode.fileContentSplit)
        novelNo=novel.novelNo()
        name = ''
        url = novel.novelUrl()
        author = ''
        imageurl = ''
        lashUpdateTime = ''
        lastUpdateChapter = ''
        novelinfo = ''
        contentList = content.decode('utf-8').split('\r\n')
        for index, raw in enumerate(contentList):
            if '<h1>' in raw :
                name = raw.split('<h1>')[1].replace('</h1>', '')
            if '<p>作&nbsp;&nbsp;者:' in raw :
                author = raw.split('者:')[1].replace('</p>', '')
            if '<img alt' in raw :
                imageurl = systemCode.baseUrl+raw.split('src="')[1].split('" width')[0]
            if '<p>最后更新:' in raw :
                lashUpdateTime = raw.split('更新:')[1].replace('</p>', '')
            if ' <p>最新更新:' in raw :
                lastUpdateChapter = raw.split('">')[1].replace('</a></p>', '')
        novelinfo = str(novelNo)+split+str(name)+ split +str(url)+ split +str(author)+ split \
                    +str(imageurl)+ split +str(lashUpdateTime)+ split +str(lastUpdateChapter)
        Log.info(novelinfo)

        fileTools = FileTools(systemCode.baseFolder+ u'/SourceUrlFile/'+systemCode.allNovelsNameInfoFile)
        allNovels = fileTools.readFile()
        # if allNovels != "":
        if novelNo not in allNovels:
            fileTools1 = FileTools(systemCode.baseFolder+ u'/SourceUrlFile/'+systemCode.allNovelsNameInfoFile)
            fileTools1.fileWriteAppend(novelinfo)
        else:
            Log.info("analysisNovelInfo [%s]  is already exist!"%(novelinfo))
            # allNovelsList = allNovels.split('\r\n')
            # for index,raw in enumerate(allNovelsList):
            #     if name in raw:
            #         tmpAllNovels += novelinfo+'\r\n';
            #     else:
            #         tmpAllNovels += raw+'\r\n';
        # else:
        tmpAllNovels = novelinfo+'\r\n';

        Log.info("analysisNovelInfo end")
    def userGetChapter(self, novelNo, chapterNo, chapterTitle, id):
        Log.info("userGetChapter novelNo [ %s ] chapterNo [ %s ] "
                 " chapterTitle [ %s ]  user id [%s]" %
                 (novelNo, chapterNo, chapterTitle, id))
        fileTools = FileTools(systemCode.baseFolder + u'/SourceUrlFile/' +
                              novelNo + u'/' + chapterNo + chapterTitle +
                              u'.n')
        content = fileTools.readFile()

        split = systemCode.fileContentSplit
        userReadInfo = id + split + novelNo + split + chapterNo + split + chapterTitle
        fileTools = FileTools(systemCode.userReadNovelFile)
        readInfo = fileTools.readFile()
        if userReadInfo not in readInfo:
            fileTools = FileTools(systemCode.userReadNovelFile)
            fileTools.fileWriteAppend(userReadInfo)
        result = ResponseChapterContent(content)
        return ObjectJson.convert_to_dict(result)
 def addOneNovel(self, novelNo):
     ok = False
     Log.info("addOneNovel novelNo [ %s ] " % (novelNo))
     url = systemCode.baseUrl + u'/' + novelNo + '/'
     urlTools = UrlTools(url)
     header, content = urlTools.getUrlContent()
     if '笔下文学' in content:
         fileTools = FileTools(systemCode.downloadNovelsInfoFile)
         content = fileTools.readFile()
         if novelNo not in content:
             fileTools = FileTools(systemCode.downloadNovelsInfoFile)
             fileTools.fileWriteAppend(novelNo + u'\r\n')
         Log.info("addOneNovel novelNo [ %s ] success " % (novelNo))
         ok = True
     else:
         Log.info(
             "addOneNovel novelNo [ %s ] failed  maybe not 笔下文学 or novelNo is error"
             % (novelNo))
     return ok
 def registry(self, username, password, org):
     if org != 'Super':
         return systemCode.registryErrorOrg
     elif username == '' or password == '':
         return systemCode.registryErrorNameOrPwd
     else:
         fileTools = FileTools(systemCode.userInfoFile)
         allUser = fileTools.readFile()
         if username in allUser:
             return systemCode.registryErrorAlready
         else:
             split = systemCode.fileContentSplit
             millis = int(round(time.time() * 100000))
             rand = random.randint(1, 1000)
             id = millis + rand
             user = str(
                 id
             ) + split + username + split + password + split + org + u'\r\n'
             fileTools = FileTools(systemCode.userInfoFile)
             fileTools.fileWriteAppend(user)
             user = ResponseUser(id, username, password, org)
             return ObjectJson.convert_to_dict(user)
 def error1(self, error=''):
     file = FileTools(logFileName)
     file.fileWriteAppend("Error %s "%(ctime())+error)
 def deg1(self, debug=''):
     file = FileTools(logFileName)
     file.fileWriteAppend("Debug %s "%(ctime())+debug)
 def info1(self, info=''):
     file = FileTools(logFileName)
     file.fileWriteAppend("Info %s "%(ctime())+info)
 def waring(waring=''):
     file = FileTools(logFileName)
     file.fileWriteAppend("Error %s "%(ctime())+waring)