Ejemplo n.º 1
0
def getStockGoodBadfromHK(stock_code):

    count_good = 0
    count_bad = 0

    try:

        driver = Preference.getWebDriver()

        today = date.today()
        pre_1month = today - timedelta(30)

        today_str = today.strftime('%Y-%m-%d')
        pre_1month_str = pre_1month.strftime('%Y-%m-%d')

        #목표상향 갯수 추출
        request_url = 'http://consensus.hankyung.com/apps.analysis/analysis.list?skinType=stock_good&search_text=' + stock_code + '&sdate=' + pre_1month_str + '&edate=' + today_str
        #print request_url

        driver.get(request_url)
        table_element = driver.find_element_by_xpath(
            '//*[@id="contents"]/div[2]/table/tbody')
        tablebody_html = table_element.get_attribute('innerHTML')

        soup = BeautifulSoup(tablebody_html, "html.parser")
        stock_element_list = soup.find_all('tr')

        for stock_element in stock_element_list:
            result_msg = stock_element.find('td').text
            #print result_msg
            #if(result_msg.find("결과가".decode('UTF-8'))):
            if "결과가".decode('UTF-8') in result_msg:
                print("None")
            else:
                count_good = count_good + 1
        #목표하향 갯수 추출
        request_url = 'http://consensus.hankyung.com/apps.analysis/analysis.list?skinType=stock_bad&search_text=' + stock_code + '&sdate=' + pre_1month_str + '&edate=' + today_str
        #print request_url

        driver.get(request_url)
        table_element = driver.find_element_by_xpath(
            '//*[@id="contents"]/div[2]/table/tbody')
        tablebody_html = table_element.get_attribute('innerHTML')

        soup = BeautifulSoup(tablebody_html, "html.parser")
        stock_element_list = soup.find_all('tr')

        for stock_element in stock_element_list:
            result_msg = stock_element.find('td').text
            #print result_msg
            #if(result_msg.find("결과가".decode('UTF-8'))):
            if "결과가".decode('UTF-8') in result_msg:
                print("None")
            else:
                count_bad = count_bad + 1

    except Exception as e:
        print(e)

    return count_good, count_bad
Ejemplo n.º 2
0
def tester():

    today = date.today()
    yesterday = today - timedelta(1)
    yesterday_str = yesterday.strftime('%Y-%m-%d')

    today_str = datetime.today().strftime('%Y-%m-%d')

    request_url = 'http://hkconsensus.hankyung.com/apps.analysis/analysis.list?skinType=stock_good&sdate=' + yesterday_str + '&edate=' + today_str + '&order_type=10010000&pagenum=150'
    print(request_url)

    driver = Preference.getWebDriver()
    driver.get(request_url)

    report_index_element = driver.find_element_by_xpath(
        '//*[@id="contents"]/div[2]/table/tbody/tr/td[2]/div')
    report_index_html = report_index_element.get_attribute('innerHTML')
    spl = report_index_html.split("\"")
    spl2 = spl[1].split("_")
    report_index = spl2[1]
    '''
    soup = BeautifulSoup(tablebody_html, "html.parser")
    div_list = soup.find_all('div')
    
    for _div in div_list:
        print _div
        print '---'
    '''

    #print tablebody_html

    return True
Ejemplo n.º 3
0
def main(login_pw, mail_pw):

    #환경세팅
    Preference.setPhantomjsPath()
    Preference.setChromedriverPath()
    Preference.setWebDriverInit()

    try:
        #최근 몇개 주식을 가지고 올것이냐(250)
        Preference.setStockLoadCount("250")
        #250
        #괴리율 랭킹 몇등까지 표출
        Preference.setStockRankCount(50)
        #20
        #이전목표주가는 몇개까지 표출
        Preference.setPrePriceCount(7)
        #7
        #몇일전 보고서 까지 찾을꺼냐
        Preference.setStockDaysCount(14)
        #14

        stock_dic_list = GetStockListfromHK.getCurrentStockConsenFromHK()

        count, result_html = HtmlMaker.makeVolumeUpHtml(stock_dic_list)

        print "  "
        print "--------------------------------"
        print "  "

        #print result_html

        print "--------------------------------"

        KST = datetime.now(timezone('Asia/Seoul'))
        title_name = KST.strftime('%Y년 %m월 %d일 %H시 '), ' 저평가 거래 폭증종목 Catcher'

        driver = Preference.getWebDriver()

        if (count > 1):
            if (Preference.isLinux()):
                SendEmail.sendMailtoGmail(title_name, result_html, mail_pw)

            time.sleep(10)
            #WriteWordPress.write_post(WriteWordPress.write_init(driver,login_pw), Preference.getCategory("거래폭발"), title_name, "", result_html)
        else:
            print "Nothing Catched"

        print "--------------------------------"

    except Exception as e:
        print e
        traceback.print_stack()
        traceback.print_exc()
        print "exception"

    finally:
        #Driver 닫기
        Preference.setWebDriverClose()
Ejemplo n.º 4
0
def getCurrentStockPriceNaver(stock_code):

    stock_price = {}
    if stock_code == '130960':
        stock_code = '035760'

    request_url = 'https://finance.naver.com/item/main.nhn?code=' + stock_code
    driver = Preference.getWebDriver()

    try:

        driver.get(request_url)
        #print request_url + "aaa"

        stock_price_info_element = driver.find_element_by_xpath(
            '//*[@id="middle"]/dl/dd[4]')
        stock_price_info = stock_price_info_element.get_attribute('innerHTML')
        #print stock_price_info

        stock_price_info_array = stock_price_info.split(' ')

        #print stock_price_info_array[1]
        #print stock_price_info_array[5]
        #print stock_price_info_array[6]

        #stock_updown_rate = driver.find_element_by_xpath('//*[@id="disArr[0]"]/span')
        #print stock_updown_rate.text
        plusminus = stock_price_info_array[5]

        if (plusminus == '플러스'):
            plusminus = '+'
            #print '+'
        elif (plusminus == '마이너스'):
            plusminus = '-'
            #print '-'

        #stock_price['now_price'] = stock_price_info_array[1].encode('utf-8')
        stock_price['now_price'] = stock_price_info_array[1]
        #stock_price['updown_rate'] = plusminus.encode('utf-8')+stock_price_info_array[6].encode('utf-8')+'%'.encode('utf-8')
        stock_price[
            'updown_rate'] = plusminus + stock_price_info_array[6] + '%'

    except Exception as e:
        print(e)
        stock_price['now_price'] = "0"
        stock_price['updown_rate'] = "0"

    #print stock_code
    #print stock_now_price.text
    #print stock_updown_rate.text

    #print stock_now_price.text+' ('+stock_updown_rate+')'

    return stock_price
Ejemplo n.º 5
0
def main(login_pw):
    
    #환경세팅
    Preference.setPhantomjsPath()
    Preference.setChromedriverPath()
    Preference.setWebDriverInit()
    
    try:
        #최근 몇개 주식을 가지고 올것이냐(250)
        Preference.setStockLoadCount("250")
        #250
        #괴리율 랭킹 몇등까지 표출
        Preference.setStockRankCount(30)
        #20
         #이전목표주가는 몇개까지 표출
        Preference.setPrePriceCount(7)
        #7
        #몇일전 보고서 까지 찾을꺼냐
        Preference.setStockDaysCount(14)
        #14
            
        stock_dic_list = GetStockListfromHK.getCurrentStockConsenFromHK()
        
        result_html = HtmlMaker.makeSTOCKHtml(stock_dic_list)

        
        #print result_html 
        
        print "--------------------------------"
        
        KST=datetime.now(timezone('Asia/Seoul'))
        title_name = KST.strftime('%Y년 %m월 %d일 %H시 '),' 상승여력 랭킹 '
        
        driver = Preference.getWebDriver()
        WriteWordPress.write_post(WriteWordPress.write_init(driver,login_pw), Preference.getCategory("상승여력"), title_name, "", result_html)
        print "--------------------------------"
        
        
    except Exception as e:
        print '--- stack ---'
        traceback.print_stack()
        print '--- exec ---'
        traceback.print_exc()
        print '--- e ---'
        print e
        print "exception"
        
    finally:
        #Driver 닫기
        Preference.setWebDriverClose()
Ejemplo n.º 6
0
def main(login_pw, mail_pw):

    #환경세팅
    Preference.setPhantomjsPath()
    Preference.setChromedriverPath()
    Preference.setWebDriverInit()

    try:

        #몇일간 리포트 확인, 최근 1주리포트
        Preference.setStockDaysCount(7)
        #이전목표주가는 몇개까지 표출
        Preference.setPrePriceCount(7)

        ##목표주가 상향 리포트 확인
        stock_dic_list = GetStockListfromHK.getUpturnStockFromHK()
        ### 크레온 Plus에서 수급정보 가져오기
        stock_dic_list = GetDetailInfoFromPlus.getPlusStockInfo(stock_dic_list)
        ###

        result_html = HtmlMaker.makeUpturnAllStockHtml(stock_dic_list)

        print("--------------------------------")
        print(result_html)
        print("--------------------------------")

        KST = datetime.now(timezone('Asia/Seoul'))
        title_name = KST.strftime('%Y년 %m월 %d일 %H시 '), ' 목표가 상향기업 '

        print("WordPress Write Start")
        driver = Preference.getWebDriver()
        #WriteWordPress.write_post(WriteWordPress.write_init(driver,login_pw), Preference.getCategory("목표상향"), title_name, "", result_html)
        print("WordPress Write Complete")
        print("--------------------------------")
        print("Send Email Start")
        SendEmail.sendMailtoGmail(title_name, result_html, mail_pw)

    except Exception as e:
        traceback.print_stack()
        traceback.print_exc()
        print(e)
        print("exception")

    finally:
        #Driver 닫기
        Preference.setWebDriverClose()
Ejemplo n.º 7
0
def main(login_pw):

    #환경세팅
    Preference.setPhantomjsPath()
    Preference.setChromedriverPath()
    Preference.setWebDriverInit()

    try:

        #이전목표주가는 몇개까지 표출
        Preference.setPrePriceCount(7)

        stock_dic_list = GetStockListfromHK.getUpturnStockFromHK()

        result_html = HtmlMaker.makeUpturnStockHtml(stock_dic_list)

        print "  "
        print "--------------------------------"
        print "  "

        print result_html

        print "--------------------------------"

        KST = datetime.now(timezone('Asia/Seoul'))
        title_name = KST.strftime('%Y년 %m월 %d일 %H시 '), ' 목표가 상향기업 '

        driver = Preference.getWebDriver()
        WriteWordPress.write_post(WriteWordPress.write_init(driver, login_pw),
                                  Preference.getCategory("목표상향"), title_name,
                                  "", result_html)
        print "--------------------------------"

    except Exception as e:
        print '--- stack ---'
        traceback.print_stack()
        print '--- exec ---'
        traceback.print_exc()
        print '--- e ---'
        print e
        print "exception"

    finally:
        #Driver 닫기
        Preference.setWebDriverClose()
Ejemplo n.º 8
0
def getCommpanyInfo(stock_code):

    stock_info = {}
    request_url = 'https://navercomp.wisereport.co.kr/v2/company/c1010001.aspx?cmp_cd=' + stock_code

    print(request_url)

    driver = Preference.getWebDriver()
    driver.get(request_url)

    company_info = driver.find_element_by_xpath(
        '/html/body/div/form/div[1]/div/div[2]/div[3]/div/div/div[5]/div[2]/ul'
    )
    company_info_html = company_info.get_attribute('innerHTML')
    print(company_info_html)

    soup = BeautifulSoup(company_info_html, "html.parser")
    company_info_list = soup.find_all('li')
    for a_company_info in company_info_list:
        print(a_company_info)

    return 0
Ejemplo n.º 9
0
def getStockDeatilInfofromPaxnet(stock_code):

    stock_info = {}
    request_url = 'http://www.paxnet.co.kr/stock/analysis/presentValue?abbrSymbol=' + stock_code

    print(request_url)

    driver = Preference.getWebDriver()

    try:

        driver.get(request_url)

        #시가총액
        stock_info_element = driver.find_element_by_xpath(
            '//*[@id="contents"]/div[1]/div[2]/div[1]/div/table/tbody/tr[8]/td[1]'
        )
        stock_info['total_cap'] = stock_info_element.get_attribute('innerHTML')
        print(stock_info['total_cap'])

        #당일 거래량
        stock_info_element = driver.find_element_by_xpath(
            '//*[@id="contents"]/div[1]/div[2]/div[1]/div/table/tbody/tr[4]/td[1]'
        )
        stock_info['today_volume'] = stock_info_element.get_attribute(
            'innerHTML')
        print(stock_info['today_volume'])

        #전일 거래량 -> 5일평균으로 변경
        #stock_info_element = driver.find_element_by_xpath('//*[@id="contents"]/div[1]/div[2]/div[1]/div/table/tbody/tr[8]/td[2]')
        #stock_info['everage_5day_volume']= stock_info_element.get_attribute('innerHTML')
        #print stock_info['everage_5day_volume']

        # 5일평균 거래량
        volume_bf_days_element = driver.find_element_by_xpath(
            '//*[@id="viewHtml2"]/tr[1]/td[8]')
        volume_bf_1day = float(
            volume_bf_days_element.get_attribute('innerHTML').replace(',', ''))

        volume_bf_days_element = driver.find_element_by_xpath(
            '//*[@id="viewHtml2"]/tr[2]/td[8]')
        volume_bf_2day = float(
            volume_bf_days_element.get_attribute('innerHTML').replace(',', ''))

        volume_bf_days_element = driver.find_element_by_xpath(
            '//*[@id="viewHtml2"]/tr[3]/td[8]')
        volume_bf_3day = float(
            volume_bf_days_element.get_attribute('innerHTML').replace(',', ''))

        volume_bf_days_element = driver.find_element_by_xpath(
            '//*[@id="viewHtml2"]/tr[4]/td[8]')
        volume_bf_4day = float(
            volume_bf_days_element.get_attribute('innerHTML').replace(',', ''))

        volume_bf_days_element = driver.find_element_by_xpath(
            '//*[@id="viewHtml2"]/tr[5]/td[8]')
        volume_bf_5day = float(
            volume_bf_days_element.get_attribute('innerHTML').replace(',', ''))

        everage_5day_volume = float(
            (volume_bf_1day + volume_bf_2day + volume_bf_3day +
             volume_bf_4day + volume_bf_5day) / 5)

        #거래량 5일평균 대비
        volume_ratio = float(stock_info['today_volume'].replace(
            ',', '')) / everage_5day_volume
        volume_ratio = int(volume_ratio * 100)
        stock_info['volume_ratio'] = str(volume_ratio)
        print(stock_info['volume_ratio'])

        #PER
        #stock_info_element = driver.find_element_by_xpath('//*[@id="contents"]/div[1]/div[2]/div[1]/div/table/tbody/tr[12]/td[1]')
        #stock_info_element = driver.find_element_by_xpath('//*[@id="contents"]/div[1]/div[2]/div[1]/div/table/tbody/tr[12]/td[1]')
        stock_info_element = driver.find_element_by_xpath(
            '//*[@id="contents"]/div[1]/div[2]/div[1]/div/table/tbody/tr[13]/td[1]'
        )
        stock_info['PER'] = stock_info_element.get_attribute('innerHTML')
        stock_info['PER'] = stock_info['PER'].replace('\ubc30', '')
        temp = stock_info['PER'].splitlines()
        stock_info['PER'] = "".join(temp)
        stock_info['PER'] = stock_info['PER'].replace('-', '0.0')
        print(stock_info['PER'])

        #PBR
        #stock_info_element = driver.find_element_by_xpath('//*[@id="contents"]/div[1]/div[2]/div[1]/div/table/tbody/tr[13]/td[2]')
        #stock_info_element = driver.find_element_by_xpath('//*[@id="contents"]/div[1]/div[2]/div[1]/div/table/tbody/tr[13]/td[1]')
        stock_info_element = driver.find_element_by_xpath(
            '//*[@id="contents"]/div[1]/div[2]/div[1]/div/table/tbody/tr[14]/td[1]'
        )
        stock_info['PBR'] = stock_info_element.get_attribute('innerHTML')
        stock_info['PBR'] = stock_info['PBR'].replace('\ubc30', '')
        temp = stock_info['PBR'].splitlines()
        stock_info['PBR'] = "".join(temp)
        stock_info['PBR'] = stock_info['PBR'].replace('-', '0.0')
        print(stock_info['PBR'])

        good_count = 0
        bad_count = 0

        good_count, bad_count = getStockGoodBadfromHK(stock_code)
        stock_info['GOOD'] = str(good_count)
        stock_info['BAD'] = str(bad_count)

    except Exception as e:
        print(e)

    return stock_info
Ejemplo n.º 10
0
def getPreStockConsenFromHK(stock_code):
    
    try:
        stock_pre_consen_list = []
        
        today = date.today()
        
        yesterday = today - timedelta(1)
        pre_2month = today - timedelta(90)
        
        yesterday_str = yesterday.strftime('%Y-%m-%d')
        pre_2month_str = pre_2month.strftime('%Y-%m-%d')
        
        request_url = 'http://hkconsensus.hankyung.com/apps.analysis/analysis.list?sdate='+pre_2month_str+'&edate='+yesterday_str+'&now_page=1&search_value=&report_type=CO&pagenum=50&search_text='+stock_code+'&business_code='
        print(request_url)
        
        driver=Preference.getWebDriver()
        driver.get(request_url)

        
        table_element = driver.find_element_by_xpath('//*[@id="contents"]/div[2]/table/tbody')
        tablebody_html = table_element.get_attribute('innerHTML')
        #print tablebody_html

        
        
        soup = BeautifulSoup(tablebody_html, "html.parser")
        
        stock_element_list = soup.find_all('tr')
        count = 1
        
        
        for stock_element in stock_element_list:
            
            #DATE
            upload_date=stock_element.td.string
            stock_data = stock_element.find_all('td')
            stock_pre_consen ={}
            i = 1
            
            for astock_data in stock_data:
                if(i==1):
                    #print astock_data.text
                    stock_pre_consen['update_date']=astock_data.text
                    if(stock_pre_consen['update_date']=='결과가 없습니다.'):
                        break
                if(i==2):                
                    #print astock_data.find('strong').text
                    stock_pre_consen['all_title'] = astock_data.find('strong').text
                    all_title = stock_pre_consen['all_title']
                    start = all_title.find('(')+1
                    end = start+6    
                    stock_code = all_title[start:end]
                    stock_pre_consen['stock_code']=stock_code
                    #stockcode=stock_code
                    
                    stock_name = all_title[0:all_title.find('(')] 
                    stock_pre_consen['stock_name']=stock_name
                    title = all_title[end+1:len(all_title)]
                    stock_pre_consen['title']=title
                
                if(i==3):
                    #print astock_data.text
                    stock_pre_consen['consen_price']=astock_data.text
                    print('###'+stock_pre_consen['consen_price'])
                                    
                if(i==4):
                    #print astock_data.text
                    stock_pre_consen['opinion']=astock_data.text    
                if(i==6):
                    #print astock_data.text
                    stock_pre_consen['analyst_company']=astock_data.text
                
                if(i==9):
                    for link in astock_data.find_all('a', href=True):
                        url = link['href']
                    stock_pre_consen['report_url'] = 'http://hkconsensus.hankyung.com/'+ url
                    #print stock_dic['report_url']
                    break
                
                i=i+1
                #print "."
             
            #if(stock_pre_consen['consen_price']=='0'):
            if(stock_pre_consen['update_date']=='결과가 없습니다.'):
                print('NONE A')
            elif(stock_pre_consen['stock_code']==''):
                print('NONE B')
            else:
                stock_pre_consen_list.append(stock_pre_consen)
                count+=1
             
            '''
            stock_pre_consen_list.append(stock_pre_consen)
            count+=1    
            '''
            #print '####'+count
            #print 'debug4'
            #print count
                 
            if (count > Preference.getPrePriceCount()):
                print(Preference.getPrePriceCount() + ' line limited')
                break
                
    except Exception as e:
        
        print('No Pre Consen')
        print(str(e))
    

    print(stock_pre_consen_list)
    
    return stock_pre_consen_list
Ejemplo n.º 11
0
def getUpturnStockFromHK():
    
    #한경 컨세서스 연결.
    
    stock_dic_list = []
    
    today = date.today()   
    today_str = datetime.today().strftime('%Y-%m-%d')

    yesterday = today - timedelta(Preference.getStockDaysCount())
    yesterday_str = yesterday.strftime('%Y-%m-%d')
    
    request_url = 'http://hkconsensus.hankyung.com/apps.analysis/analysis.list?skinType=stock_good&sdate='+yesterday_str+'&edate='+today_str+'&order_type=10010000&pagenum=150'
    print(request_url)
        
    
    driver = Preference.getWebDriver()   
    driver.get(request_url)
    
    table_element = driver.find_element_by_xpath('//*[@id="contents"]/div[2]/table/tbody')
    tablebody_html = table_element.get_attribute('innerHTML')
    
    soup = BeautifulSoup(tablebody_html, "html.parser")
    
    stock_element_list = soup.find_all('tr')
    
    for stock_element in stock_element_list:
        
        #DATE
        upload_date=stock_element.td.string
        stock_data = stock_element.find_all('td')
        stock_dic ={}
        i = 1
        for astock_data in stock_data:
            
            if(i==1):
                #print astock_data.text
                stock_dic['update_date']=astock_data.text
            if(i==2):
                #print '---'
                stock_dic['report_url']=''
                try:
                    spl1 = str(astock_data).split("\n")
                    #print spl1
                    spl2 = spl1[3].split("\"")
                    #print spl2
                    spl3 = spl2[3].split("_")
                    #print spl3
                    report_index = spl3[1]
                    #print report_index
                    stock_dic['report_url']='http://hkconsensus.hankyung.com/apps.analysis/analysis.downpdf?report_idx='+report_index
                except:
                    stock_dic['report_url']=''
                    
                stock_dic['all_title'] = astock_data.find('strong').text
                all_title = stock_dic['all_title']
                start = all_title.find('(')+1
                end = start+6    
                stock_code = all_title[start:end]
                stock_dic['stock_code']=stock_code
                stock_name = all_title[0:all_title.find('(')] 
                stock_dic['stock_name']=stock_name
                title = all_title[end+1:len(all_title)]
                stock_dic['title']=title
                #print stock_dic['all_title']
                #print stock_dic['stock_code']
                #print stock_dic['stock_name']
                #print stock_dic['title']
            if(i==3):
                #print astock_data.text
                stock_dic['analyst_name']=astock_data.text                
            if(i==4):
                #print astock_data.text
                stock_dic['analyst_company']=astock_data.text    
            if(i==5):
                #print astock_data.text
                stock_dic['new_price']=astock_data.text
            if(i==6):
                #print astock_data.text
                stock_dic['old_price']=astock_data.text
                continue
            i=i+1
            #print "."
        

        stock_dic['companyinfo_url']='http://media.kisline.com/highlight/mainHighlight.nice?paper_stock='+stock_code+'&nav=1'    
        #print stock_dic['companyinfo_url']        
        upper_rate=float(stock_dic['new_price'].replace(',',''))/float(stock_dic['old_price'].replace(',',''))    
        upper_rate=int((upper_rate-1)*100)        
        stock_dic['upper_rate']=str(upper_rate)
        
        
        if(stock_dic['new_price'] != "0" ):
             
            now_stock_price = GetStockPrice.getCurrentStockPriceNaver(stock_dic['stock_code'])
                    
            stock_dic['now_price']=now_stock_price['now_price']
            stock_dic['now_updown_rate']=now_stock_price['updown_rate']
            
            print((stock_dic['stock_name']))
            print((stock_dic['new_price']))
            print((stock_dic['now_price']))
                  
            diff_rate=float(stock_dic['now_price'].replace(',',''))/float(stock_dic['new_price'].replace(',',''))    
            diff_rate=int(diff_rate*100)
            stock_dic['diff_rate']=str(diff_rate)
            
            print((stock_dic['diff_rate']))
            
            if(diff_rate > 20 and diff_rate < 100):
                stock_dic_list.append(stock_dic)
            
        #print stock_dic
    
    #다 뽑아와서 차이나는 순대로 정렬    
    stock_dic_list_sorted = sorted(stock_dic_list, key=lambda k: k['diff_rate'], reverse=False)
        
    
    return stock_dic_list_sorted
Ejemplo n.º 12
0
def getCurrentStockConsenFromHK():

    #한경 컨세서스 연결.
    stock_dic_list = []

    KST = datetime.now(timezone('Asia/Seoul'))
    today_str = KST.strftime('%Y-%m-%d')
    #몇일전까지 : days=0 은 오늘
    startday_str = (
        datetime.today() -
        timedelta(days=Preference.getStockDaysCount())).strftime('%Y-%m-%d')
    #몇개 분석할 것이냐?
    stock_count = Preference.getStockLoadCount()
    #request_url = 'http://hkconsensus.hankyung.com/apps.analysis/analysis.list?skinType=stock_good&sdate='+today_str+'&edate='+today_str+'&order_type=10010000&pagenum=150'
    #http://hkconsensus.hankyung.com/apps.analysis/analysis.list?skinType=business&sdate=2019-04-03&edate=2019-04-09&pagenum=1000&order_type=12000001&now_page=1
    request_url = 'http://hkconsensus.hankyung.com/apps.analysis/analysis.list?skinType=business&sdate=' + startday_str + '&edate=' + today_str + '&pagenum=' + stock_count + '&order_type=12000001&now_page=1'

    print(request_url)

    driver = Preference.getWebDriver()

    driver.get(request_url)
    #html = driver.page_source
    table_element = driver.find_element_by_xpath(
        '//*[@id="contents"]/div[2]/table/tbody')
    tablebody_html = table_element.get_attribute('innerHTML')
    #print tablebody_html

    soup = BeautifulSoup(tablebody_html, "html.parser")

    stock_element_list = soup.find_all('tr')

    for stock_element in stock_element_list:

        #DATE
        upload_date = stock_element.td.string
        stock_data = stock_element.find_all('td')
        stock_dic = {}
        stockcode = '000000'
        i = 1
        for astock_data in stock_data:
            if (i == 1):
                #print astock_data.text
                stock_dic['update_date'] = astock_data.text
            if (i == 2):
                #print astock_data.find('strong').text
                stock_dic['all_title'] = astock_data.find('strong').text
                all_title = stock_dic['all_title']
                start = all_title.find('(') + 1
                end = start + 6
                stock_code = all_title[start:end]
                stock_dic['stock_code'] = stock_code
                stockcode = stock_code
                stock_name = all_title[0:all_title.find('(')]
                stock_dic['stock_name'] = stock_name
                title = all_title[end + 1:len(all_title)]
                stock_dic['title'] = title
                #print stock_dic['all_title']
                #print stock_dic['stock_code']
                #print stock_dic['stock_name']
                #print stock_dic['title']
            if (i == 3):
                #적정가격
                #print astock_data.text
                stock_dic['new_price'] = astock_data.text
            if (i == 4):
                #print astock_data.text
                stock_dic['opinion'] = astock_data.text
            if (i == 5):
                #print astock_data.text
                stock_dic['analyst_name'] = astock_data.text
            if (i == 6):
                #print "####a####"
                #print astock_data.text
                stock_dic['analyst_company'] = astock_data.text

            if (i == 9):
                for link in astock_data.find_all('a', href=True):
                    url = link['href']
                stock_dic[
                    'report_url'] = 'http://hkconsensus.hankyung.com/' + url
                #print stock_dic['report_url']
                break
            i = i + 1
            #print "."

        stock_dic[
            'companyinfo_url'] = 'http://media.kisline.com/highlight/mainHighlight.nice?paper_stock=' + stockcode + '&nav=1'
        #print stock_dic['companyinfo_url']

        if (stock_dic['new_price'] != "0"):

            now_stock_price = GetStockPrice.getCurrentStockPriceNaver(
                stock_dic['stock_code'])

            stock_dic['now_price'] = now_stock_price['now_price']
            stock_dic['now_updown_rate'] = now_stock_price['updown_rate']

            print((stock_dic['stock_name']))
            print((stock_dic['new_price']))
            print((stock_dic['now_price']))

            diff_rate = float(stock_dic['now_price'].replace(',', '')) / float(
                stock_dic['new_price'].replace(',', ''))
            diff_rate = int(diff_rate * 100)
            stock_dic['diff_rate'] = str(diff_rate)

            print((stock_dic['diff_rate']))

            if (diff_rate > 20 and diff_rate < 100):
                stock_dic_list.append(stock_dic)

        #print stock_dic
    stock_dic_list_sorted = sorted(stock_dic_list,
                                   key=lambda k: k['diff_rate'],
                                   reverse=False)

    return stock_dic_list_sorted
Ejemplo n.º 13
0
def main(login_pw):

    #환경세팅
    Preference.setPhantomjsPath()
    Preference.setChromedriverPath()
    Preference.setWebDriverInit()

    try:

        #이전목표주가는 몇개까지 표출
        Preference.setPrePriceCount(7)
        Preference.setStockRankCount(20)

        #GetStockInfoDetail.getCommpanyInfo('054950')
        #exit(0)

        stock_dic_list = GetStockListfromMaster.getStockListfromCreonPlus()

        for astock in stock_dic_list:
            print(astock['stock_code'], " : ", astock['stock_name'])

        Preference.setStockRankCount(len(stock_dic_list))

        result_html = HtmlMaker.makeSTOCKHtml(stock_dic_list)

        print("############################################")
        print("############################################")
        print("############################################")

        print(result_html)

        print("--------------------------------")

        KST = datetime.now(timezone('Asia/Seoul'))
        title_name = KST.strftime('%Y년 %m월 %d일 %H시 '), ' 오늘의 특징 주 '

        driver = Preference.getWebDriver()
        WriteWordPress.write_post(WriteWordPress.write_init(driver, login_pw),
                                  Preference.getCategory("오늘의특징주"), title_name,
                                  "", result_html)
        print("--------------------------------")
        '''
        
        print "--------------------------------"
        
        KST=datetime.now(timezone('Asia/Seoul'))
        title_name = KST.strftime('%Y년 %m월 %d일 %H시 '),' 상승여력 랭킹 '
        
        driver = Preference.getWebDriver()
        WriteWordPress.write_post(WriteWordPress.write_init(driver,login_pw), Preference.getCategory("상승여력"), title_name, "", result_html)
        print "--------------------------------"
        
        '''

    except Exception as e:
        print('--- stack ---')
        traceback.print_stack()
        print('--- exec ---')
        traceback.print_exc()
        print('--- e ---')
        print(e)
        print("exception")

    finally:
        #Driver 닫기
        Preference.setWebDriverClose()
Ejemplo n.º 14
0
def main(login_pw, mail_pw):

    #환경세팅
    Preference.setPhantomjsPath()
    Preference.setChromedriverPath()
    Preference.setWebDriverInit()

    try:

        #몇일 전 목표가 상향보고서까지 가지고 올건지
        Preference.setStockDaysCount(14)

        #이전목표주가는 몇개까지 표출
        Preference.setPrePriceCount(7)

        ### RSI과매도 종목을 몇개까지?
        Preference.setStockRankCount(20)

        ### 목표가 상향 종목 가져오기
        stock_dic_list = GetStockListfromHK.getUpturnStockFromHK()
        ### 크레온 Plus에서 수급정보 가져오기
        stock_dic_list = GetDetailInfoFromPlus.getPlusStockInfo(stock_dic_list)
        ###

        result_html = HtmlMaker.makeUpturnStockHtml(stock_dic_list)

        try:
            ### 과매도 종목 가져오기 ###
            print("RSI 과매도 종목 가져오기")
            stock_dic_list2 = GetStockListfromMaster.getStockListfromCreonPlus(
            )
            stock_dic_list2 = GetDetailInfoFromPlus.getPlusStockInfo(
                stock_dic_list2)
            result_html += HtmlMaker.makeRSIdownSTOCKHtml(stock_dic_list2)
        except Exception as E:
            print("RSI과매도 가져오기 실패")
            print(E)
            traceback.print_exc()

        result_html += HtmlMaker.getPostScript()

        print(result_html)

        KST = datetime.now(timezone('Asia/Seoul'))
        title_name = KST.strftime('%Y년 %m월 %d일 %H시 '), ' CHOICESTOCK '

        #if(ResultVO.getIsCatched()):
        print("WordPress Write Start")

        driver = Preference.getWebDriver()
        #WriteWordPress.write_post(WriteWordPress.write_init(driver,login_pw), Preference.getCategory("목표상향"), title_name, "", result_html)

        print("WordPress Write Complete")
        print("Send Email Start")
        SendEmail.sendMailtoGmail(title_name, result_html, mail_pw)
        #else:
        #print("CHOICESTOCK Didn't Catch Any Stock")

    except Exception as e:
        print('--- stack ---')
        traceback.print_stack()
        print('--- exec ---')
        traceback.print_exc()
        print(e)
        print("exception")

    finally:
        #Driver 닫기
        Preference.setWebDriverClose()
Ejemplo n.º 15
0
def getPreStockConsenFromHK(stock_code):

    #driver = webdriver.PhantomJS(phantomjs, service_args=['--cookies-file=/tmp/cookies.txt'])
    #driver.delete_all_cookies()
    '''
    opt = webdriver.ChromeOptions()
    opt.add_argument('headless')
    opt.add_argument("--disable-gpu")
    driver = webdriver.Chrome(chromedrive, chrome_options=opt)
    '''

    try:
        stock_pre_consen_list = []

        today = date.today()

        yesterday = today - timedelta(1)
        pre_2month = today - timedelta(60)

        yesterday_str = yesterday.strftime('%Y-%m-%d')
        pre_2month_str = pre_2month.strftime('%Y-%m-%d')

        request_url = 'http://hkconsensus.hankyung.com/apps.analysis/analysis.list?sdate=' + pre_2month_str + '&edate=' + yesterday_str + '&now_page=1&search_value=&report_type=CO&pagenum=50&search_text=' + stock_code + '&business_code='
        print request_url

        #driver = webdriver.PhantomJS(phantomjs)
        driver = Preference.getWebDriver()
        driver.get(request_url)

        table_element = driver.find_element_by_xpath(
            '//*[@id="contents"]/div[2]/table/tbody')
        tablebody_html = table_element.get_attribute('innerHTML')
        #print tablebody_html

        soup = BeautifulSoup(tablebody_html, "html.parser")

        stock_element_list = soup.find_all('tr')
        count = 1

        for stock_element in stock_element_list:

            #DATE
            upload_date = stock_element.td.string
            stock_data = stock_element.find_all('td')
            stock_pre_consen = {}
            i = 1

            for astock_data in stock_data:
                if (i == 1):
                    #print astock_data.text
                    stock_pre_consen['update_date'] = astock_data.text
                if (i == 3):
                    #print astock_data.text
                    stock_pre_consen['consen_price'] = astock_data.text
                    print '###' + stock_pre_consen['consen_price']

                if (i == 4):
                    #print astock_data.text
                    stock_pre_consen['opinion'] = astock_data.text
                if (i == 6):
                    #print astock_data.text
                    stock_pre_consen['analyst_company'] = astock_data.text

                if (i == 9):
                    stock_pre_consen['report_url'] = astock_data.text
                    print stock_pre_consen['report_url']

                i = i + 1
                #print "."

            if (stock_pre_consen['consen_price'] == '0'):
                print 'Not Rated'

            else:
                stock_pre_consen_list.append(stock_pre_consen)
                count += 1
                #print '####'+count

            #print 'debug4'
            #print count

            if (count > Preference.getPrePriceCount()):
                print Preference.getPrePriceCount() + ' line limited'
                break

    except Exception, e:

        print 'No Pre Consen'
        print str(e)