From d074af571a93fc9a3ab8f39ee5357093c6b0860a Mon Sep 17 00:00:00 2001 From: mjjo53 Date: Thu, 7 Jun 2018 15:35:31 +0900 Subject: [PATCH] =?UTF-8?q?-=20elk=20update=20-=20=EB=AA=A8=EC=9D=98?= =?UTF-8?q?=ED=88=AC=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CodeList.cs | 24 +++++- Config.cs | 7 +- ConfigForm.Designer.cs | 74 ++++++++-------- ConfigForm.cs | 2 + Crawler.cs | 21 ++++- FluentFTP/Client/FtpClient_HighLevel.cs | 8 +- FluentFTP/Client/FtpClient_LowLevel.cs | 4 +- NewsForm.cs | 109 ++++++++++++++++++++++-- Program.cs | 14 +-- TextCondition.cs | 25 ++++++ 10 files changed, 228 insertions(+), 60 deletions(-) diff --git a/CodeList.cs b/CodeList.cs index dae291f..2f9a050 100644 --- a/CodeList.cs +++ b/CodeList.cs @@ -80,6 +80,9 @@ namespace NewsCrawler Console.WriteLine(SearchCode("[특징주] 에이치엘비-생명, 아파티닙 글로벌 임상 3상 최종 승인 소식에 상승세")); Console.WriteLine(SearchCode("진도군, 112건의 계약심사 통해 예산 10억원 절감")); + Console.WriteLine(SearchCode("[특징주] 브레인콘텐츠, 삼성전자 폴더블폰")); + Console.WriteLine(SearchCode("[아시아경제] 큐젠바이오텍, 미국 지사 설립 추진")); + Console.WriteLine("Test End"); } @@ -274,10 +277,10 @@ namespace NewsCrawler string strReplace = Regex.Replace(strText, @"(\[).*(\])", ""); strReplace = Regex.Replace(strReplace, @"(\().*(\))", ""); strReplace = Regex.Replace(strReplace, @"(\<).*(\>)", ""); - string[] words = strReplace.Trim().Split(' '); + string[] words = strReplace.Trim().Split(' ', ','); string strCodeWord = words[0]; - CODE_VALUE Result = m_CodeList.Find(s => strCodeWord.Contains(s.m_strName)); + CODE_VALUE Result = m_CodeList.Find(s => (s.m_strName == strCodeWord)); if(Result != null) return Result; @@ -306,5 +309,22 @@ namespace NewsCrawler CODE_VALUE Result = m_CodeList.Find(s => s.m_strName == strCodeName); return Result; } + + public List GetAllDeny() + { + return m_CodeList.Where(r => r.m_enType == CODE_TYPE.DENIAL).Select(c => c.m_strName).ToList(); + } + public List GetAllDuplicated() + { + return m_CodeList.Where(r => r.m_enType == CODE_TYPE.DUPLICATED).Select(c => c.m_strName).ToList(); + } + public List GetAllManual() + { + return m_CodeList.Where(r => r.m_enType == CODE_TYPE.MANUAL).Select(c => c.m_strName).ToList(); + } + public List GetAllSynonym() + { + return m_SynonymList.Select(r => $"{r.m_strName}={r.m_strName}").ToList(); + } } } diff --git a/Config.cs b/Config.cs index df769e5..e0d00b2 100644 --- a/Config.cs +++ b/Config.cs @@ -256,7 +256,7 @@ namespace NewsCrawler public static void SetMockTrading(bool bMock) { - m_Data.Add("mock-trading", bMock); + m_Data["mock-trading"] = bMock; Save(); } @@ -264,5 +264,10 @@ namespace NewsCrawler { return (bool)m_Data["mock-trading"]; } + + public static Dictionary GetAllConfig() + { + return m_Data; + } } } diff --git a/ConfigForm.Designer.cs b/ConfigForm.Designer.cs index 6faac06..8e1c5b4 100644 --- a/ConfigForm.Designer.cs +++ b/ConfigForm.Designer.cs @@ -36,6 +36,9 @@ this.groupBox1 = new System.Windows.Forms.GroupBox(); this.btnCodeManualEdit = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.groupBox13 = new System.Windows.Forms.GroupBox(); + this.btnDuplicatedKeywordApply = new System.Windows.Forms.Button(); + this.btnDuplicatedKeywordEdit = new System.Windows.Forms.Button(); this.groupBox6 = new System.Windows.Forms.GroupBox(); this.btnSynonymApply = new System.Windows.Forms.Button(); this.btnSynonymEdit = new System.Windows.Forms.Button(); @@ -79,11 +82,9 @@ this.tbAnSupplyContractRate = new System.Windows.Forms.TextBox(); this.label9 = new System.Windows.Forms.Label(); this.cbMockTrading = new System.Windows.Forms.CheckBox(); - this.groupBox13 = new System.Windows.Forms.GroupBox(); - this.btnDuplicatedKeywordApply = new System.Windows.Forms.Button(); - this.btnDuplicatedKeywordEdit = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); + this.groupBox13.SuspendLayout(); this.groupBox6.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox5.SuspendLayout(); @@ -94,7 +95,6 @@ this.groupBox10.SuspendLayout(); this.groupBox11.SuspendLayout(); this.groupBox12.SuspendLayout(); - this.groupBox13.SuspendLayout(); this.SuspendLayout(); // // tbVolume @@ -182,6 +182,37 @@ this.groupBox2.TabStop = false; this.groupBox2.Text = "키워드"; // + // groupBox13 + // + this.groupBox13.Controls.Add(this.btnDuplicatedKeywordApply); + this.groupBox13.Controls.Add(this.btnDuplicatedKeywordEdit); + this.groupBox13.Location = new System.Drawing.Point(190, 148); + this.groupBox13.Name = "groupBox13"; + this.groupBox13.Size = new System.Drawing.Size(165, 58); + this.groupBox13.TabIndex = 13; + this.groupBox13.TabStop = false; + this.groupBox13.Text = "중복 등록 문구"; + // + // btnDuplicatedKeywordApply + // + this.btnDuplicatedKeywordApply.Location = new System.Drawing.Point(86, 14); + this.btnDuplicatedKeywordApply.Name = "btnDuplicatedKeywordApply"; + this.btnDuplicatedKeywordApply.Size = new System.Drawing.Size(72, 39); + this.btnDuplicatedKeywordApply.TabIndex = 4; + this.btnDuplicatedKeywordApply.Text = "적용"; + this.btnDuplicatedKeywordApply.UseVisualStyleBackColor = true; + this.btnDuplicatedKeywordApply.Click += new System.EventHandler(this.btnDuplicatedKeywordApply_Click); + // + // btnDuplicatedKeywordEdit + // + this.btnDuplicatedKeywordEdit.Location = new System.Drawing.Point(8, 14); + this.btnDuplicatedKeywordEdit.Name = "btnDuplicatedKeywordEdit"; + this.btnDuplicatedKeywordEdit.Size = new System.Drawing.Size(72, 39); + this.btnDuplicatedKeywordEdit.TabIndex = 4; + this.btnDuplicatedKeywordEdit.Text = "편집"; + this.btnDuplicatedKeywordEdit.UseVisualStyleBackColor = true; + this.btnDuplicatedKeywordEdit.Click += new System.EventHandler(this.btnDuplicatedKeywordEdit_Click); + // // groupBox6 // this.groupBox6.Controls.Add(this.btnSynonymApply); @@ -627,7 +658,7 @@ this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(132, 12); this.label9.TabIndex = 20; - this.label9.Text = "Version : 2018.01.01.20"; + this.label9.Text = "Version : 2018.01.04.12"; // // cbMockTrading // @@ -640,37 +671,6 @@ this.cbMockTrading.UseVisualStyleBackColor = true; this.cbMockTrading.CheckedChanged += new System.EventHandler(this.cbMockTrading_CheckedChanged); // - // groupBox13 - // - this.groupBox13.Controls.Add(this.btnDuplicatedKeywordApply); - this.groupBox13.Controls.Add(this.btnDuplicatedKeywordEdit); - this.groupBox13.Location = new System.Drawing.Point(190, 148); - this.groupBox13.Name = "groupBox13"; - this.groupBox13.Size = new System.Drawing.Size(165, 58); - this.groupBox13.TabIndex = 13; - this.groupBox13.TabStop = false; - this.groupBox13.Text = "중복 등록 문구"; - // - // btnDuplicatedKeywordApply - // - this.btnDuplicatedKeywordApply.Location = new System.Drawing.Point(86, 14); - this.btnDuplicatedKeywordApply.Name = "btnDuplicatedKeywordApply"; - this.btnDuplicatedKeywordApply.Size = new System.Drawing.Size(72, 39); - this.btnDuplicatedKeywordApply.TabIndex = 4; - this.btnDuplicatedKeywordApply.Text = "적용"; - this.btnDuplicatedKeywordApply.UseVisualStyleBackColor = true; - this.btnDuplicatedKeywordApply.Click += new System.EventHandler(this.btnDuplicatedKeywordApply_Click); - // - // btnDuplicatedKeywordEdit - // - this.btnDuplicatedKeywordEdit.Location = new System.Drawing.Point(8, 14); - this.btnDuplicatedKeywordEdit.Name = "btnDuplicatedKeywordEdit"; - this.btnDuplicatedKeywordEdit.Size = new System.Drawing.Size(72, 39); - this.btnDuplicatedKeywordEdit.TabIndex = 4; - this.btnDuplicatedKeywordEdit.Text = "편집"; - this.btnDuplicatedKeywordEdit.UseVisualStyleBackColor = true; - this.btnDuplicatedKeywordEdit.Click += new System.EventHandler(this.btnDuplicatedKeywordEdit_Click); - // // ConfigForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); @@ -693,6 +693,7 @@ this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); + this.groupBox13.ResumeLayout(false); this.groupBox6.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.groupBox5.ResumeLayout(false); @@ -706,7 +707,6 @@ this.groupBox11.PerformLayout(); this.groupBox12.ResumeLayout(false); this.groupBox12.PerformLayout(); - this.groupBox13.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); diff --git a/ConfigForm.cs b/ConfigForm.cs index c35a0f4..1808c33 100644 --- a/ConfigForm.cs +++ b/ConfigForm.cs @@ -29,6 +29,8 @@ namespace NewsCrawler tbAnSupplyContractRate.Text = Config.GetSupplyContractRate().ToString(); tbAnRevenueRate.Text = Config.GetRevenueRate().ToString(); + + cbMockTrading.Checked = Config.GetMockTrading(); } private void OpenFile(string strName) diff --git a/Crawler.cs b/Crawler.cs index a8bd57a..702927f 100644 --- a/Crawler.cs +++ b/Crawler.cs @@ -78,7 +78,10 @@ namespace NewsCrawler foreach(var item in lists) { string strTitle1 = item.SelectSingleNode(".//a").GetAttributeValue("title", ""); - string strTitle2 = item.SelectSingleNode(".//a").FirstChild.InnerText; + var child = item.SelectSingleNode(".//a").FirstChild; + string strTitle2 = ""; + if (child != null) + strTitle2 = child.InnerText; string strTitle = (strTitle1.Length > strTitle2.Length ? strTitle1 : strTitle2); string strTime = item.SelectSingleNode(".//span").InnerText; string strURL = strServerURL+item.SelectSingleNode(".//a").GetAttributeValue("href", ""); @@ -309,6 +312,8 @@ namespace NewsCrawler using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"))) { string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd()); + if (responseFromServer.Contains("정정")) + Console.WriteLine(""); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(responseFromServer); @@ -389,6 +394,8 @@ namespace NewsCrawler using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"))) { string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd()); + if (responseFromServer.Contains("정정")) + Console.WriteLine(""); dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer); string strBody = jObj["reportBody"]; @@ -464,6 +471,8 @@ namespace NewsCrawler using (StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"))) { string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd()); + if (responseFromServer.Contains("정정")) + Console.WriteLine(""); dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer); string strBody = jObj["reportBody"]; @@ -541,6 +550,8 @@ namespace NewsCrawler using (StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"))) { string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd()); + if (responseFromServer.Contains("정정")) + Console.WriteLine(""); dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer); string strBody = jObj["reportBody"]; @@ -613,6 +624,8 @@ namespace NewsCrawler using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"))) { string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd()); + if (responseFromServer.Contains("정정")) + Console.WriteLine(""); dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer); string strBody = jObj["reportBody"]; @@ -686,6 +699,8 @@ namespace NewsCrawler using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"))) { string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd()); + if (responseFromServer.Contains("정정")) + Console.WriteLine(""); dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer); string strBody = jObj["reportBody"]; @@ -770,6 +785,8 @@ namespace NewsCrawler using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"))) { string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd()); + if (responseFromServer.Contains("정정")) + Console.WriteLine(""); dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer); string strErrCode = jObj["err_code"]; @@ -900,6 +917,8 @@ namespace NewsCrawler using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"))) { string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd()); + if (responseFromServer.Contains("정정")) + Console.WriteLine(""); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(responseFromServer); diff --git a/FluentFTP/Client/FtpClient_HighLevel.cs b/FluentFTP/Client/FtpClient_HighLevel.cs index 3af6228..402820c 100644 --- a/FluentFTP/Client/FtpClient_HighLevel.cs +++ b/FluentFTP/Client/FtpClient_HighLevel.cs @@ -1067,7 +1067,7 @@ namespace FluentFTP { // seek to required offset fileData.Position = offset; - } catch (Exception ex2) { + } catch (Exception) { } } @@ -1208,11 +1208,11 @@ namespace FluentFTP { Stream upStream = null; try { long offset = 0; - bool checkFileExistsAgain = false; + //bool checkFileExistsAgain = false; // check if the file exists, and skip, overwrite or append if (existsMode == FtpExists.NoCheck) { - checkFileExistsAgain = true; + //checkFileExistsAgain = true; } else { if (!fileExistsKnown) { fileExists = await FileExistsAsync(remotePath); @@ -1254,7 +1254,7 @@ namespace FluentFTP { // seek to required offset fileData.Position = offset; - } catch (Exception ex2) { + } catch (Exception) { } } diff --git a/FluentFTP/Client/FtpClient_LowLevel.cs b/FluentFTP/Client/FtpClient_LowLevel.cs index 7475fd3..64ef603 100644 --- a/FluentFTP/Client/FtpClient_LowLevel.cs +++ b/FluentFTP/Client/FtpClient_LowLevel.cs @@ -313,7 +313,7 @@ namespace FluentFTP { try { stream.Listen(m_stream.LocalEndPoint.Address, port); success = true; - } catch (SocketException se) { + } catch (SocketException) { #if NETFX // Already in use if (se.ErrorCode != 10048) @@ -448,7 +448,7 @@ namespace FluentFTP { stream.Listen(m_stream.LocalEndPoint.Address, port); success = true; } - catch (SocketException se) + catch (SocketException) { #if NETFX // Already in use diff --git a/NewsForm.cs b/NewsForm.cs index 57bba25..771ff5e 100644 --- a/NewsForm.cs +++ b/NewsForm.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json.Linq; +using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; @@ -9,6 +10,7 @@ using System.Globalization; using System.IO; using System.Linq; using System.Net; +using System.Net.Http; using System.Net.NetworkInformation; using System.Text; using System.Text.RegularExpressions; @@ -819,8 +821,13 @@ namespace NewsCrawler return; string strCodeName = lvList.SelectedItems[0].SubItems[chCodeName.Index].Text; + string strTitle = lvList.SelectedItems[0].SubItems[chTitle.Index].Text; CodeList.CODE_VALUE Code = m_CodeList.GetCodeByName(strCodeName); - m_CybosHelper.Buy(Code, Config.GetBuyPrice()); + if (Code == null) + Code = m_CodeList.SearchCode(strTitle); + + if (Code != null) + ProcessSearchAndBuy(new NEWS_ITEM(-1, strTitle, Code.m_strCode, Code, DateTime.Now, DateTime.Now, "", "", 0)); } public void OnConfigFormClosing() @@ -872,6 +879,94 @@ namespace NewsCrawler Util.Clear(); } + public class HttpResult + { + public HttpStatusCode StatusCode; + public string strData; + }; + + async Task Request(string url, HttpMethod method, + string data = null, + Dictionary headers = null) + { + HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); + req.Method = method.ToString(); + req.ContentType = "application/json"; + if(headers != null) + { + foreach (var kv in headers) + req.Headers[kv.Key] = kv.Value; + } + + if (data != null) + { + Stream writeStream = req.GetRequestStream(); + byte[] buffer = Encoding.UTF8.GetBytes(data); + await writeStream.WriteAsync(buffer, 0, buffer.Length); + } + + HttpWebResponse resp = null; + HttpResult result = null; + try + { + resp = await req.GetResponseAsync() as HttpWebResponse; + } + catch (WebException ex) + { + if (ex.Status == WebExceptionStatus.ProtocolError) + resp = ex.Response as HttpWebResponse; + } + finally + { + Stream readStream = resp.GetResponseStream(); + StreamReader sr = new StreamReader(readStream); + result = new HttpResult() + { + StatusCode = resp.StatusCode, + strData = await sr.ReadToEndAsync() + }; + } + + return result; + } + + async void SendConfiguration() + { + var oData = new + { + Mac = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString(), + Date = DateTime.Now.ToString("yyyy-MM-dd"), + Config = Config.GetAllConfig(), + Keywords = new + { + Positive = m_Condition.GetAllPositive(), + PositiveForce = m_Condition.GetAllPositiveForce(), + Negative = m_Condition.GetAllNegative(), + Manual = m_Condition.GetAllManual(), + Duplicated = m_Condition.GetAllDuplicated(), + }, + Codes = new + { + Deny = m_CodeList.GetAllDeny(), + Duplicated = m_CodeList.GetAllDuplicated(), + Manual = m_CodeList.GetAllManual(), + }, + Synonym = m_CodeList.GetAllSynonym(), + }; + + string serverURL = "http://mjjo53.us.to:9200"; + string index = "trading-news"; + string doc = "default"; + string id = $"{oData.Mac}-{oData.Date}"; + JObject data = JObject.FromObject(oData); + string json = data.ToString(Newtonsoft.Json.Formatting.Indented); + + Dictionary headers = new Dictionary(); + headers["Authorization"] = "Basic dHJhZGVyOnNidG1hb2Fv"; + + var result = await Request($"{serverURL}/{index}/{doc}/{id}?pretty", HttpMethod.Post, json, headers); + } + private void chBuy_CheckedChanged(object sender, EventArgs e) { m_bBuy = chBuy.Checked; @@ -885,10 +980,12 @@ namespace NewsCrawler if (m_bBuy == true) { - FileTransfer ft = new FileTransfer(); - string today = DateTime.Now.ToString("yyyy-MM-dd"); - string macAddr = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString(); - ft.SendDir("/configure", macAddr + "/NewsCrawler/" + today); + //FileTransfer ft = new FileTransfer(); + //string today = DateTime.Now.ToString("yyyy-MM-dd"); + //string macAddr = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString(); + //ft.SendDir("/configure", macAddr + "/NewsCrawler/" + today); + + SendConfiguration(); Util.Log(Util.LOG_TYPE.VERVOSE, "매수 시작"); } diff --git a/Program.cs b/Program.cs index 3453231..0a6b81a 100644 --- a/Program.cs +++ b/Program.cs @@ -14,16 +14,16 @@ namespace NewsCrawler [STAThread] static void Main() { - try - { + //try + //{ Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new NewsForm()); - } - catch(Exception ex) - { - Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); - } + //} + //catch(Exception ex) + //{ + // Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); + //} } } } diff --git a/TextCondition.cs b/TextCondition.cs index b220c63..4f7ed24 100644 --- a/TextCondition.cs +++ b/TextCondition.cs @@ -245,5 +245,30 @@ namespace NewsCrawler Regex result = m_Duplicated.Find(s => s.IsMatch(strText)); return (result != null); } + + public List GetAllPositive() + { + return m_Positive.Select(a => a.ToString()).ToList(); + } + + public List GetAllPositiveForce() + { + return m_PositiveForce.Select(a => a.ToString()).ToList(); + } + + public List GetAllNegative() + { + return m_Negative.Select(a => a.ToString()).ToList(); + } + + public List GetAllManual() + { + return m_Manual.Select(a => a.ToString()).ToList(); + } + + public List GetAllDuplicated() + { + return m_Duplicated.Select(a => a.ToString()).ToList(); + } } }