From ea5165a4aab7ffafa8b5b47e0c659f86a8dcfa43 Mon Sep 17 00:00:00 2001 From: mjjo Date: Tue, 10 Jan 2017 19:22:02 +0900 Subject: [PATCH] =?UTF-8?q?-=20=EC=A2=85=EB=AA=A9=EB=AA=85=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EA=B0=9C=EC=84=A0=20-=20=EC=97=91=EC=85=80=20?= =?UTF-8?q?=ED=95=B8=EB=93=A4=EB=9F=AC=20=EC=B6=94=EA=B0=80=20-=20?= =?UTF-8?q?=EA=B8=B0=ED=83=80=20=EC=BD=94=EB=93=9C=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CodeList.cs | 45 ++++++----- Crawler.cs | 6 +- CybosHelper.cs | 53 ------------- ExcelHandler.cs | 97 +++++++++++++++++++++++ NewsCrawler.csproj | 38 +++++++++ NewsForm.Designer.cs | 12 +-- NewsForm.cs | 181 ++++++++++++++++++++++++++----------------- Util.cs | 13 +--- 8 files changed, 286 insertions(+), 159 deletions(-) create mode 100644 ExcelHandler.cs diff --git a/CodeList.cs b/CodeList.cs index cf6b9e2..b95f57a 100644 --- a/CodeList.cs +++ b/CodeList.cs @@ -55,11 +55,29 @@ namespace NewsCrawler if(Util.IsDebugging() == false) return; - SearchCode("[클릭 e종목]로엔, 본격적으로 시작되는 카카오 시너"); - SearchCode("[클릭 e종목]\"SK텔레콤, 투자심리 개선 가능성 주목해"); - SearchCode("[클릭 e종목]SK하이닉스, 추가 상승 낙관적"); - SearchCode("MBK, 45억 규모 유상증자 결정"); - SearchCode("다음주 코스피 1960~1990…산유량 감산여부에 주목"); + Console.WriteLine("Code Search Test"); + + Console.WriteLine(SearchCode("[클릭 e종목]로엔, 본격적으로 시작되는 카카오 시너")); + Console.WriteLine(SearchCode("[클릭 e종목]\"SK텔레콤, 투자심리 개선 가능성 주목해")); + Console.WriteLine(SearchCode("[클릭 e종목]SK하이닉스, 추가 상승 낙관적")); + Console.WriteLine(SearchCode("MBK, 45억 규모 유상증자 결정")); + Console.WriteLine(SearchCode("다음주 코스피 1960~1990…산유량 감산여부에 주목")); + + Console.WriteLine(SearchCode("\"사세요 일색 보고서\" 증권사 투자등급 공시 '")); + Console.WriteLine(SearchCode("허서홍 GS에너지 상무, GS 보통주 5.1만주 매수")); + Console.WriteLine(SearchCode("엠씨넥스, 아이클론 프리미엄 블랙박스 'i5 W")); + Console.WriteLine(SearchCode("에스아이티글로벌, 김의서 대표이사 체제로 변")); + Console.WriteLine(SearchCode("시몬스침대, 일산 가구공단에 프리미엄 매장 오")); + Console.WriteLine(SearchCode("[유럽증시]美 고용지표 앞두고 짙은 관망세")); + Console.WriteLine(SearchCode("코스콤, 강신 신임 전무이사 선임")); + Console.WriteLine(SearchCode("[베스트리포트]원자현미경, 반도체의 질문에 답")); + Console.WriteLine(SearchCode("거래소, 인콘에 최대주주 지분매각 추진설 조회")); + Console.WriteLine(SearchCode("와이제이엠게임즈, 서울 강남구로 본점 이전")); + + Console.WriteLine(SearchCode("[특징주] 에이치엘비-생명, 아파티닙 글로벌 임상 3상 최종 승인 소식에 상승세")); + Console.WriteLine(SearchCode("진도군, 112건의 계약심사 통해 예산 10억원 절감")); + + Console.WriteLine("Test End"); } void MakeList() @@ -75,6 +93,8 @@ namespace NewsCrawler if(Code.m_strCode[0] == 'A') m_CodeList.Add(Code); } + + m_CodeList.Sort((a, b) => b.m_strName.Length-a.m_strName.Length); } void LoadCodeType(string strPath, CODE_TYPE enType) @@ -221,6 +241,8 @@ namespace NewsCrawler m_SynonymList.Add(Code); } } + + m_SynonymList.Sort((a, b) => b.m_strName.Length-a.m_strName.Length); } } @@ -232,19 +254,6 @@ namespace NewsCrawler string[] words = strReplace.Trim().Split(' '); string strCodeWord = words[0]; - //int iBracesPos = strText.Trim().IndexOfAny(new char[] { ']', '>', ')' }); - //string[] astrWords = strText.Substring(iBracesPos).Trim().Split(' '); - - //string[] astrWords = strText.Trim().Split(' '); - //if(astrWords.Length < 1) - // return null; - - //string strCodeWord; - //if(astrWords.Length > 1 && astrWords[0].IndexOfAny(new char[] { ']', '>', ')' }) >= 0) - // strCodeWord = astrWords[1]; - //else - // strCodeWord = astrWords[0]; - CODE_VALUE Result = m_CodeList.Find(s => strCodeWord.Contains(s.m_strName)); if(Result != null) return Result; diff --git a/Crawler.cs b/Crawler.cs index cf89dc7..4b3a8a1 100644 --- a/Crawler.cs +++ b/Crawler.cs @@ -449,12 +449,12 @@ namespace NewsCrawler if(strErrCode == "020") { Config.SetDartAPIKeyLimit(State.m_strAuthKey); - Util.Log(Util.LOG_TYPE.ERROR, string.Format("[DartAPI] {0} ({1})", jObj["err_msg"], m_iDartAPIRetry)); + Util.Log(Util.LOG_TYPE.ERROR, string.Format("[DartAPI] {0} (key:{1}, retry:{2})", jObj["err_msg"], State.m_strAuthKey, m_iDartAPIRetry)); return; } else if(strErrCode != "000") { - Util.Log(Util.LOG_TYPE.ERROR, string.Format("[DartAPI] {0} ({1})", jObj["err_msg"], m_iDartAPIRetry)); + Util.Log(Util.LOG_TYPE.ERROR, string.Format("[DartAPI] {0} (key:{1}, retry:{2})", jObj["err_msg"], State.m_strAuthKey, m_iDartAPIRetry)); m_iDartAPIRetry--; return; } @@ -475,7 +475,7 @@ namespace NewsCrawler m_Listener.InsertItem(strTitle, strCodeName, "", DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture), DateTime.Now, - strURL, "DART API", State.m_Timer.Elapsed.TotalMilliseconds, bInitial); + strURL, "DartAPI", State.m_Timer.Elapsed.TotalMilliseconds, bInitial); } } } diff --git a/CybosHelper.cs b/CybosHelper.cs index 42cdce3..13c82b5 100644 --- a/CybosHelper.cs +++ b/CybosHelper.cs @@ -17,9 +17,6 @@ namespace NewsCrawler CPSYSDIBLib.StockChart m_StockChart = new CPSYSDIBLib.StockChart(); bool m_bInitialized = false; - System.Timers.Timer m_timer = new System.Timers.Timer(); - ushort m_uiLastReqT = 0; - DSCBO1Lib.CpSvr8092S m_Cp8092S = new DSCBO1Lib.CpSvr8092S(); NewsForm m_Listener = null; @@ -53,10 +50,6 @@ namespace NewsCrawler break; } - m_timer.Interval = 1000; - m_timer.Elapsed += M_timer_Elapsed; - //m_timer.Start(); - m_Cp8092S.SetInputValue(0, "*"); m_Cp8092S.Received += Cp8092S_Received; m_Cp8092S.Subscribe(); @@ -82,52 +75,6 @@ namespace NewsCrawler //Console.WriteLine(string.Format("[8092S] {0} ({1}:{2})", strContents, strName, strCode)); } - private void M_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) - { - m_timer.Enabled = false; - - if(GetLimitRemainCountRQ() < 5) - return; - - CPSYSDIBLib.CpMarketWatch Watch = new CPSYSDIBLib.CpMarketWatch(); - Watch.SetInputValue(0, "*"); - Watch.SetInputValue(1, "1,2"); - Watch.SetInputValue(2, 0); - - Watch.BlockRequest2(0); - - ushort uiLatestT = 0; - int iCount = Watch.GetHeaderValue(2); - if(iCount > 0) - uiLatestT = Watch.GetDataValue(0, 0); - - for(int i = 0; i 0) - { - m_Listener.InsertItem(strContents, "", strCode, - DateTime.ParseExact(uiTime.ToString("0000"), "HHmm", CultureInfo.CurrentCulture), - DateTime.Now, - "", "CYBOS", 0, m_uiLastReqT>0); - } - - //Console.WriteLine(string.Format("[{0}][{1}] {2} ({3}:{4})", uiTime, uiType, strContents, strName, strCode)); - } - - m_uiLastReqT = uiLatestT; - - m_timer.Enabled = true; - } - public string[] GetAccounts() { return m_CPUtil.AccountNumber; diff --git a/ExcelHandler.cs b/ExcelHandler.cs new file mode 100644 index 0000000..06510d1 --- /dev/null +++ b/ExcelHandler.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using Excel = Microsoft.Office.Interop.Excel; +using System.Reflection; +namespace NewsCrawler +{ + public class ExcelHandler + { + bool m_bAvailable = false; + string m_strFileName = ""; + string m_strToday = DateTime.Now.ToString("yyyy-MM-dd"); + Excel.Application m_App = null; + + public ExcelHandler(string strFileName) + { + m_App = new Excel.Application(); + if(m_App == null) + { + Util.Log(Util.LOG_TYPE.ERROR, "엑셀이 설치되지 않음"); + m_bAvailable = false; + return; + } + + m_strFileName = strFileName; + } + + ~ExcelHandler() + { + Marshal.ReleaseComObject(m_App); + } + + public bool IsAvailable() + { + return m_bAvailable; + } + + private void Create() + { + Excel._Workbook Workbook = m_App.Workbooks.Add(Missing.Value); + Excel._Worksheet Worksheet = Workbook.ActiveSheet; + + Worksheet.Cells[1, 1] = "날짜"; + Worksheet.Cells[1, 2] = "기사 시간"; + Worksheet.Cells[1, 3] = "받은 시간"; + Worksheet.Cells[1, 4] = "출처"; + Worksheet.Cells[1, 5] = "제목"; + Worksheet.Cells[1, 6] = "요청 시간"; + Worksheet.Cells[1, 7] = "시가"; + Worksheet.Cells[1, 8] = "저가"; + Worksheet.Cells[1, 9] = "대비"; + Worksheet.Cells[1, 10] = "고가"; + Worksheet.Cells[1, 11] = "대비"; + Worksheet.Cells[1, 12] = "링크"; + + Workbook.SaveAs(m_strFileName, Excel.XlFileFormat.xlOpenXMLWorkbook, Missing.Value, + Missing.Value, false, false, Excel.XlSaveAsAccessMode.xlNoChange, + Excel.XlSaveConflictResolution.xlUserResolution, true, + Missing.Value, Missing.Value, Missing.Value); + Workbook.Close(); + } + + public void AddRow(string strNewsTime, string strResTime, string strRef, string strTitle, float fReqTime, int iPriceS, int iPriceLow, float fPriceLowP, int iPriceHigh, float fPriceHighP, string strLink) + { + if(m_bAvailable == false) + return; + + if(File.Exists(m_strFileName) == false) + Create(); + + + Excel._Workbook Workbook = m_App.Workbooks.Open(m_strFileName); + Excel._Worksheet Worksheet = Workbook.ActiveSheet; + + int iRow = Worksheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing).Row+1; + Worksheet.Cells[iRow, 1] = m_strToday; + Worksheet.Cells[iRow, 2] = strNewsTime; + Worksheet.Cells[iRow, 3] = strResTime; + Worksheet.Cells[iRow, 4] = strRef; + Worksheet.Cells[iRow, 5] = strTitle; + Worksheet.Cells[iRow, 6] = fReqTime; + Worksheet.Cells[iRow, 7] = iPriceS; + Worksheet.Cells[iRow, 8] = iPriceLow; + Worksheet.Cells[iRow, 9] = fPriceLowP; + Worksheet.Cells[iRow, 10] = iPriceHigh; + Worksheet.Cells[iRow, 11] = fPriceHighP; + Worksheet.Cells[iRow, 12] = strLink; + + Workbook.Save(); + Workbook.Close(); + } + } +} diff --git a/NewsCrawler.csproj b/NewsCrawler.csproj index e2ed01d..5b44f4d 100644 --- a/NewsCrawler.csproj +++ b/NewsCrawler.csproj @@ -89,6 +89,7 @@ + @@ -99,6 +100,7 @@ + Form @@ -212,6 +214,33 @@ False True + + {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52} + 2 + 4 + 0 + primary + False + True + + + {00020813-0000-0000-C000-000000000046} + 1 + 6 + 0 + primary + False + True + + + {0002E157-0000-0000-C000-000000000046} + 5 + 3 + 0 + primary + False + True + @@ -226,6 +255,15 @@ + + if NOT "$(ConfigurationName)" == "Release" (goto :nocopy) + +copy $(TargetPath) $(ProjectDir)publish\ /y +copy $(TargetDir)*.dll $(ProjectDir)publish\ /y + +:nocopy + +