diff --git a/CodeList.cs b/CodeList.cs index c1027f8..e10a733 100644 --- a/CodeList.cs +++ b/CodeList.cs @@ -118,6 +118,11 @@ namespace NewsCrawler LoadCodeType(strPath, CODE_TYPE.DUPLICATED); } + public bool IsBuyableCode(CODE_VALUE Code) + { + return ((Code.m_enType & CODE_TYPE.DENIAL) | (Code.m_enType & CODE_TYPE.DUPLICATED)) == CODE_TYPE.NONE; + } + public void AddDuplicatedList(string strCode, string strName) { CODE_VALUE Result = m_CodeList.Find(s => s.m_strCode == strCode); @@ -225,5 +230,11 @@ namespace NewsCrawler return m_CodeList.Find(s => s.m_strCode == Synonym.m_strCode); } + + public CODE_VALUE GetCode(string strCode) + { + CODE_VALUE Result = m_CodeList.Find(s => s.m_strCode == strCode); + return Result; + } } } diff --git a/CybosHelper.cs b/CybosHelper.cs index a374557..24cd5c5 100644 --- a/CybosHelper.cs +++ b/CybosHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Threading; @@ -15,8 +16,15 @@ namespace NewsCrawler CPTRADELib.CpTd0311 m_CP0311 = new CPTRADELib.CpTd0311(); bool m_bInitialized = false; - public CybosHelper() + System.Timers.Timer m_timer = new System.Timers.Timer(); + ushort m_uiLastReqT = 0; + + NewsForm m_Listener = null; + + public CybosHelper(NewsForm Listener) { + m_Listener = Listener; + short iResult = m_CPUtil.TradeInit(); switch(iResult) { @@ -41,6 +49,56 @@ namespace NewsCrawler Util.Log(Util.LOG_TYPE.ERROR, "[TradeInit] 취소되었습니다"); break; } + + m_timer.Interval = 1000; + m_timer.Elapsed += M_timer_Elapsed; + m_timer.Start(); + } + + private void M_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + m_timer.Enabled = false; + + if(GetLimitRemainCountTrace() < 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() diff --git a/NewsForm.Designer.cs b/NewsForm.Designer.cs index b0e92f2..47646d1 100644 --- a/NewsForm.Designer.cs +++ b/NewsForm.Designer.cs @@ -32,6 +32,7 @@ this.chTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chTitle = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chReference = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.chResponseT = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chLink = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.wbView = new System.Windows.Forms.WebBrowser(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); @@ -43,6 +44,7 @@ this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.tbLog = new System.Windows.Forms.RichTextBox(); this.chBuy = new System.Windows.Forms.CheckBox(); + this.chResT = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -57,8 +59,10 @@ // this.lvList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.chTime, - this.chTitle, + this.chResT, this.chReference, + this.chTitle, + this.chResponseT, this.chLink}); this.lvList.Dock = System.Windows.Forms.DockStyle.Fill; this.lvList.FullRowSelect = true; @@ -67,7 +71,7 @@ this.lvList.Location = new System.Drawing.Point(0, 0); this.lvList.MultiSelect = false; this.lvList.Name = "lvList"; - this.lvList.Size = new System.Drawing.Size(862, 123); + this.lvList.Size = new System.Drawing.Size(862, 603); this.lvList.TabIndex = 0; this.lvList.UseCompatibleStateImageBehavior = false; this.lvList.View = System.Windows.Forms.View.Details; @@ -88,6 +92,11 @@ this.chReference.Text = "출처"; this.chReference.Width = 72; // + // chResponseT + // + this.chResponseT.Text = "요청 시간"; + this.chResponseT.Width = 69; + // // chLink // this.chLink.Text = "링크"; @@ -99,7 +108,7 @@ this.wbView.Location = new System.Drawing.Point(0, 0); this.wbView.MinimumSize = new System.Drawing.Size(20, 20); this.wbView.Name = "wbView"; - this.wbView.Size = new System.Drawing.Size(862, 507); + this.wbView.Size = new System.Drawing.Size(862, 27); this.wbView.TabIndex = 1; // // splitContainer1 @@ -117,7 +126,7 @@ // this.splitContainer1.Panel2.Controls.Add(this.wbView); this.splitContainer1.Size = new System.Drawing.Size(862, 634); - this.splitContainer1.SplitterDistance = 123; + this.splitContainer1.SplitterDistance = 603; this.splitContainer1.TabIndex = 2; // // chAutoReload @@ -218,6 +227,11 @@ this.chBuy.UseVisualStyleBackColor = true; this.chBuy.CheckedChanged += new System.EventHandler(this.chBuy_CheckedChanged); // + // chResT + // + this.chResT.Text = "받은 시간"; + this.chResT.Width = 66; + // // NewsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); @@ -263,6 +277,8 @@ private System.Windows.Forms.SplitContainer splitContainer2; private System.Windows.Forms.RichTextBox tbLog; private System.Windows.Forms.CheckBox chBuy; + private System.Windows.Forms.ColumnHeader chResponseT; + private System.Windows.Forms.ColumnHeader chResT; } } diff --git a/NewsForm.cs b/NewsForm.cs index 2141c82..e068333 100644 --- a/NewsForm.cs +++ b/NewsForm.cs @@ -22,8 +22,6 @@ namespace NewsCrawler TextCondition m_Condition = null; ConfigForm m_ConfigForm = null; - delegate void InsertListView(string strTitle, DateTime time, string strURL, string strRef, bool bInitial); - System.Timers.Timer m_CrawlTimer = new System.Timers.Timer(); int m_iCrawlInterval = 500; bool m_bBrowserReload = false; @@ -39,6 +37,7 @@ namespace NewsCrawler Util.SetLogView(tbLog); m_CodeList = new CodeList(); m_Condition = new TextCondition(); + MessageBox.Show("Keywords : \n\n" + m_Condition.GetKeywordsCnt()); wbView.ScriptErrorsSuppressed = false; @@ -46,6 +45,7 @@ namespace NewsCrawler ReadKIND(true); ReadDart(true); ReadEtoday(true); + ReadEToday2(true); ReadAsiaE(true); ReadEdaily(true); ReadMoneyToday(true); @@ -71,7 +71,7 @@ namespace NewsCrawler m_CrawlTimer.Start(); - m_CybosHelper = new CybosHelper(); + m_CybosHelper = new CybosHelper(this); Test(); } @@ -81,10 +81,10 @@ namespace NewsCrawler if(Util.IsDebugging() == false) return; - InsertItem("[test] 덕산하이메탈, 덕산네오룩스 66만여주 취득14:38", new DateTime(2016, 11, 30, 00, 00, 00), "http://www.asiae.co.kr/news/sokbo/sokbo_view.htm?idxno=2016112914371817318", "asiae", false); - InsertItem("[test] 자연과환경, 12월15일~22일 주주명부폐쇄14:19", new DateTime(2016, 11, 30, 00, 00, 00), "http://www.asiae.co.kr/news/sokbo/sokbo_view.htm?idxno=2016112914193170301", "asiae", false); - InsertItem("[test] 이엠코리아, 한국항공우주산업과 3억원 규모 공급계약14:06", new DateTime(2016, 11, 30, 00, 00, 00), "http://www.asiae.co.kr/news/sokbo/sokbo_view.htm?idxno=2016112914055964082", "asiae", false); - + InsertItem("[test] 덕산하이메탈, 덕산네오룩스 66만여주 취득14:38", "", "", new DateTime(2016, 11, 30, 00, 00, 00), DateTime.Now, "http://www.asiae.co.kr/news/sokbo/sokbo_view.htm?idxno=2016112914371817318", "asiae", 0, false); + InsertItem("[test] 자연과환경, 12월15일~22일 주주명부폐쇄14:19", "", "", new DateTime(2016, 11, 30, 00, 00, 00), DateTime.Now, "http://www.asiae.co.kr/news/sokbo/sokbo_view.htm?idxno=2016112914193170301", "asiae", 0, false); + InsertItem("[test] 이엠코리아, 한국항공우주산업과 3억원 규모 공급계약14:06", "", "", new DateTime(2016, 11, 30, 00, 00, 00), DateTime.Now, "http://www.asiae.co.kr/news/sokbo/sokbo_view.htm?idxno=2016112914055964082", "asiae", 0, false); + InsertItem("[test] [특징주] 진원생명과학, 국외 AI 인체감염증...", "", "", new DateTime(2016, 11, 30, 00, 00, 00), DateTime.Now, "http://www.etoday.co.kr/news/sokbo/sokbo_view.htm?idxno=2016112914055964082", "이투데이", 0, false); } private void BuyItem(CodeList.CODE_VALUE Code) @@ -92,8 +92,11 @@ namespace NewsCrawler if(m_bBuy == false) return; - m_CybosHelper.Buy(Code, Config.GetBuyPrice()); - m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName); + if(m_CodeList.IsBuyableCode(Code) == true) + { + m_CybosHelper.Buy(Code, Config.GetBuyPrice()); + m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName); + } } public void OnManualItemBuy(CodeList.CODE_VALUE Code) @@ -101,9 +104,14 @@ namespace NewsCrawler BuyItem(Code); } - void ProcessSearchAndBuy(string strTitle, string strRef) + void ProcessSearchAndBuy(string strTitle, string strName, string strCode, string strRef) { - CodeList.CODE_VALUE Code = m_CodeList.SearchCode(strTitle); + CodeList.CODE_VALUE Code; + if(strCode == "") + Code = m_CodeList.SearchCode(strTitle); + else + Code = m_CodeList.GetCode(strCode); + if(Code != null) { TextCondition.RESULT MatchResult = m_Condition.Match(strTitle); @@ -148,24 +156,21 @@ namespace NewsCrawler } } - private void InsertItem(string strTitle, DateTime time, string strURL, string strRef, bool bInitial) + delegate void InsertListView(string strTitle, string strName, string strCode, DateTime time, DateTime ResTime, string strURL, string strRef, double responseT, bool bInitial); + public void InsertItem(string strTitle, string strName, string strCode, DateTime time, DateTime ResTime, string strURL, string strRef, double responseT, bool bInitial) { try { if(this.InvokeRequired) { - this.Invoke(new InsertListView(InsertItem), strTitle, time, strURL, strRef, bInitial); + this.Invoke(new InsertListView(InsertItem), strTitle, strName, strCode, time, ResTime, strURL, strRef, responseT, bInitial); } else { - foreach(ListViewItem item in lvList.Items) - { - if(item.SubItems[chLink.Index].Text == strURL) - return; - } - - lvList.Items.Add(new ListViewItem(new string[] { time.ToString("HH:mm:ss"), strTitle, strRef, strURL })); + if(lvList.Items.Cast().Any(s => s.SubItems[chLink.Index].Text == strURL)) + return; + lvList.Items.Add(new ListViewItem(new string[] { time.ToString("HH:mm:ss"), ResTime.ToString("HH:mm:ss"), strRef, strTitle, string.Format("{0} ms", responseT), strURL })); if(bInitial == false && chAutoSelect.Checked == true) { @@ -179,7 +184,7 @@ namespace NewsCrawler if(bInitial == false) { lvList.Sort(); - ProcessSearchAndBuy(strTitle, strRef); + ProcessSearchAndBuy(strTitle, strName, strCode, strRef); } } } @@ -200,8 +205,12 @@ namespace NewsCrawler request.Credentials=CredentialCache.DefaultCredentials; request.Timeout=2000; + System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); + timer.Start(); using(HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { + timer.Stop(); + using(Stream dataStream = response.GetResponseStream()) { using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("EUC-KR"))) @@ -228,7 +237,10 @@ namespace NewsCrawler continue; } - InsertItem(strTitle, DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture), strURL, "아시아경제", bInitial); + InsertItem(strTitle, "", "", + DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture), + DateTime.Now, + strURL, "아시아경제", timer.Elapsed.TotalMilliseconds, bInitial); } } @@ -254,8 +266,12 @@ namespace NewsCrawler request.Credentials=CredentialCache.DefaultCredentials; request.Timeout=2000; + System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); + timer.Start(); using(HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { + timer.Stop(); + using(Stream dataStream = response.GetResponseStream()) { using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"))) @@ -279,7 +295,75 @@ namespace NewsCrawler continue; } - InsertItem(strTitle, DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture), strURL, "이투데이", bInitial); + InsertItem(strTitle, "", "", + DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture), + DateTime.Now, + strURL, "이투데이", timer.Elapsed.TotalMilliseconds, bInitial); + } + } + } + } + } + catch(Exception e) + { + Console.WriteLine(e.ToString()); + } + + return bHasNew; + } + + bool ReadEToday2(bool bInitial = false) + { + bool bHasNew = false; + + try + { + WebRequest request = WebRequest.Create("http://rss.etoday.co.kr/etoday/etoday_news_all.xml"); + request.Credentials=CredentialCache.DefaultCredentials; + request.Timeout=2000; + int iCDATALen = "