- 이투데이 rss 추가

- 요청 시간, 받은 시간 추가
- CYBOS 뉴스 추가
- 중복종목 버그 수정
- 실행시 키워드 수 추가
This commit is contained in:
2016-12-27 10:49:19 +09:00
parent a93faf9eb5
commit a93d3a8f45
5 changed files with 237 additions and 34 deletions

View File

@@ -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;
}
}
}

View File

@@ -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<iCount; i++)
{
ushort uiTime = Watch.GetDataValue(0, i);
string strCode = Watch.GetDataValue(1, i);
string strName = Watch.GetDataValue(2, i);
ushort uiType = Watch.GetDataValue(3, i);
string strContents = Watch.GetDataValue(4, i);
if(uiTime <= m_uiLastReqT)
break;
if(m_uiLastReqT > 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()

24
NewsForm.Designer.cs generated
View File

@@ -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;
}
}

View File

@@ -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,18 +92,26 @@ namespace NewsCrawler
if(m_bBuy == false)
return;
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)
{
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)
if(lvList.Items.Cast<ListViewItem>().Any(s => s.SubItems[chLink.Index].Text == strURL))
return;
}
lvList.Items.Add(new ListViewItem(new string[] { time.ToString("HH:mm:ss"), strTitle, strRef, strURL }));
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 = "<![CDATA[".Length;
DateTime today = DateTime.Now;
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")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(responseFromServer);
string strXPath = "//item";
var lists = doc.DocumentNode.SelectNodes(strXPath);
if(lists == null)
return false;
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 = "[rss] " + item.ChildNodes["link"].NextSibling.InnerText;
if(time.Day != today.Day)
{
//Console.WriteLine("어제 기사 : " + item.InnerHtml);
continue;
}
InsertItem(strTitle, "", "",
DateTime.ParseExact(strTime, "HH:mm:ss", CultureInfo.CurrentCulture),
DateTime.Now,
strURL, "이투데이 rss", timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
@@ -304,8 +388,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")))
@@ -337,7 +425,10 @@ namespace NewsCrawler
continue;
}
InsertItem(strTitle, DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture), strURL, "DART", bInitial);
InsertItem(strTitle, "", "",
DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture),
DateTime.Now,
strURL, "DART", timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
@@ -363,8 +454,13 @@ namespace NewsCrawler
request.Timeout=2000;
int iCDATALen = "<![CDATA[".Length;
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")))
@@ -395,7 +491,10 @@ namespace NewsCrawler
continue;
}
InsertItem(strTitle, DateTime.ParseExact(strTime, "HH:mm:ss", CultureInfo.CurrentCulture), strURL, "KIND", bInitial);
InsertItem(strTitle, "", "",
DateTime.ParseExact(strTime, "HH:mm:ss", CultureInfo.CurrentCulture),
DateTime.Now,
strURL, "KIND", timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
@@ -422,8 +521,11 @@ namespace NewsCrawler
DateTime PrevTime = DateTime.Now;
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")))
@@ -449,7 +551,7 @@ namespace NewsCrawler
break;
PrevTime = Time;
InsertItem(strTitle, Time, strURL, "이데일리", bInitial);
InsertItem(strTitle, "", "", Time, DateTime.Now, strURL, "이데일리", timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
@@ -476,8 +578,13 @@ namespace NewsCrawler
DateTime PrevTime = DateTime.Now;
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")))
@@ -508,7 +615,7 @@ namespace NewsCrawler
break;
PrevTime = Time;
InsertItem(strTitle, Time, strURL, "머니투데이", bInitial);
InsertItem(strTitle, "", "", Time, DateTime.Now, strURL, "머니투데이", timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
@@ -535,8 +642,13 @@ namespace NewsCrawler
DateTime Today = DateTime.Now;
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")))
@@ -555,7 +667,7 @@ namespace NewsCrawler
string strURL = strServerURL+strCode;
if(Time.DayOfYear == Today.DayOfYear)
InsertItem(strTitle, Time, strURL, "파이낸셜뉴스", bInitial);
InsertItem(strTitle, "", "", Time, DateTime.Now, strURL, "파이낸셜뉴스", timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
@@ -596,7 +708,7 @@ namespace NewsCrawler
{
m_CrawlTimer.Enabled = false;
Console.WriteLine(string.Format("timer thread {0}", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()));
//Console.WriteLine(string.Format("timer thread {0}", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()));
if(chAutoReload.Checked == true)
{
@@ -604,6 +716,7 @@ namespace NewsCrawler
ReadDart();
ReadAsiaE();
ReadEtoday();
ReadEToday2();
ReadEdaily();
ReadMoneyToday();
ReadFinacialNews();

View File

@@ -137,6 +137,11 @@ namespace NewsCrawler
LoadManual();
}
public string GetKeywordsCnt()
{
return string.Format("Positive : {0}\nNegative : {1}\nManual : {2}", m_Positive.Count, m_Negative.Count, m_Manual.Count);
}
public class RESULT
{
public TYPE m_enType;