티스토리 뷰

<주요 기능>

1. 특정 검색어에 대해 주요 검색엔진(다음, 네이버, 구글)이 제공하는 웹페이지 정보

  • 페이지 주소(URL)
  • 페이지 제목(Title)
  • 페이지 내용(Contents)

 

2. 특정 웹 페이지 내 게시글 중 최신 정보 수집

  • 게시글 주소(URL)
  • 게시글 제목(Title)
  • 게시글 내용(Contents)

 

3. 특정 웹 페이지 내 게시글을 PDF로 저장

 

4. 크롤링 결과를 엑셀(EXCEL)로 저장

 

5. 크롤링 결과를 이메일로 전송

  • 요청이 있는 경우, 저장될 파일을 이메일에 첨부

 

6. 크롤링 결과의 요약문을 카카오톡 메시지로 전송

 

 

 

 


class cArticleCollector:
    ChromeAccess = cChromeAccess()

    def __init__(self):
        pass

    def StartCollection(self, collectionParam):
        date0 = datetime.now()
        datename0 = date0.strftime("%Y-%m-%d")
        nextDate = collectionParam.get('NextDate')
        if nextDate and datename0<nextDate:
            print("Before ", nextDate)
            return None

        SA1 = cServerAccess()
        try:
            userGroup = collectionParam['UserGroup']
            if userGroup == 'UG901':
                AS1 = cArticleSearcher()
                collectedResult = AS1.StartSearch(collectionParam)
            elif userGroup == 'UG801':
                NC1 = cNoticeCollector()
                collectedResult = NC1.StartCollection(collectionParam)
            else:
                print('[UserGroup]', userGroup)
                return None
        
            PP1 = cPostProcessor()
            if not collectedResult: return None
            PP1.TreatPostprocess(collectionParam, collectedResult)
            return None

            period1 = collectionParam.get('Period')
            if not period1: period = 7
            else: period = int(period1)
            date1 = datetime.fromisoformat(datename0)
            date2 = date1 + timedelta(days=period)
            nextDate1 = date2.strftime("%Y-%m-%d")

            SA1.UploadArticles(collectionParam, collectedResult['CollectedArticles'])

            updateInfo = {
                'SNo' : collectionParam['SNo'],
                'UserAddress': collectionParam['UserAddress'],
                'NextDate': nextDate1,
                'LatestStatus': collectedResult['Abstract']
                }
        except:
            updateInfo = {
                'SNo' : collectionParam['SNo'],
                'UserAddress': collectionParam['UserAddress'],
                #'NextDate': nextDate1,
                'LatestStatus': 'None'
                }

        SA1.UpdateCollection(updateInfo)

class cArticleSearcher:
    PortalInfos = {}
    ChromeAccess = cChromeAccess()
    EXECUTABLE_PATH = cConstants.PATH_CHROMEDRIVER
    DEFAULT_REPEATABLE = cConstants.DEFAULT_REPEATABLE_PORTAL
    MARK_TITLE = cConstants.MARK_TITLE
    MARK_LINK = cConstants.MARK_LINK

    IsLogging = cConstants.IsLogging
    IsTesting = cConstants.IsTesting
    Flag_CheckPrevious = False

    CollectedResult = {}
    SheetName = None
    IsFirst = True
    PreviousArticles = None
    Repeatable = -1

    def __init__(self, portalInfos=None):

        if not portalInfos:
            SA1 = cServerAccess()
            params = {
                'UserGroup': 'Portals'
            }
            portalData = SA1.LoadCollections(params)
            self.PortalInfos = {}
            for portal1 in portalData:
                self.PortalInfos[portal1['Keyword']] = json.loads(portal1['TargetInfo'])
        else:
            self.PortalInfos = portalInfos


    def StartSearch(self, searchParams):
        if not searchParams:
            print("[!0] No parameter for searching articles")
            return None
        date0 = datetime.now()
        datename0 = date0.strftime("%Y-%m-%d")
        nextDate = searchParams.get('NextDate')
        if not nextDate:
            nextDate = datename0
        else:
            if nextDate > datename0:
                print('NextDate :', nextDate)
                return None

        self.Params = searchParams

        targetInfos = json.loads(searchParams['TargetInfo'])
        targetNames = targetInfos['PortalNames']
        targetNumber = targetInfos['PortalNumber']
        keywordID = searchParams.get('KeywordID')
        tableName = searchParams.get('Tablename')
        try:
            period = int(searchParams['Period'])
        except:
            period = 7
        try:
            repeatable = searchParams['Repeatable']
        except:
            repeatable = self.DEFAULT_REPEATABLE
        keyWord = searchParams['Keyword']
        userAddress = searchParams['UserAddress']
        if keywordID:
            req1 = {
                'KeywordID' : keywordID,
                'Tablename': tableName,
                'ArticleNumber': 200
            }
            SA1 = cServerAccess()
            try:
                self.PreviousArticles = SA1.LoadArticles(req1)
            except:
                print("No previous articles")
                self.PreviousArticles = None
            if not self.PreviousArticles: repeatable=-1
        else:
            print("[!] No KeywordID")

        datename1 = date0.strftime("%Y-%m-%d %H:%M:%S")
        datename2 = date0.strftime("%Y%m%d%H%M%S")
        date1 = datetime.fromisoformat(nextDate)
        date2 = date1 + timedelta(days=period)
        nextDate1 = date2.strftime("%Y-%m-%d")

        collectionAbstract = '[Abstract]'
        articleNo = 0
        overlappedNo = 0
        targetPortals = ''
        for target1 in targetNames:
            searchParams['PortalName'] = target1
            if target1 == 'NaverAPI':
                naverAPI = cNaverAPI_Search(self.PreviousArticles)
                searchedInfos = naverAPI.StartSearch_News(searchParams)
            elif target1 == 'NaverNews':
                print ('naver news ...')
            else:
                try:
                    searchedInfos = self.SearchEachPortal(searchParams, self.PortalInfos[target1])
                except:
                    print('[???] SearchEachPortal() with', target1)
                    continue
            targetPortals += target1
            if searchedInfos:
                self.AddList(searchedInfos)
                collectionAbstract += searchedInfos['Abstract']+ '; '
            else:
                collectionAbstract += target1+ ' - NONE; ' 

        print('[Abstract]', collectionAbstract)

        collectionOverview = {
            'address': '[Overview]'+ ' @ ' + datename1,
            'title': keyWord + ' with ' + targetPortals,
            'body': collectionAbstract
        }
        print("Uploaded article number : ", len(self.CollectedResult['CollectedArticles']))
        self.CollectedResult['CollectedArticles'].insert(0, collectionOverview)
        self.CollectedResult['Abstract'] = collectionAbstract

        #SA1.UploadArticles(searchParams, CollectedResult['CollectedArticles'])

        return self.CollectedResult

    def SearchEachPortal(self, searchParam, portalInfo):

        keyWord = searchParam['Keyword']
        repeatable = searchParam.get('Repeatable')
        targetURL = portalInfo['T_URL']
        classQuery = portalInfo['c_Qy']
        classLC = portalInfo['c_LC']
        classIC = portalInfo['c_IC']
        classLP = portalInfo['c_LP']
        classIP = portalInfo['c_IP']
        targetInfo = json.loads(searchParam['TargetInfo'])
        portalName = searchParam['PortalName']
        try:
            listNumber = int(targetInfo['ListNumber'])
        except:
            listNumber = 2

        print("Searing portal ...", portalName)
        flag_CheckPrevious = targetInfo.get('CheckPrevious')
        if flag_CheckPrevious:
            self.Flag_CheckPrevious = True

        date0 = datetime.now()
        datename1 = date0.strftime("%Y-%m-%d %H:%M:%S")
        collectedResult = {
            'PortalName': portalName,
            'Date': datename1,
            'Keyword': keyWord,
            'RequestListNumber': listNumber,
            'CollectedListNumber': 0,
            'CollectedArticleNumber': 0,
            'CollectedArticles': None
        }
        print("Arranging lists ...")
        webDriver = webdriver.Chrome(executable_path=self.EXECUTABLE_PATH)
        webDriver.get(targetURL)
        elem1 = webDriver.find_element_by_css_selector(classQuery)
        elem1.clear()
        elem1.send_keys(keyWord)
        elem1.send_keys(Keys.RETURN)
#            self.CheckAdditionalAction(webDriver, portalName) #******************************
#*****
        if portalName == 'DaumNews':
            if self.IsLogging: print('Portal', portalName)
            url11 = webDriver.current_url
            url11 = url11.replace('w=tot', 'w=news')
            webDriver.get(url11)
#*****
        webDriver.implicitly_wait(5)

        start = datetime.now()
        end = start + timedelta(seconds=listNumber)
        while True:
            webDriver.execute_script('window.scrollTo(0, document.body.scrollHeight);')
            time.sleep(1)
            if datetime.now() > end:
                break

        e_Address = portalInfo.get('E_Address')
        e_Body = targetInfo.get('E_Body')
        e_Title = targetInfo.get('E_Title')
        timeoutID = portalInfo.get('TimeoutID')
        repeatCount = 0
        articleNo = 0
        listNo = 0
        overlappedNo = 0
        while True:
            repeatCount+=1
            if repeatCount > 10: break
            if listNo >= listNumber: break

            if classIC != '-':
                item0 = webDriver.find_element_by_css_selector(classIC)
                if self.IsLogging: print('[21]', classIC)
                if classIP.startswith('.'):
                    items = item0.find_elements_by_css_selector(classIP)
                else:
                    items = item0.find_elements_by_tag_name(classIP)
                if self.IsLogging: print('[22]', classIP)
            else:
                if self.IsLogging: print('[23]', classIC)
                if classIP.startswith('.'):
                    items = webDriver.find_elements_by_css_selector(classIP)
                else:
                    items = webDriver.find_elements_by_tag_name(classIP)
                if self.IsLogging: print('[24]', classIP)

            print('Collecting items ... ')
            count1 = 1
            collectedArticles = []

            articleCount = 0
            for item1 in items:
                if self.IsTesting: 
                    if articleCount > 2: break
                if self.IsLogging: print(item1.text)
                if len(item1.text) < 10: continue
                try:
                    itemTag = item1.find_element_by_tag_name('a')
                    linkAddress1 = itemTag.get_attribute('href')
                    itemText = itemTag.text
                except:
                    linkAddress1 = item1.get_attribute('href')
                    itemText = item1.text
                if len(linkAddress1) < 10: continue
                articleCount += 1
                indicator1 = str(listNo)+'-'+ str(articleNo)
                print('[', portalName, '-', indicator1, ']', linkAddress1)

                if (not e_Address) and (not e_Title) and (not e_Body):
                    rsp1['title'] = itemText
                    rsp1['body'] = '-'
                    rsp1['address'] = linkAddress1
                else:
                    try:
                        if self.Flag_CheckPrevious:
                                for art2 in self.PreviousArticles:
                                    if art2['Title'] == itemText or art2['URLAddress'] == linkAddress1:
                                        continue
                        rsp1 = self.ChromeAccess.GetPageInfo(linkAddress1, e_Title, e_Body)
                    except:
                        continue
                    if not rsp1:
                        continue
                articleNo += 1
                collectedArticles.append(rsp1)
                print('[address]', rsp1['address'])
            listNo += 1
            lists = None
            try:
                if classLC != '-':
                    list0 = webDriver.find_element_by_css_selector(classLC)
                    if self.IsLogging: print('[11]', classLC) #--------
                    if classLP.startswith('.'):
                        lists = list0.find_elements_by_css_selector(classLP)
                    else:
                        lists = list0.find_elements_by_tag_name(classLP)
                    if self.IsLogging: print('[12]', classLP) #--------
                else:
                    if self.IsLogging: print('[13]', classLC) #--------
                    if classLP.startswith('.'):
                        lists = webDriver.find_elements_by_css_selector(classLP)
                    else:
                        lists = webDriver.find_elements_by_tag_name(classLP)
                    if self.IsLogging: print('[14]', classLP) #--------
            except:
                pass
            if not lists:
                break;

            outofList = True
            for list1 in lists:
                try:
                    if int(list1.text) == (listNo+1):
                        list1.click()
                        outofList = False
                        break
                except:
                    outofList = True
                    continue
            if outofList: break

        overlappedNo = 0
        print("Removing overlapped articles ...")
        if not repeatable:
            for index1 in range(len(collectedArticles)-1, -1, -1):
                art1 = collectedArticles[index1]
                for art2 in self.PreviousArticles:
                    if art2['Title'] == art1['title']:
                        overlappedNo += 1
                        articleNo -= 1
                        collectedArticles.remove(art1)
                        break

        abstractString = portalName + ' - ' + 'R:'+ str(listNumber) + ', '
        abstractString += 'L:' + str(listNo) + ', '
        abstractString += 'A:' + str(articleNo) + ', '
        abstractString += 'O:' + str(overlappedNo)
        print('[Abstract]', abstractString)
        date0 = datetime.now()
        datename1 = date0.strftime("%Y-%m-%d %H:%M:%S")
        collectionOverview = {
            'address': '[Overview]'+ ' @ ' + datename1,
            'title': keyWord + ' with ' + targetURL,
            'body': abstractString
        }
        collectedArticles.insert(0, collectionOverview)

        collectedResult['CollectedArticleNumber'] = articleNo
        collectedResult['OverlappedArticleNumber'] = overlappedNo
        collectedResult['CollectedListNumber'] = listNo
        collectedResult['CollectedArticles'] = collectedArticles
        collectedResult['Abstract'] = abstractString

        #time.sleep(5)

        return collectedResult

    def AddList(self, listInfo):
        print(" >>> Adding Lists ...")
        if not self.CollectedResult:
            self.CollectedResult = listInfo
            return
        articleList = self.CollectedResult['CollectedArticles']
        newArticleList = listInfo['CollectedArticles']
        articleNo = 0
        for article1 in newArticleList:
            isNewOne = True
            try:
                for article2 in articleList:
                    if article1['address'] == article2['address']:
                        isNewOne = False
                        break
                if isNewOne:
                    print('>>> Added', article1['address'])
                    articleList.append(article1)
            except:
                pass



class cNoticeCollector:
    def _init__(self, ):
        pass

    def StartCollection(self, collectionParam):
        
        try:
            repeatable = collectionParam.get('Repeatable')
            keyWord = collectionParam.get('Keyword')
            keywordID = collectionParam.get('KeywordID')
            tableName = collectionParam.get('Tablename')
            targetInfo = json.loads(collectionParam['TargetInfo'])
            targetURL = targetInfo['TU']
        except:
            print('[!!!!!-NoticeCollector]', 'Wrong COLLECTION-INFO')
            return None
        listNumber = targetInfo.get('LN') # list number
        preProcess = targetInfo.get('PP1') # Preprocess
        mainProcess = targetInfo.get('MP') # Main-process
        postProcess = targetInfo.get('PP2') # Postprocess
        checkPrevious = targetInfo.get('CP') # check-previous
        if checkPrevious or repeatable:
            req1 = {
                'KeywordID' : keywordID,
                'Tablename': tableName,
                'ArticleNumber': 100
            }
            SA1 = cServerAccess()
            try:
                previousArticles = SA1.LoadArticles(req1)
            except:
                previousArticles = []
        if listNumber:
            listNumber = int(listNumber)
        else:
            listNumber = 2



        webDriver = webdriver.Chrome(executable_path=cConstants.PATH_CHROMEDRIVER)
        webDriver.get(targetURL)
        webDriver.implicitly_wait(5)

        if preProcess:
            for process1 in preProcess:
                type1 = process1.get('Tp')
                IC1 = process1.get('IC') # item container
                IP1 = process1.get('IP') # item page
                Op1 = process1.get('Op') # Operation
                Qu1 = process1.get('Qu') # Query string
                RW1 = process1.get('RW') # Replaced word in url
                NW1 = process1.get('NW') # New word in url
                SD1 = process1.get('SD') # Scroll down
                if not type1: break;
                if type1=='i': # id
                    elem0 = None
                    if IC1:
                        elem0 = webDriver.find_element_by_id(IC1)
                    if item0:
                        elem1 = elem0.find_element_by_id(IP1)
                    else:
                        elem1 = webDriver.find_element_by_id(IP1)
                if type1=='c': # classname
                    item0 = None
                    if IC1:
                        elem0 = webDriver.find_element_by_css_selector(IC1)
                    if item0:
                        elem1 = elem0.find_element_by_css_selector(IP1)
                    else:
                        elem1 = webDriver.find_element_by_css_selector(IP1)
                if type1=='t': # tagname
                    elem0 = None
                    if IC1:
                        elem0 = webDriver.find_element_by_tag_name(IC1)
                    if item0:
                        elem1 = elem0.find_element_by_tag_name(IP1)
                    else:
                        elem1 = webDriver.find_element_by_tag_name(IP1)
                if Qu1:
                    item1.send_keys(Qu1)
                if Op1:
                    if Op1 == 'C':
                        try:
                            elem1.click()
                        except:
                            webDriver.execute_script("arguments[0].click();", 
                                                     elem1)
                    elif Op1 == 'E': elem1.send_Keys(Keys.RETURN)
                if RW1 and NW1:
                    if self.IsLogging: print('Portal', portalName)
                    url11 = webDriver.current_url
                    url11 = url11.replace(RW1, NW)
                    webDriver.get(url11)
                if SD1:
                    start = datetime.now()
                    if int(SD1) == 0:
                        end = start + timedelta(seconds=listNumber)
                    else:
                        end = start + timedelta(seconds=int(SD1))
                    while True:
                        webDriver.execute_script('window.scrollTo(0, document.body.scrollHeight);')
                        time.sleep(1)
                        if datetime.now() > end:
                            break

                #webDriver.implicitly_wait(5)

        # MAIN PROCESS ---------------------------------
        if not mainProcess:
            return None

        repeatIt = mainProcess.get('Rpt')
        cIC1 = mainProcess.get('cIC')
        cIP1 = mainProcess.get('cIP')
        cLC1 = mainProcess.get('cLC') # classname for list container
        cLP1 = mainProcess.get('cLP') # classname for list pages
        LO1 = mainProcess.get('LO') # list operation
        IO1 = mainProcess.get('IO') # item operation
        e_Title = mainProcess.get('tl') # enable title
        e_Body = mainProcess.get('bd') # enable body
        e_Address = mainProcess.get('ad') # enable address

        collectedArticles = []
        repeatCount = 0
        repeatCountLimit = 10
        articleNo=0
        listNo = 0
        portalName = 'Testsssss' #-------------------------
        while True:
            if repeatCount>=repeatCountLimit: break
            if listNo >= listNumber: break
            if cConstants.IsTesting:
                if itemNo > 12: break

            item0 = None
            if cIC1:
                if cIC1.startswith('.'):
                    item0 = webDriver.find_element_by_css_selector(cIC1)
                else:
                    item0 = webDriver.find_element_by_tag_name(cIC1)
            if item0:
                if not cIP1:
                    print(" No classname for item-page")
                    return None
                if cIP1.startswith('.'):
                    items = item0.find_elements_by_css_selector(cIP1)
                else:
                    items = item0.find_elements_by_tag_name(cIP1)
            else:
                if cIP1.startswith('.'):
                    items = webDriver.find_elements_by_css_selector(cIP1)
                else:
                    items = webDriver.find_elements_by_tag_name(cIP1)

            itemCount = 0
            for item1 in items:
                itemCount += 1
                if itemCount > 100: break
                if not IO1:
                    IO1 = 'L' #linkAddress
                if IO1 == 'L':
                    try:
                        itemTag = item1.find_element_by_tag_name('a')
                        linkAddress1 = itemTag.get_attribute('href')
                        itemText = itemTag.text
                    except:
                        linkAddress1 = item1.get_attribute('href')
                        itemText = item1.text
                    if len(linkAddress1) < 10: continue
                    indicator1 = str(listNo)+'-'+ str(articleNo)
                    print('[', itemText, '-', indicator1, ']', linkAddress1)
                    pageInfo = {}
                    if not e_Address and not e_Title and not e_Body:
                        pageInfo['title'] = itemText
                        pageInfo['body'] = '-'
                        pageInfo['address'] = linkAddress1
                    else:
                        try:
                            if checkPrevious:
                                    for art2 in previousArticles:
                                        if art2['Title'] == itemText or art2['URLAddress'] == linkAddress1:
                                            continue
                            rsp1 = self.ChromeAccess.GetPageInfo(linkAddress1, e_Address, e_Title, e_body)
                        except:
                            continue
                        if not rsp1:
                            continue
                    if e_Address: pageInfo['address'] = rsp1['address']
                    if e_Title: pageInfo['title'] = rsp1['title']
                    if e_Body: pageInfo['body'] = rsp1['body']
                    articleNo += 1
                    collectedArticles.append(pageInfo)
                elif IO1 == 'C':
                    itemText = item1.text
                    try:
                        item1.click()
                    except:
                        webDriver.execute_script("arguments[0].click();", item1)
                    linkAddress1 = webDriver.current_url
                    if not e_Address and not e_Title and not e_Body:
                        pageInfo['title'] = itemText
                        pageInfo['body'] = '-'
                        pageInfo['address'] = linkAddress1
                    else:
                        driverSource = webDriver.page_source
                        try:
                            AL1 = cArticleLoader()
                            rsp1 = AL1.LoadArticlefromWebdriver(driverSource, linkAddress1)
                        except:
                            continue
                        if not rsp1:
                            continue
                    articleNo += 1
                    collectedArticles.append(pageInfo)
                    item1.send_keys(Keys.BACK_SPACE)

            listNo += 1

            if not cLP1:
                print(" No classname for class-page")
                return None
            if cLC1:
                if cLC1.startswith('.'):
                    list0 = webDriver.find_element_by_css_selector(cLC1)
                else:
                    list0 = webDriver.find_element_by_tag_name(cLC1)
            if list0:
                if cLP1.startswith('.'):
                    lists = list0.find_elements_by_css_selector(cLP1)
                else:
                    lists = list0.find_elements_by_tag_name(cLP1)
            else:
                if cLP1.startswith('.'):
                    lists = webDriver.find_elements_by_css_selector(cLP1)
                else:
                    lists = webDriver.find_elemens_by_tag_name(cLP1)

            if not LO1:
                LO1 = 'C' # click
            if LO1 == 'C':
                try:
                    lists[listNo].click()
                except:
                    webDriver.execute_script("arguments[0].click();", lists[listNo])
            else:
                print('[!!!]', 'Unknown list operation code')
                break


            if not repeatIt: break
            repeatCount += 1


    # POSTPROCESS --------------------------------------------------------
        if postProcess:
            pass

        overlappedNo = 0
        print("Removing overlapped articles ...")
        if repeatable:
            for index1 in range(len(collectedArticles)-1, -1, -1):
                art1 = collectedArticles[index1]
                for art2 in previousArticles:
                    if art2['Title'] == art1['title']:
                        overlappedNo += 1
                        articleNo -= 1
                        collectedArticles.remove(art1)
                        break

        abstractString = 'R:'+ str(listNumber) + ', '
        abstractString += 'L:' + str(listNo) + ', '
        abstractString += 'A:' + str(articleNo) + ', '
        abstractString += 'O:' + str(overlappedNo)
        print('[Abstract]', abstractString)
        date0 = datetime.now()
        datename1 = date0.strftime("%Y-%m-%d %H:%M:%S")
        collectionOverview = {
            'address': '[Overview]'+ ' @ ' + datename1,
            'title': keyWord + ' with ' + targetURL,
            'body': abstractString
        }
        collectedArticles.insert(0, collectionOverview)

        collectedResult = {}
        collectedResult['CollectedArticleNumber'] = articleNo
        collectedResult['OverlappedArticleNumber'] = overlappedNo
        collectedResult['CollectedListNumber'] = listNo
        collectedResult['CollectedArticles'] = collectedArticles
        collectedResult['Abstract'] = abstractString

        #time.sleep(5)

        return collectedResult


class cPostProcessor:
    CollectedResult = {}
    KakaoAPI = None

    def __init__(self):
        try:
            self.KakaoAPI = cKakaoAPI()
        except:
            print("[???] Except in cKakaoAPI()")

    def TreatPostprocess(self, collectionParam, collectedResult):
        processes = json.loads(collectionParam['Postprocess'])
        userAddress = collectionParam['UserAddress']
        keyWord = collectionParam['Keyword']
        articleNo = int(collectedResult['CollectedArticleNumber'])
        date0 = datetime.now()
        datename1 = date0.strftime("%Y-%m-%d %H:%M:%S")
        sheetName = keyWord + ' at ' + datename1
        print(collectedResult['Abstract'])
        try:
            if self.KakaoAPI: self.KakaoAPI.SendMessage(collectedResult['Abstract'])
        except:
            print("[???] Except in KakaoAPI.SendMessage()")
        emailProcess = processes.get('Email')
        if not emailProcess: emailProcess = 'T'
        if emailProcess:
            if emailProcess == 'T':
                subject1 = "Collected Articles on " + collectionParam['Keyword'] + ' @ '+datename1
                body1 = cConstants.MARK_TITLE + ' Collection Completed as belows <br><br><br>'
                if articleNo == 0:
                    body1 += cConstants.MARK_LINK + ' There is no newly updated articles'
                else:
                    for article1 in collectedResult['CollectedArticles']:
                        body1 += cConstants.MARK_LINK + ' ' +article1['title']+'<a href="'+ article1['address']+'">[Link]</a><br><br>'
                mailContents1={
                    'Subject' : subject1,
                    'Body': body1,
                    'Receivers': userAddress
                }
                if cConstants.IsTesting: print('[Mail Contents]', mailContents1)
                mailer = cBMailer()
                mailer.SendMail(mailContents1)
            elif emailProcess == 'F':
                fileName = sheetName+'.xlsx'
                BExcel = cBExcel()
                BExcel.WriteSearchedInfos(fileName, collectedResult['CollectedArticles'])

                subject1 = "Collected Notices on " + sheetName
                body1 = "Attached filename : " + fileName
                mailContents1={
                    'Subject' : subject1,
                    'Body': body1,
                    'Receivers': userAddress
                }
                mailer = cBMailer()
                mailer.SendMail(mailContents1, fileName, receivers='ideas2biz@outlook.com')

        naverCafeProcess = processes.get('NaverCafe')
        if naverCafeProcess:
            cafe1 = cNaverCafeAPI()
            if naverCafeProcess=='0':
                cafe1.UploadCollectedArticles2Cafe(collectionParam, collectedResult['CollectedArticles'])
            else:
                cafe1.UploadCollectedArticles2Cafe(collectionParam, collectedResult['CollectedArticles'], processes)

        tistoryProcess_token = processes.get('TistoryToken')
        if tistoryProcess_token:
            TA1 = cTistoryAPI()
            if tistoryProcess_token == '0':
                TA1.UploadCollectedArticles2Blog(collectionParam, collectedResult['CollectedArticles'])
            else:
                TA1.UploadCollectedArticles2Blog(collectionParam, collectedResult['CollectedArticles'], processes)

    



 

 

반응형