- KIND 추가

- lock 추가
This commit is contained in:
2016-08-02 23:53:25 +09:00
parent 08e6ff57cd
commit 865e5f7ec9
2 changed files with 257 additions and 156 deletions

301
Form1.Designer.cs generated
View File

@@ -28,161 +28,164 @@
/// </summary>
private void InitializeComponent()
{
this.lvList = new System.Windows.Forms.ListView();
this.chTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chTitle = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chCodeName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chCode = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chReference = ((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();
this.chAutoReload = new System.Windows.Forms.CheckBox();
this.chAutoSelect = new System.Windows.Forms.CheckBox();
this.tbInterval = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// lvList
//
this.lvList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.lvList = new System.Windows.Forms.ListView();
this.chTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chTitle = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chCodeName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chCode = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chReference = ((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();
this.chAutoReload = new System.Windows.Forms.CheckBox();
this.chAutoSelect = new System.Windows.Forms.CheckBox();
this.tbInterval = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// lvList
//
this.lvList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.chTime,
this.chTitle,
this.chCodeName,
this.chCode,
this.chReference,
this.chLink});
this.lvList.Dock = System.Windows.Forms.DockStyle.Fill;
this.lvList.FullRowSelect = true;
this.lvList.GridLines = true;
this.lvList.HideSelection = false;
this.lvList.Location = new System.Drawing.Point(0, 0);
this.lvList.MultiSelect = false;
this.lvList.Name = "lvList";
this.lvList.Size = new System.Drawing.Size(864, 157);
this.lvList.TabIndex = 0;
this.lvList.UseCompatibleStateImageBehavior = false;
this.lvList.View = System.Windows.Forms.View.Details;
this.lvList.SelectedIndexChanged += new System.EventHandler(this.lvList_SelectedIndexChanged);
//
// chTime
//
this.chTime.Text = "시간";
//
// chTitle
//
this.chTitle.Text = "제목";
this.chTitle.Width = 366;
//
// chCodeName
//
this.chCodeName.Text = "종목명";
//
// chCode
//
this.chCode.Text = "종목코드";
//
// chReference
//
this.chReference.Text = "출처";
this.chReference.Width = 72;
//
// chLink
//
this.chLink.Text = "링크";
this.chLink.Width = 241;
//
// wbView
//
this.wbView.Dock = System.Windows.Forms.DockStyle.Fill;
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(864, 644);
this.wbView.TabIndex = 1;
//
// splitContainer1
//
this.splitContainer1.Location = new System.Drawing.Point(0, 25);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.lvList);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.wbView);
this.splitContainer1.Size = new System.Drawing.Size(864, 805);
this.splitContainer1.SplitterDistance = 157;
this.splitContainer1.TabIndex = 2;
//
// chAutoReload
//
this.chAutoReload.AutoSize = true;
this.chAutoReload.Checked = true;
this.chAutoReload.CheckState = System.Windows.Forms.CheckState.Checked;
this.chAutoReload.Location = new System.Drawing.Point(3, 4);
this.chAutoReload.Name = "chAutoReload";
this.chAutoReload.Size = new System.Drawing.Size(76, 16);
this.chAutoReload.TabIndex = 3;
this.chAutoReload.Text = "자동 갱신";
this.chAutoReload.UseVisualStyleBackColor = true;
//
// chAutoSelect
//
this.chAutoSelect.AutoSize = true;
this.chAutoSelect.Checked = true;
this.chAutoSelect.CheckState = System.Windows.Forms.CheckState.Checked;
this.chAutoSelect.Location = new System.Drawing.Point(85, 4);
this.chAutoSelect.Name = "chAutoSelect";
this.chAutoSelect.Size = new System.Drawing.Size(76, 16);
this.chAutoSelect.TabIndex = 4;
this.chAutoSelect.Text = "자동 선택";
this.chAutoSelect.UseVisualStyleBackColor = true;
//
// tbInterval
//
this.tbInterval.Location = new System.Drawing.Point(226, 2);
this.tbInterval.Name = "tbInterval";
this.tbInterval.Size = new System.Drawing.Size(42, 21);
this.tbInterval.TabIndex = 5;
this.tbInterval.Text = "0.5초";
this.tbInterval.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tbInterval.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbInterval_KeyPress);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(167, 5);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(53, 12);
this.label1.TabIndex = 6;
this.label1.Text = "갱신주기";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(864, 829);
this.Controls.Add(this.label1);
this.Controls.Add(this.tbInterval);
this.Controls.Add(this.chAutoSelect);
this.Controls.Add(this.chAutoReload);
this.Controls.Add(this.splitContainer1);
this.Name = "Form1";
this.Text = "News Crawler";
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
this.lvList.Dock = System.Windows.Forms.DockStyle.Fill;
this.lvList.FullRowSelect = true;
this.lvList.GridLines = true;
this.lvList.HideSelection = false;
this.lvList.Location = new System.Drawing.Point(0, 0);
this.lvList.MultiSelect = false;
this.lvList.Name = "lvList";
this.lvList.Size = new System.Drawing.Size(864, 157);
this.lvList.TabIndex = 0;
this.lvList.UseCompatibleStateImageBehavior = false;
this.lvList.View = System.Windows.Forms.View.Details;
this.lvList.SelectedIndexChanged += new System.EventHandler(this.lvList_SelectedIndexChanged);
//
// chTime
//
this.chTime.Text = "시간";
//
// chTitle
//
this.chTitle.Text = "제목";
this.chTitle.Width = 366;
//
// chCodeName
//
this.chCodeName.Text = "종목명";
//
// chCode
//
this.chCode.Text = "종목코드";
//
// chReference
//
this.chReference.Text = "출처";
this.chReference.Width = 72;
//
// chLink
//
this.chLink.Text = "링크";
this.chLink.Width = 241;
//
// wbView
//
this.wbView.Dock = System.Windows.Forms.DockStyle.Fill;
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(864, 644);
this.wbView.TabIndex = 1;
//
// splitContainer1
//
this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.splitContainer1.Location = new System.Drawing.Point(0, 25);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.lvList);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.wbView);
this.splitContainer1.Size = new System.Drawing.Size(864, 805);
this.splitContainer1.SplitterDistance = 157;
this.splitContainer1.TabIndex = 2;
//
// chAutoReload
//
this.chAutoReload.AutoSize = true;
this.chAutoReload.Checked = true;
this.chAutoReload.CheckState = System.Windows.Forms.CheckState.Checked;
this.chAutoReload.Location = new System.Drawing.Point(3, 4);
this.chAutoReload.Name = "chAutoReload";
this.chAutoReload.Size = new System.Drawing.Size(76, 16);
this.chAutoReload.TabIndex = 3;
this.chAutoReload.Text = "자동 갱신";
this.chAutoReload.UseVisualStyleBackColor = true;
//
// chAutoSelect
//
this.chAutoSelect.AutoSize = true;
this.chAutoSelect.Checked = true;
this.chAutoSelect.CheckState = System.Windows.Forms.CheckState.Checked;
this.chAutoSelect.Location = new System.Drawing.Point(85, 4);
this.chAutoSelect.Name = "chAutoSelect";
this.chAutoSelect.Size = new System.Drawing.Size(76, 16);
this.chAutoSelect.TabIndex = 4;
this.chAutoSelect.Text = "자동 선택";
this.chAutoSelect.UseVisualStyleBackColor = true;
//
// tbInterval
//
this.tbInterval.Location = new System.Drawing.Point(226, 2);
this.tbInterval.Name = "tbInterval";
this.tbInterval.Size = new System.Drawing.Size(42, 21);
this.tbInterval.TabIndex = 5;
this.tbInterval.Text = "0.5초";
this.tbInterval.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tbInterval.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbInterval_KeyPress);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(167, 5);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(53, 12);
this.label1.TabIndex = 6;
this.label1.Text = "갱신주기";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(864, 829);
this.Controls.Add(this.label1);
this.Controls.Add(this.tbInterval);
this.Controls.Add(this.chAutoSelect);
this.Controls.Add(this.chAutoReload);
this.Controls.Add(this.splitContainer1);
this.Name = "Form1";
this.Text = "News Crawler";
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}

112
Form1.cs
View File

@@ -90,10 +90,17 @@ namespace NewsCrawler
news.m_strURL=strURL;
news.m_strReference="아시아경제";
m_ItemList.Add(news);
lock(m_ItemList)
{
m_ItemList.Add(news);
}
bHasNew=true;
}
else
{
break;
}
}
}
@@ -152,10 +159,17 @@ namespace NewsCrawler
news.m_strURL=strURL;
news.m_strReference="이투데이";
m_ItemList.Add(news);
lock(m_ItemList)
{
m_ItemList.Add(news);
}
bHasNew=true;
}
else
{
break;
}
}
}
}
@@ -217,13 +231,20 @@ namespace NewsCrawler
news.m_strTitle=strTitle;
news.m_Time=DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture);
news.m_strURL=strURL;
news.m_strReference="전자공시";
news.m_strReference="DART";
m_ItemList.Add(news);
lock(m_ItemList)
{
m_ItemList.Add(news);
}
bHasNew=true;
bHasNew=true;
}
}
else
{
break;
}
}
}
}
}
@@ -236,12 +257,86 @@ namespace NewsCrawler
return bHasNew;
}
bool ReadKIND()
{
bool bHasNew = false;
try
{
//string strServerURL = "https://dart.fss.or.kr";
WebRequest request = WebRequest.Create("http://kind.krx.co.kr/disclosure/rsstodaydistribute.do?method=searchRssTodayDistribute&repIsuSrtCd=&mktTpCd=0&searchCorpName=&currentPageSize=1000");
request.Credentials=CredentialCache.DefaultCredentials;
request.Timeout=2000;
int iCDATALen = "<![CDATA[".Length;
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using(Stream dataStream = response.GetResponseStream())
{
using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(responseFromServer);
string strXPath = "//item";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
string strTitle = item.SelectSingleNode(".//title").InnerText;
strTitle = strTitle.Substring(iCDATALen, strTitle.Length-iCDATALen-3);
string strTime = item.ChildNodes["pubDate"].InnerText;
DateTime time = Convert.ToDateTime(strTime);
strTime = time.ToString("HH:mm:ss");
string strURL = item.ChildNodes["link"].NextSibling.InnerText;
strURL = strURL.Substring(iCDATALen, strURL.Length-iCDATALen-3);
if(Regex.IsMatch(strTime, @"\d+/\d+")==true)
{
//Console.WriteLine("어제 기사 : " + item.InnerHtml);
continue;
}
if(m_ItemList.Any(c => c.m_strURL==strURL)==false)
{
NEWS_ITEM news = new NEWS_ITEM();
news.m_strTitle=strTitle;
news.m_Time=DateTime.ParseExact(strTime, "HH:mm:ss", CultureInfo.CurrentCulture);
news.m_strURL=strURL;
news.m_strReference="KIND";
lock(m_ItemList)
{
m_ItemList.Add(news);
}
bHasNew=true;
}
else
{
break;
}
}
}
}
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
return bHasNew;
}
private void CrawlTimer_Tick(object sender, EventArgs e)
{
m_CrawlTimer.Enabled = false;
if(chAutoReload.Checked == true)
{
ReadKIND();
ReadDart();
ReadAsiaE();
ReadEtoday();
@@ -256,7 +351,10 @@ namespace NewsCrawler
if (m_iLastItemCnt == m_ItemList.Count)
return;
m_ItemList.Sort((NEWS_ITEM news1, NEWS_ITEM news2) => news1.m_Time.CompareTo(news2.m_Time));
lock(m_ItemList)
{
m_ItemList.Sort((NEWS_ITEM news1, NEWS_ITEM news2) => news1.m_Time.CompareTo(news2.m_Time));
}
foreach (var item in m_ItemList)
{