- Status bar 추가

- webview 삭제
- double click 시 브라우저로 이동
- Dart API 적용
- 종목명 검색 개선
This commit is contained in:
2017-01-09 08:01:43 +09:00
parent f9057cea61
commit 349de89a05
11 changed files with 1430 additions and 691 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.IO; using System.IO;
using System.Text.RegularExpressions;
namespace NewsCrawler namespace NewsCrawler
{ {
@@ -225,21 +226,53 @@ namespace NewsCrawler
public CODE_VALUE SearchCode(string strText) public CODE_VALUE SearchCode(string strText)
{ {
CODE_VALUE Result = m_CodeList.Find(s => strText.Contains(s.m_strName)); try
{
string strReplace = Regex.Replace(strText, @"(\(|\[|\<).*(\)|\]|\>)", "");
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) if(Result != null)
return Result; return Result;
SYNONYM_VALUE Synonym = m_SynonymList.Find(s => strText.Contains(s.m_strName)); SYNONYM_VALUE Synonym = m_SynonymList.Find(s => strCodeWord.Contains(s.m_strName));
if(Synonym == null) if(Synonym == null)
return null; return null;
return m_CodeList.Find(s => s.m_strCode == Synonym.m_strCode); return m_CodeList.Find(s => s.m_strCode == Synonym.m_strCode);
} }
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
return null;
}
public CODE_VALUE GetCode(string strCode) public CODE_VALUE GetCode(string strCode)
{ {
CODE_VALUE Result = m_CodeList.Find(s => s.m_strCode == strCode); CODE_VALUE Result = m_CodeList.Find(s => s.m_strCode == strCode);
return Result; return Result;
} }
public CODE_VALUE GetCodeByName(string strCodeName)
{
CODE_VALUE Result = m_CodeList.Find(s => s.m_strName == strCodeName);
return Result;
}
} }
} }

View File

@@ -12,11 +12,29 @@ namespace NewsCrawler
{ {
static Dictionary<string, string> m_Data = new Dictionary<string, string>(); static Dictionary<string, string> m_Data = new Dictionary<string, string>();
static Random m_Random = new Random();
static int m_iDartAPIKeyCnt = 0;
static bool[] m_abDartAPIKeyLimit = null;
public static void Init() public static void Init()
{ {
m_Data.Add("manual-price", "100000"); m_Data.Add("manual-price", "100000");
m_Data.Add("buy-price", "1000000"); m_Data.Add("buy-price", "1000000");
m_Data.Add("supply-contract-rate", "5.0");
Load(); Load();
int iIdx = 1;
while(true)
{
if(m_Data.ContainsKey("dart-api-key"+iIdx) == false)
break;
iIdx++;
}
m_iDartAPIKeyCnt = iIdx-1;
m_abDartAPIKeyLimit = new bool[m_iDartAPIKeyCnt];
for(int i = 0; i<m_iDartAPIKeyCnt; i++)
m_abDartAPIKeyLimit[i] = false;
} }
static void Load() static void Load()
@@ -94,5 +112,45 @@ namespace NewsCrawler
{ {
return m_Data["sub-account"]; return m_Data["sub-account"];
} }
public static void SetSupplyContractRate(float fRate)
{
m_Data["supply-contract-rate"] = fRate.ToString();
Save();
}
public static float GetSupplyContractRate()
{
float fRate;
float.TryParse(m_Data["supply-contract-rate"], out fRate);
return fRate;
}
public static string GetDartAPIKey()
{
if(m_iDartAPIKeyCnt <= 0)
return "";
if(m_abDartAPIKeyLimit.All(s => s == true) == true)
return "";
int iNum = -1;
while(iNum < 0 || m_abDartAPIKeyLimit[iNum-1] == true)
iNum = m_Random.Next(0, 10000)%m_iDartAPIKeyCnt + 1;
return m_Data["dart-api-key"+iNum];
}
public static void SetDartAPIKeyLimit(string strKey)
{
for(int i=0; i<m_iDartAPIKeyCnt; i++)
{
if(m_Data["dart-api-key"+(i+1).ToString()] == strKey)
{
m_abDartAPIKeyLimit[i] = true;
break;
}
}
}
} }
} }

53
ConfigForm.Designer.cs generated
View File

@@ -62,6 +62,10 @@
this.tbAccountSub = new System.Windows.Forms.TextBox(); this.tbAccountSub = new System.Windows.Forms.TextBox();
this.groupBox11 = new System.Windows.Forms.GroupBox(); this.groupBox11 = new System.Windows.Forms.GroupBox();
this.btnAccountApply = new System.Windows.Forms.Button(); this.btnAccountApply = new System.Windows.Forms.Button();
this.groupBox12 = new System.Windows.Forms.GroupBox();
this.label5 = new System.Windows.Forms.Label();
this.tbSupplyContractRate = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
this.groupBox6.SuspendLayout(); this.groupBox6.SuspendLayout();
@@ -73,6 +77,7 @@
this.groupBox9.SuspendLayout(); this.groupBox9.SuspendLayout();
this.groupBox10.SuspendLayout(); this.groupBox10.SuspendLayout();
this.groupBox11.SuspendLayout(); this.groupBox11.SuspendLayout();
this.groupBox12.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// tbVolume // tbVolume
@@ -426,11 +431,53 @@
this.btnAccountApply.UseVisualStyleBackColor = true; this.btnAccountApply.UseVisualStyleBackColor = true;
this.btnAccountApply.Click += new System.EventHandler(this.btnAccountApply_Click); this.btnAccountApply.Click += new System.EventHandler(this.btnAccountApply_Click);
// //
// groupBox12
//
this.groupBox12.Controls.Add(this.label6);
this.groupBox12.Controls.Add(this.tbSupplyContractRate);
this.groupBox12.Controls.Add(this.label5);
this.groupBox12.Location = new System.Drawing.Point(280, 316);
this.groupBox12.Name = "groupBox12";
this.groupBox12.Size = new System.Drawing.Size(262, 57);
this.groupBox12.TabIndex = 19;
this.groupBox12.TabStop = false;
this.groupBox12.Text = "공시";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(28, 23);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(77, 12);
this.label5.TabIndex = 0;
this.label5.Text = "공급계약체결";
//
// tbSupplyContractRate
//
this.tbSupplyContractRate.Location = new System.Drawing.Point(111, 20);
this.tbSupplyContractRate.Name = "tbSupplyContractRate";
this.tbSupplyContractRate.Size = new System.Drawing.Size(100, 21);
this.tbSupplyContractRate.TabIndex = 1;
this.tbSupplyContractRate.Text = "5.0";
this.tbSupplyContractRate.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tbSupplyContractRate.TextChanged += new System.EventHandler(this.tbSupplyContractRate_TextChanged);
this.tbSupplyContractRate.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbSupplyContractRate_KeyPress);
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(217, 23);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(15, 12);
this.label6.TabIndex = 2;
this.label6.Text = "%";
//
// ConfigForm // ConfigForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(548, 385); this.ClientSize = new System.Drawing.Size(548, 385);
this.Controls.Add(this.groupBox12);
this.Controls.Add(this.groupBox11); this.Controls.Add(this.groupBox11);
this.Controls.Add(this.groupBox10); this.Controls.Add(this.groupBox10);
this.Controls.Add(this.groupBox9); this.Controls.Add(this.groupBox9);
@@ -456,6 +503,8 @@
this.groupBox10.PerformLayout(); this.groupBox10.PerformLayout();
this.groupBox11.ResumeLayout(false); this.groupBox11.ResumeLayout(false);
this.groupBox11.PerformLayout(); this.groupBox11.PerformLayout();
this.groupBox12.ResumeLayout(false);
this.groupBox12.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@@ -495,5 +544,9 @@
private System.Windows.Forms.TextBox tbAccountSub; private System.Windows.Forms.TextBox tbAccountSub;
private System.Windows.Forms.GroupBox groupBox11; private System.Windows.Forms.GroupBox groupBox11;
private System.Windows.Forms.Button btnAccountApply; private System.Windows.Forms.Button btnAccountApply;
private System.Windows.Forms.GroupBox groupBox12;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox tbSupplyContractRate;
private System.Windows.Forms.Label label5;
} }
} }

View File

@@ -26,6 +26,8 @@ namespace NewsCrawler
cbAccount.Items.AddRange(Accounts); cbAccount.Items.AddRange(Accounts);
if(Config.GetAccount() != "" && Accounts.Contains(Config.GetAccount())) if(Config.GetAccount() != "" && Accounts.Contains(Config.GetAccount()))
cbAccount.SelectedItem = Config.GetAccount(); cbAccount.SelectedItem = Config.GetAccount();
tbSupplyContractRate.Text = Config.GetSupplyContractRate().ToString();
} }
private void OpenFile(string strName) private void OpenFile(string strName)
@@ -141,5 +143,18 @@ namespace NewsCrawler
{ {
m_Listener.OnConfigFormClosing(); m_Listener.OnConfigFormClosing();
} }
private void tbSupplyContractRate_TextChanged(object sender, EventArgs e)
{
float fSupplyContractRate;
float.TryParse(tbSupplyContractRate.Text, out fSupplyContractRate);
m_Listener.OnSupplyContractRateChanged(fSupplyContractRate);
}
private void tbSupplyContractRate_KeyPress(object sender, KeyPressEventArgs e)
{
if(char.IsDigit(e.KeyChar) == false && e.KeyChar != '.')
e.Handled = true;
}
} }
} }

899
Crawler.cs Normal file
View File

@@ -0,0 +1,899 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace NewsCrawler
{
public class Crawler
{
NewsForm m_Listener = null;
DateTime m_Today = DateTime.Now;
int m_iDartAPIRetry = 5;
public Crawler(NewsForm Listener)
{
m_Listener = Listener;
}
class REQUEST_STATUS
{
public HttpWebRequest m_HTTPReq = null;
public bool m_bInitial = false;
public Stopwatch m_Timer = new Stopwatch();
public string m_strCodeName = "";
public string m_strAuthKey = "";
};
void ResponseAsiaE(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
string strServerURL = "http://www.asiae.co.kr";
using(HttpWebResponse response = (HttpWebResponse)HttpReq.GetResponse())
{
using(Stream dataStream = response.GetResponseStream())
{
using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("EUC-KR")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
responseFromServer = responseFromServer.Replace("\"\"", "\"");
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(responseFromServer);
string strXPath = "//div[contains(@class, 'txtform')]/ul/li";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
string strTitle1 = item.SelectSingleNode(".//a").GetAttributeValue("title", "");
string strTitle2 = item.SelectSingleNode(".//a").FirstChild.InnerText;
string strTitle = (strTitle1.Length > strTitle2.Length ? strTitle1 : strTitle2);
string strTime = item.SelectSingleNode(".//span").InnerText;
string strURL = strServerURL+item.SelectSingleNode(".//a").GetAttributeValue("href", "");
if(Regex.IsMatch(strTime, @"\d+/\d+")==true)
{
//Console.WriteLine("어제 기사 : " + item.InnerHtml);
continue;
}
m_Listener.InsertItem(strTitle, "", "",
DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture),
DateTime.Now,
strURL, "아시아경제", State.m_Timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
public void ReadAsiaE(bool bInitial = false)
{
try
{
HttpWebRequest HttpReq = WebRequest.Create("http://www.asiae.co.kr/news/sokbo/sokbo_left.htm") as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
HttpReq.BeginGetResponse(new AsyncCallback(ResponseAsiaE), State);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseEtoday(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
using(HttpWebResponse response = (HttpWebResponse)HttpReq.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 = "//div[contains(@class, 'flash_tab_lst')]/ul/li";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
string strTitle = item.SelectSingleNode(".//a").InnerText;
string strTime = item.SelectSingleNode(".//span[contains(@class, 'flash_press')]").InnerText;
string strURL = item.SelectSingleNode(".//a").GetAttributeValue("href", "");
strURL="http://www.etoday.co.kr/news/section/newsview.php?idxno="+Regex.Replace(strURL, @"\D", "");
if(Regex.IsMatch(strTime, @"\d+/\d+")==true)
{
//Console.WriteLine("어제 기사 : " + item.InnerHtml);
continue;
}
m_Listener.InsertItem(strTitle, "", "",
DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture),
DateTime.Now,
strURL, "이투데이", State.m_Timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
public void ReadEtoday(bool bInitial = false)
{
try
{
HttpWebRequest HttpReq = WebRequest.Create("http://www.etoday.co.kr/news/flash/flash_list.php?tab=1") as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
HttpReq.BeginGetResponse(new AsyncCallback(ResponseEtoday), State);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseEtoday2(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
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;
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);
if(lists == null)
return;
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 != m_Today.Day)
{
//Console.WriteLine("어제 기사 : " + item.InnerHtml);
continue;
}
m_Listener.InsertItem(strTitle, "", "",
DateTime.ParseExact(strTime, "HH:mm:ss", CultureInfo.CurrentCulture),
DateTime.Now,
strURL, "이투데이 rss", State.m_Timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
public void ReadEtoday2(bool bInitial = false)
{
try
{
HttpWebRequest HttpReq = WebRequest.Create("http://rss.etoday.co.kr/etoday/etoday_news_all.xml") as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
HttpReq.BeginGetResponse(new AsyncCallback(ResponseEtoday2), State);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseDart(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
string strServerURL = "https://dart.fss.or.kr";
using(HttpWebResponse response = (HttpWebResponse)HttpReq.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 = "//div[@id='listContents']/div[contains(@class, 'table_list')]/table/tr";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
var rows = item.SelectNodes(".//td");
if(rows.Count < 3)
continue;
string strTitle = rows[2].InnerText;
strTitle=strTitle.Trim();
string strTime = item.SelectSingleNode(".//td[contains(@class, 'cen_txt')]").InnerText;
strTime=strTime.Trim();
string strURL = rows[2].SelectSingleNode(".//a").GetAttributeValue("href", "");
strURL=strURL.Trim();
strURL =strServerURL+strURL;
if(Regex.IsMatch(strTime, @"\d+/\d+")==true)
{
//Console.WriteLine("어제 기사 : " + item.InnerHtml);
continue;
}
m_Listener.InsertItem(strTitle, "", "",
DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture),
DateTime.Now,
strURL, "DART", State.m_Timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
public void ReadDart(bool bInitial = false)
{
try
{
HttpWebRequest HttpReq = WebRequest.Create("https://dart.fss.or.kr/dsac001/mainAll.do") as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
HttpReq.BeginGetResponse(new AsyncCallback(ResponseDart), State);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseSupplyContract(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
using(HttpWebResponse response = (HttpWebResponse)HttpReq.GetResponse())
{
using(Stream dataStream = response.GetResponseStream())
{
using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer);
string strBody = jObj["reportBody"];
strBody = strBody.Replace("\\\"", "\"");
strBody = strBody.Replace("\r\n", "");
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(strBody);
string strXPath = "//tr";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
var cols = item.SelectNodes(".//td");
foreach(var col in cols)
{
if(col.InnerText.Contains("매출액 대비") == true)
{
string strRate = cols[cols.Count-1].InnerText;
float fRate;
float.TryParse(strRate, out fRate);
m_Listener.OnReceivedSupplyContract(State.m_strCodeName, fRate);
break;
}
}
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
private void ReadSupplyContract(bool bInitial, string strCodeName, string strURL)
{
if(m_iDartAPIRetry <= 0)
return;
try
{
HttpWebRequest HttpReq = WebRequest.Create(strURL) as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
State.m_strCodeName = strCodeName;
HttpReq.BeginGetResponse(new AsyncCallback(ResponseSupplyContract), State);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseDartAPI(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
using(HttpWebResponse response = (HttpWebResponse)HttpReq.GetResponse())
{
using(Stream dataStream = response.GetResponseStream())
{
using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer);
string strErrCode = jObj["err_code"];
if(strErrCode == "020")
{
Config.SetDartAPIKeyLimit(State.m_strAuthKey);
Util.Log(Util.LOG_TYPE.ERROR, string.Format("[DartAPI] {0} ({1})", jObj["err_msg"], m_iDartAPIRetry));
return;
}
else if(strErrCode != "000")
{
Util.Log(Util.LOG_TYPE.ERROR, string.Format("[DartAPI] {0} ({1})", jObj["err_msg"], m_iDartAPIRetry));
m_iDartAPIRetry--;
return;
}
foreach(var data in jObj["list"])
{
string strTime = "00:00";
string strTitle = data["rpt_nm"];
string strCodeName = data["crp_nm"];
string strURL = "http://m.dart.fss.or.kr/html_mdart/MD1007.html?rcpNo=" + data["rcp_no"];
if(strCodeName != "" && strTitle.Contains("공급계약체결") && m_Listener.IsDuplicatedURL(strURL) == false)
{
string strURL2 = "http://m.dart.fss.or.kr/viewer/main.st?rcpNo=" + data["rcp_no"];
ReadSupplyContract(bInitial, strCodeName, strURL2);
}
m_Listener.InsertItem(strTitle, strCodeName, "",
DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture),
DateTime.Now,
strURL, "DART API", State.m_Timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
public void ReadDartAPI(bool bInitial = false)
{
if(m_iDartAPIRetry <= 0)
return;
try
{
string strAuthKey = Config.GetDartAPIKey();
string strURL = "http://dart.fss.or.kr/api/search.json?auth="+strAuthKey+"&end_dt="+m_Today.ToString("yyyyMMdd");
HttpWebRequest HttpReq = WebRequest.Create(strURL) as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
State.m_strAuthKey = strAuthKey;
HttpReq.BeginGetResponse(new AsyncCallback(ResponseDartAPI), State);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseKIND(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
//string strServerURL = "https://dart.fss.or.kr";
int iCDATALen = "<![CDATA[".Length;
using(HttpWebResponse response = (HttpWebResponse)HttpReq.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);
if(lists == null)
return;
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;
}
m_Listener.InsertItem(strTitle, "", "",
DateTime.ParseExact(strTime, "HH:mm:ss", CultureInfo.CurrentCulture),
DateTime.Now,
strURL, "KIND", State.m_Timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
public void ReadKIND(bool bInitial = false)
{
try
{
HttpWebRequest HttpReq = WebRequest.Create("http://kind.krx.co.kr/disclosure/rsstodaydistribute.do?method=searchRssTodayDistribute&repIsuSrtCd=&mktTpCd=0&searchCorpName=&currentPageSize=1000") as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
HttpReq.BeginGetResponse(new AsyncCallback(ResponseKIND), State);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseEdaily(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
string strServerURL = "http://www.edaily.co.kr/news/realtime/realtime_NewsRead.asp";
DateTime PrevTime = DateTime.Now;
using(HttpWebResponse response = (HttpWebResponse)HttpReq.GetResponse())
{
using(Stream dataStream = response.GetResponseStream())
{
using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("EUC-KR")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(responseFromServer);
string strXPath = "//li[contains(@id, 'NewsIcon')]";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
string strTitle = item.SelectSingleNode(".//a").GetAttributeValue("title", "");
string strTime = item.SelectSingleNode(".//span").InnerText;
string strID = item.GetAttributeValue("id", "");
strID = strID.Substring("NewsIcon_".Length);
string strURL = strServerURL+"?newsid="+strID;
DateTime Time;
DateTime.TryParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture, DateTimeStyles.None, out Time);
if(Time > PrevTime)
break;
PrevTime = Time;
m_Listener.InsertItem(strTitle, "", "", Time, DateTime.Now, strURL, "이데일리", State.m_Timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
public void ReadEdaily(bool bInitial = false)
{
try
{
HttpWebRequest HttpReq = WebRequest.Create("http://www.edaily.co.kr/news/realtime/realtime_NewsList_1.asp") as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
HttpReq.BeginGetResponse(new AsyncCallback(ResponseEdaily), State);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseMoneyToday(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
string strServerURL = "http://news.mt.co.kr/mtview.php?no=";
DateTime PrevTime = DateTime.Now;
using(HttpWebResponse response = (HttpWebResponse)HttpReq.GetResponse())
{
using(Stream dataStream = response.GetResponseStream())
{
using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("EUC-KR")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(responseFromServer);
string strXPath = "//div[@id='articleList']//li[@class='bundle']";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
string strTitle = item.SelectSingleNode(".//a").InnerText;
string strTime = item.SelectSingleNode(".//span").InnerText;
string strID = item.SelectSingleNode(".//a").GetAttributeValue("href", "");
int iStart = strID.IndexOf('\'', 0);
iStart = strID.IndexOf('\'', iStart+1);
iStart = strID.IndexOf('\'', iStart+1);
int iEnd = strID.IndexOf('\'', iStart+1);
strID = strID.Substring(iStart+1, iEnd-iStart+1);
string strURL = strServerURL+strID;
DateTime Time;
DateTime.TryParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture, DateTimeStyles.None, out Time);
if(Time > PrevTime)
break;
PrevTime = Time;
m_Listener.InsertItem(strTitle, "", "", Time, DateTime.Now, strURL, "머니투데이", State.m_Timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
public void ReadMoneyToday(bool bInitial = false)
{
try
{
HttpWebRequest HttpReq = WebRequest.Create("http://news.mt.co.kr/newsflash/newsflash.html") as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
HttpReq.BeginGetResponse(new AsyncCallback(ResponseMoneyToday), State);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseFinancialNewsJson(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
string strServerURL = "http://www.fnnews.com/news/";
using(HttpWebResponse response = (HttpWebResponse)HttpReq.GetResponse())
{
using(Stream dataStream = response.GetResponseStream())
{
using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("UTF-8")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer);
foreach(var data in jObj)
{
string strTitle = data["title"];
string strTime = data["date"];
DateTime Time;
DateTime.TryParseExact(strTime, "yyyy.MM.dd HH:mm", CultureInfo.CurrentCulture, DateTimeStyles.None, out Time);
string strCode = data["code"];
string strURL = strServerURL+strCode;
if(Time.DayOfYear == m_Today.DayOfYear)
m_Listener.InsertItem(strTitle, "", "", Time, DateTime.Now, strURL, "파이낸셜뉴스", State.m_Timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
public void ReadFinancialNewsJson(bool bInitial = false)
{
try
{
HttpWebRequest HttpReq = WebRequest.Create("http://www.fnnews.com/newsflash/today/data?type=json") as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
HttpReq.BeginGetResponse(new AsyncCallback(ResponseFinancialNewsJson), State);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseFinancialNews(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
string strServerURL = "http://www.fnnews.com";
DateTime Today = DateTime.Now;
using(HttpWebResponse response = (HttpWebResponse)HttpReq.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 = "//div[@class='categoryList']//li";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
string strTitle = item.SelectNodes(".//a")[1].InnerText;
string strDateTime = item.SelectSingleNode(".//span[@class='category_date']").InnerText;
string strURL = strServerURL+item.SelectNodes(".//a")[1].GetAttributeValue("href", "");
DateTime Time;
DateTime.TryParseExact(strDateTime, "yyyy.MM.dd HH:mm", CultureInfo.CurrentCulture, DateTimeStyles.None, out Time);
if(Time.DayOfYear < m_Today.DayOfYear)
break;
m_Listener.InsertItem(strTitle, "", "", Time, DateTime.Now, strURL, "파이낸셜뉴스", State.m_Timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
public void ReadFinancialNews(bool bInitial = false)
{
try
{
HttpWebRequest HttpReq = WebRequest.Create("http://www.fnnews.com/newsflash") as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
HttpReq.BeginGetResponse(new AsyncCallback(ResponseFinancialNews), State);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
}
}

View File

@@ -155,9 +155,12 @@ namespace NewsCrawler
public int GetCurPrice(CodeList.CODE_VALUE Code) public int GetCurPrice(CodeList.CODE_VALUE Code)
{ {
while(GetLimitRemainCountRQ() < 1)
Thread.Sleep(100);
m_CPStockMst.SetInputValue(0, Code.m_strCode); m_CPStockMst.SetInputValue(0, Code.m_strCode);
m_CPStockMst.BlockRequest2(0); m_CPStockMst.BlockRequest2(0);
int iCurPrice = m_CPStockMst.GetHeaderValue(13); int iCurPrice = m_CPStockMst.GetHeaderValue(11);
return iCurPrice; return iCurPrice;
} }
@@ -184,8 +187,6 @@ namespace NewsCrawler
int iTimeStart; int iTimeStart;
int.TryParse(StartTime.ToString("HHmm"), out iTimeStart); int.TryParse(StartTime.ToString("HHmm"), out iTimeStart);
int iCheckCnt = 0;
int iCount = m_StockChart.GetHeaderValue(3); int iCount = m_StockChart.GetHeaderValue(3);
for(int i=0; i<iCount; i++) for(int i=0; i<iCount; i++)
{ {
@@ -201,11 +202,9 @@ namespace NewsCrawler
iPriceLow = Math.Min(iPriceLow, (int)iPriceLowLocal); iPriceLow = Math.Min(iPriceLow, (int)iPriceLowLocal);
iPriceHigh = Math.Max(iPriceLow, (int)iPriceHighLocal); iPriceHigh = Math.Max(iPriceLow, (int)iPriceHighLocal);
iCheckCnt++;
} }
if(iCheckCnt >= 5) if(iTime < iTimeStart)
break; break;
} }
} }

View File

@@ -97,6 +97,7 @@
<Compile Include="ConfigForm.Designer.cs"> <Compile Include="ConfigForm.Designer.cs">
<DependentUpon>ConfigForm.cs</DependentUpon> <DependentUpon>ConfigForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Crawler.cs" />
<Compile Include="CybosHelper.cs" /> <Compile Include="CybosHelper.cs" />
<Compile Include="ModelessPopup.cs"> <Compile Include="ModelessPopup.cs">
<SubType>Form</SubType> <SubType>Form</SubType>

156
NewsForm.Designer.cs generated
View File

@@ -37,27 +37,29 @@
this.chResponseT = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chResponseT = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chPriceS = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chPriceS = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chPriceLow = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chPriceLow = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chPriceLowP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chPriceHigh = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chPriceHigh = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chPriceHighP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chLink = ((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.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.statusBar = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel3 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel4 = new System.Windows.Forms.ToolStripStatusLabel();
this.tbLog = new System.Windows.Forms.RichTextBox();
this.chAutoReload = new System.Windows.Forms.CheckBox(); this.chAutoReload = new System.Windows.Forms.CheckBox();
this.chAutoSelect = new System.Windows.Forms.CheckBox(); this.chAutoSelect = new System.Windows.Forms.CheckBox();
this.tbInterval = new System.Windows.Forms.TextBox(); this.tbInterval = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.btnConfig = new System.Windows.Forms.Button(); this.btnConfig = new System.Windows.Forms.Button();
this.splitContainer2 = new System.Windows.Forms.SplitContainer();
this.tbLog = new System.Windows.Forms.RichTextBox();
this.chBuy = new System.Windows.Forms.CheckBox(); this.chBuy = new System.Windows.Forms.CheckBox();
this.cbPriceCheck = new System.Windows.Forms.CheckBox(); this.cbPriceCheck = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout(); this.splitContainer1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); this.statusBar.SuspendLayout();
this.splitContainer2.Panel1.SuspendLayout();
this.splitContainer2.Panel2.SuspendLayout();
this.splitContainer2.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// lvList // lvList
@@ -71,7 +73,9 @@
this.chResponseT, this.chResponseT,
this.chPriceS, this.chPriceS,
this.chPriceLow, this.chPriceLow,
this.chPriceLowP,
this.chPriceHigh, this.chPriceHigh,
this.chPriceHighP,
this.chLink}); this.chLink});
this.lvList.Dock = System.Windows.Forms.DockStyle.Fill; this.lvList.Dock = System.Windows.Forms.DockStyle.Fill;
this.lvList.FullRowSelect = true; this.lvList.FullRowSelect = true;
@@ -80,12 +84,12 @@
this.lvList.Location = new System.Drawing.Point(0, 0); this.lvList.Location = new System.Drawing.Point(0, 0);
this.lvList.MultiSelect = false; this.lvList.MultiSelect = false;
this.lvList.Name = "lvList"; this.lvList.Name = "lvList";
this.lvList.Size = new System.Drawing.Size(1100, 603); this.lvList.Size = new System.Drawing.Size(1412, 587);
this.lvList.TabIndex = 0; this.lvList.TabIndex = 0;
this.lvList.UseCompatibleStateImageBehavior = false; this.lvList.UseCompatibleStateImageBehavior = false;
this.lvList.View = System.Windows.Forms.View.Details; this.lvList.View = System.Windows.Forms.View.Details;
this.lvList.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lvList_ColumnClick); this.lvList.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lvList_ColumnClick);
this.lvList.SelectedIndexChanged += new System.EventHandler(this.lvList_SelectedIndexChanged); this.lvList.DoubleClick += new System.EventHandler(this.lvList_DoubleClick);
// //
// chId // chId
// //
@@ -126,29 +130,30 @@
this.chPriceLow.Text = "최저가"; this.chPriceLow.Text = "최저가";
this.chPriceLow.Width = 75; this.chPriceLow.Width = 75;
// //
// chPriceLowP
//
this.chPriceLowP.Text = "최저가 대비(%)";
//
// chPriceHigh // chPriceHigh
// //
this.chPriceHigh.Text = "최고가"; this.chPriceHigh.Text = "최고가";
this.chPriceHigh.Width = 73; this.chPriceHigh.Width = 73;
// //
// chPriceHighP
//
this.chPriceHighP.Text = "최고가 대비(%)";
//
// chLink // chLink
// //
this.chLink.Text = "링크"; this.chLink.Text = "링크";
this.chLink.Width = 241; 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(1100, 27);
this.wbView.TabIndex = 1;
//
// splitContainer1 // splitContainer1
// //
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.splitContainer1.Location = new System.Drawing.Point(0, 0); | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.splitContainer1.Location = new System.Drawing.Point(0, 27);
this.splitContainer1.Name = "splitContainer1"; this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
// //
@@ -158,11 +163,62 @@
// //
// splitContainer1.Panel2 // splitContainer1.Panel2
// //
this.splitContainer1.Panel2.Controls.Add(this.wbView); this.splitContainer1.Panel2.Controls.Add(this.statusBar);
this.splitContainer1.Size = new System.Drawing.Size(1100, 634); this.splitContainer1.Panel2.Controls.Add(this.tbLog);
this.splitContainer1.SplitterDistance = 603; this.splitContainer1.Size = new System.Drawing.Size(1412, 805);
this.splitContainer1.SplitterDistance = 587;
this.splitContainer1.TabIndex = 2; this.splitContainer1.TabIndex = 2;
// //
// statusBar
//
this.statusBar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel1,
this.toolStripStatusLabel2,
this.toolStripStatusLabel3,
this.toolStripStatusLabel4});
this.statusBar.Location = new System.Drawing.Point(0, 192);
this.statusBar.Name = "statusBar";
this.statusBar.Size = new System.Drawing.Size(1412, 22);
this.statusBar.TabIndex = 1;
this.statusBar.Text = "statusStrip1";
//
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.BorderSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.Right;
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(4, 17);
//
// toolStripStatusLabel2
//
this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
this.toolStripStatusLabel2.Size = new System.Drawing.Size(1389, 17);
this.toolStripStatusLabel2.Spring = true;
//
// toolStripStatusLabel3
//
this.toolStripStatusLabel3.BorderSides = ((System.Windows.Forms.ToolStripStatusLabelBorderSides)((System.Windows.Forms.ToolStripStatusLabelBorderSides.Left | System.Windows.Forms.ToolStripStatusLabelBorderSides.Right)));
this.toolStripStatusLabel3.Name = "toolStripStatusLabel3";
this.toolStripStatusLabel3.Size = new System.Drawing.Size(4, 17);
//
// toolStripStatusLabel4
//
this.toolStripStatusLabel4.Name = "toolStripStatusLabel4";
this.toolStripStatusLabel4.Size = new System.Drawing.Size(0, 17);
//
// tbLog
//
this.tbLog.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.tbLog.BackColor = System.Drawing.SystemColors.Window;
this.tbLog.Location = new System.Drawing.Point(0, 0);
this.tbLog.Name = "tbLog";
this.tbLog.ReadOnly = true;
this.tbLog.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.tbLog.Size = new System.Drawing.Size(1412, 189);
this.tbLog.TabIndex = 0;
this.tbLog.Text = "";
//
// chAutoReload // chAutoReload
// //
this.chAutoReload.AutoSize = true; this.chAutoReload.AutoSize = true;
@@ -209,7 +265,7 @@
// btnConfig // btnConfig
// //
this.btnConfig.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnConfig.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnConfig.Location = new System.Drawing.Point(1026, 1); this.btnConfig.Location = new System.Drawing.Point(1336, 1);
this.btnConfig.Name = "btnConfig"; this.btnConfig.Name = "btnConfig";
this.btnConfig.Size = new System.Drawing.Size(75, 23); this.btnConfig.Size = new System.Drawing.Size(75, 23);
this.btnConfig.TabIndex = 7; this.btnConfig.TabIndex = 7;
@@ -217,38 +273,6 @@
this.btnConfig.UseVisualStyleBackColor = true; this.btnConfig.UseVisualStyleBackColor = true;
this.btnConfig.Click += new System.EventHandler(this.btnConfig_Click); this.btnConfig.Click += new System.EventHandler(this.btnConfig_Click);
// //
// splitContainer2
//
this.splitContainer2.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.splitContainer2.Location = new System.Drawing.Point(1, 26);
this.splitContainer2.Name = "splitContainer2";
this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// splitContainer2.Panel1
//
this.splitContainer2.Panel1.Controls.Add(this.splitContainer1);
//
// splitContainer2.Panel2
//
this.splitContainer2.Panel2.Controls.Add(this.tbLog);
this.splitContainer2.Size = new System.Drawing.Size(1100, 803);
this.splitContainer2.SplitterDistance = 634;
this.splitContainer2.TabIndex = 8;
//
// tbLog
//
this.tbLog.BackColor = System.Drawing.SystemColors.Window;
this.tbLog.Dock = System.Windows.Forms.DockStyle.Fill;
this.tbLog.Location = new System.Drawing.Point(0, 0);
this.tbLog.Name = "tbLog";
this.tbLog.ReadOnly = true;
this.tbLog.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.tbLog.Size = new System.Drawing.Size(1100, 165);
this.tbLog.TabIndex = 0;
this.tbLog.Text = "";
//
// chBuy // chBuy
// //
this.chBuy.Appearance = System.Windows.Forms.Appearance.Button; this.chBuy.Appearance = System.Windows.Forms.Appearance.Button;
@@ -275,10 +299,10 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1102, 829); this.ClientSize = new System.Drawing.Size(1412, 829);
this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.cbPriceCheck); this.Controls.Add(this.cbPriceCheck);
this.Controls.Add(this.chBuy); this.Controls.Add(this.chBuy);
this.Controls.Add(this.splitContainer2);
this.Controls.Add(this.btnConfig); this.Controls.Add(this.btnConfig);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Controls.Add(this.tbInterval); this.Controls.Add(this.tbInterval);
@@ -289,12 +313,11 @@
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.NewsForm_FormClosing); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.NewsForm_FormClosing);
this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.Panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false); this.splitContainer1.ResumeLayout(false);
this.splitContainer2.Panel1.ResumeLayout(false); this.statusBar.ResumeLayout(false);
this.splitContainer2.Panel2.ResumeLayout(false); this.statusBar.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
this.splitContainer2.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@@ -307,14 +330,12 @@
private System.Windows.Forms.ColumnHeader chTitle; private System.Windows.Forms.ColumnHeader chTitle;
private System.Windows.Forms.ColumnHeader chReference; private System.Windows.Forms.ColumnHeader chReference;
private System.Windows.Forms.ColumnHeader chLink; private System.Windows.Forms.ColumnHeader chLink;
private System.Windows.Forms.WebBrowser wbView;
private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.CheckBox chAutoReload; private System.Windows.Forms.CheckBox chAutoReload;
private System.Windows.Forms.CheckBox chAutoSelect; private System.Windows.Forms.CheckBox chAutoSelect;
private System.Windows.Forms.TextBox tbInterval; private System.Windows.Forms.TextBox tbInterval;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnConfig; private System.Windows.Forms.Button btnConfig;
private System.Windows.Forms.SplitContainer splitContainer2;
private System.Windows.Forms.RichTextBox tbLog; private System.Windows.Forms.RichTextBox tbLog;
private System.Windows.Forms.CheckBox chBuy; private System.Windows.Forms.CheckBox chBuy;
private System.Windows.Forms.ColumnHeader chResponseT; private System.Windows.Forms.ColumnHeader chResponseT;
@@ -324,6 +345,13 @@
private System.Windows.Forms.ColumnHeader chPriceLow; private System.Windows.Forms.ColumnHeader chPriceLow;
private System.Windows.Forms.ColumnHeader chPriceHigh; private System.Windows.Forms.ColumnHeader chPriceHigh;
private System.Windows.Forms.CheckBox cbPriceCheck; private System.Windows.Forms.CheckBox cbPriceCheck;
private System.Windows.Forms.ColumnHeader chPriceLowP;
private System.Windows.Forms.ColumnHeader chPriceHighP;
private System.Windows.Forms.StatusStrip statusBar;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel3;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel4;
} }
} }

View File

@@ -11,6 +11,7 @@ using System.Linq;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@@ -26,6 +27,7 @@ namespace NewsCrawler
public int m_iPriceLow = 0; public int m_iPriceLow = 0;
public int m_iPriceHigh = 0; public int m_iPriceHigh = 0;
public DateTime m_StartTime; public DateTime m_StartTime;
public int m_iTryCnt = 0;
} }
@@ -36,12 +38,22 @@ namespace NewsCrawler
System.Timers.Timer m_CrawlTimer = new System.Timers.Timer(); System.Timers.Timer m_CrawlTimer = new System.Timers.Timer();
int m_iCrawlInterval = 500; int m_iCrawlInterval = 500;
bool m_bBrowserReload = false;
bool m_bBuy = false; bool m_bBuy = false;
System.Timers.Timer m_SystemTimer = new System.Timers.Timer();
ConcurrentQueue<PRICE_CHECK_DATA> m_PriceCheckList = new ConcurrentQueue<PRICE_CHECK_DATA>(); ConcurrentQueue<PRICE_CHECK_DATA> m_PriceCheckList = new ConcurrentQueue<PRICE_CHECK_DATA>();
System.Timers.Timer m_PriceCheckTimer = new System.Timers.Timer(); System.Timers.Timer m_PriceCheckTimer = new System.Timers.Timer();
delegate void InsertListView(string strTitle, string strName, string strCode, DateTime time, DateTime ResTime, string strURL, string strRef, double responseT, bool bInitial);
InsertListView m_InsertListViewDelegate = null;
Crawler m_Crawler = null;
float m_fSupplyContractRate;
object m_lvListLock = new object();
public NewsForm() public NewsForm()
{ {
InitializeComponent(); InitializeComponent();
@@ -51,21 +63,32 @@ namespace NewsCrawler
m_CodeList = new CodeList(); m_CodeList = new CodeList();
m_Condition = new TextCondition(); m_Condition = new TextCondition();
m_CybosHelper = new CybosHelper(this); m_CybosHelper = new CybosHelper(this);
m_Crawler = new Crawler(this);
m_fSupplyContractRate = Config.GetSupplyContractRate();
MessageBox.Show("Keywords : \n\n" + m_Condition.GetKeywordsCnt()); //MessageBox.Show("Keywords : \n\n" + m_Condition.GetKeywordsCnt());
m_InsertListViewDelegate = new InsertListView(this.InsertItem);
m_Crawler.ReadKIND(true);
m_Crawler.ReadDart(true);
m_Crawler.ReadEtoday(true);
m_Crawler.ReadEtoday2(true);
m_Crawler.ReadAsiaE(true);
m_Crawler.ReadEdaily(true);
m_Crawler.ReadMoneyToday(true);
m_Crawler.ReadFinancialNews(true);
wbView.ScriptErrorsSuppressed = false; lvList.Columns[chTime.Index].TextAlign = HorizontalAlignment.Right;
lvList.Columns[chResponseT.Index].TextAlign = HorizontalAlignment.Right;
ReadKIND(true); lvList.Columns[chResT.Index].TextAlign = HorizontalAlignment.Right;
ReadDart(true); lvList.Columns[chId.Index].TextAlign = HorizontalAlignment.Right;
ReadEtoday(true); lvList.Columns[chPriceS.Index].TextAlign = HorizontalAlignment.Right;
ReadEToday2(true); lvList.Columns[chPriceLow.Index].TextAlign = HorizontalAlignment.Right;
ReadAsiaE(true); lvList.Columns[chPriceLowP.Index].TextAlign = HorizontalAlignment.Right;
ReadEdaily(true); lvList.Columns[chPriceHigh.Index].TextAlign = HorizontalAlignment.Right;
ReadMoneyToday(true); lvList.Columns[chPriceHighP.Index].TextAlign = HorizontalAlignment.Right;
ReadFinacialNews(true);
lvList.ListViewItemSorter = new ListViewItemComparer(chId.Index, SortOrder.Ascending); lvList.ListViewItemSorter = new ListViewItemComparer(chId.Index, SortOrder.Ascending);
lvList.Sorting = SortOrder.Ascending; lvList.Sorting = SortOrder.Ascending;
@@ -78,18 +101,22 @@ namespace NewsCrawler
if(lvList.SelectedItems.Count > 0) if(lvList.SelectedItems.Count > 0)
lvList.SelectedItems[0].EnsureVisible(); lvList.SelectedItems[0].EnsureVisible();
} }
lvList.Columns[chTime.Index].TextAlign = HorizontalAlignment.Right;
lvList.Columns[chResponseT.Index].TextAlign = HorizontalAlignment.Right; foreach(ColumnHeader col in lvList.Columns)
lvList.Columns[chResT.Index].TextAlign = HorizontalAlignment.Right; {
lvList.Columns[chId.Index].TextAlign = HorizontalAlignment.Right; if(!(col == chPriceS || col == chPriceLow || col == chPriceHigh))
lvList.Columns[chPriceS.Index].TextAlign = HorizontalAlignment.Right; col.Width = -2;
lvList.Columns[chPriceLow.Index].TextAlign = HorizontalAlignment.Right; }
lvList.Columns[chPriceHigh.Index].TextAlign = HorizontalAlignment.Right;
m_CrawlTimer.Elapsed+=CrawlTimer_Tick; m_CrawlTimer.Elapsed+=CrawlTimer_Tick;
m_CrawlTimer.Interval=m_iCrawlInterval; m_CrawlTimer.Interval = m_iCrawlInterval;
m_CrawlTimer.Start(); m_CrawlTimer.Start();
m_SystemTimer.Elapsed+=SystemTimer_Elapsed;
m_SystemTimer.Interval=1000;
m_SystemTimer.Start();
m_PriceCheckTimer.Interval = 5000; m_PriceCheckTimer.Interval = 5000;
m_PriceCheckTimer.Elapsed += PriceCheckTimer_Elapsed; m_PriceCheckTimer.Elapsed += PriceCheckTimer_Elapsed;
m_PriceCheckTimer.Start(); m_PriceCheckTimer.Start();
@@ -102,6 +129,17 @@ namespace NewsCrawler
if(Util.IsDebugging() == false) if(Util.IsDebugging() == false)
return; return;
Console.WriteLine(m_CodeList.SearchCode("\"사세요 일색 보고서\" 증권사 투자등급 공시 '"));
Console.WriteLine(m_CodeList.SearchCode("허서홍 GS에너지 상무, GS 보통주 5.1만주 매수"));
Console.WriteLine(m_CodeList.SearchCode("엠씨넥스, 아이클론 프리미엄 블랙박스 'i5 W"));
Console.WriteLine(m_CodeList.SearchCode("에스아이티글로벌, 김의서 대표이사 체제로 변"));
Console.WriteLine(m_CodeList.SearchCode("시몬스침대, 일산 가구공단에 프리미엄 매장 오"));
Console.WriteLine(m_CodeList.SearchCode("[유럽증시]美 고용지표 앞두고 짙은 관망세"));
Console.WriteLine(m_CodeList.SearchCode("코스콤, 강신 신임 전무이사 선임"));
Console.WriteLine(m_CodeList.SearchCode("[베스트리포트]원자현미경, 반도체의 질문에 답"));
Console.WriteLine(m_CodeList.SearchCode("거래소, 인콘에 최대주주 지분매각 추진설 조회"));
Console.WriteLine(m_CodeList.SearchCode("와이제이엠게임즈, 서울 강남구로 본점 이전"));
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] 덕산하이메탈, 덕산네오룩스 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] 자연과환경, 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] 이엠코리아, 한국항공우주산업과 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);
@@ -136,6 +174,9 @@ namespace NewsCrawler
void CheckPrice(int iID, CodeList.CODE_VALUE Code) void CheckPrice(int iID, CodeList.CODE_VALUE Code)
{ {
if(DateTime.Now.Hour < 9 || DateTime.Now.Hour >= 15)
return;
PRICE_CHECK_DATA CheckData = new PRICE_CHECK_DATA(); PRICE_CHECK_DATA CheckData = new PRICE_CHECK_DATA();
CheckData.m_iID = iID; CheckData.m_iID = iID;
CheckData.m_Code = Code; CheckData.m_Code = Code;
@@ -145,14 +186,15 @@ namespace NewsCrawler
void ProcessSearchAndBuy(string strTitle, string strName, string strCode, string strRef, int iID) void ProcessSearchAndBuy(string strTitle, string strName, string strCode, string strRef, int iID)
{ {
CodeList.CODE_VALUE Code; CodeList.CODE_VALUE Code = null;
if(strCode == "") if(strCode == "")
Code = m_CodeList.SearchCode(strTitle); Code = m_CodeList.SearchCode(strTitle);
else else
Code = m_CodeList.GetCode(strCode); Code = m_CodeList.GetCode(strCode);
if(Code != null) if(Code == null)
{ return;
TextCondition.RESULT MatchResult = m_Condition.Match(strTitle); TextCondition.RESULT MatchResult = m_Condition.Match(strTitle);
switch(MatchResult.m_enType) switch(MatchResult.m_enType)
{ {
@@ -163,10 +205,19 @@ namespace NewsCrawler
case TextCondition.TYPE.POSITIVE: case TextCondition.TYPE.POSITIVE:
if((Code.m_enType&CodeList.CODE_TYPE.DENIAL) == CodeList.CODE_TYPE.DENIAL) if((Code.m_enType&CodeList.CODE_TYPE.DENIAL) == CodeList.CODE_TYPE.DENIAL)
Util.Log(Util.LOG_TYPE.DENIAL, string.Format("[{0}] {1} (keyword:{2}, code:{3})", strRef, strTitle, MatchResult.m_strKeyword, Code.ToString())); Util.Log(Util.LOG_TYPE.DENIAL, string.Format("[{0}] {1} (keyword:{2}, code:{3})", strRef, strTitle, MatchResult.m_strKeyword, Code.ToString()));
else if((Code.m_enType&CodeList.CODE_TYPE.DENIAL) == CodeList.CODE_TYPE.DUPLICATED) else if((Code.m_enType&CodeList.CODE_TYPE.DUPLICATED) == CodeList.CODE_TYPE.DUPLICATED)
Util.Log(Util.LOG_TYPE.DUPLICATED, string.Format("[{0}] {1} (keyword:{2}, code:{3})", strRef, strTitle, MatchResult.m_strKeyword, Code.ToString())); Util.Log(Util.LOG_TYPE.DUPLICATED, string.Format("[{0}] {1} (keyword:{2}, code:{3})", strRef, strTitle, MatchResult.m_strKeyword, Code.ToString()));
else if((Code.m_enType&CodeList.CODE_TYPE.DENIAL) == CodeList.CODE_TYPE.MANUAL) else if((Code.m_enType&CodeList.CODE_TYPE.MANUAL) == CodeList.CODE_TYPE.MANUAL)
{
Util.Log(Util.LOG_TYPE.MANUAL_CODE, string.Format("[{0}] {1} (keyword:{2}, code:{3})", strRef, strTitle, MatchResult.m_strKeyword, Code.ToString())); Util.Log(Util.LOG_TYPE.MANUAL_CODE, string.Format("[{0}] {1} (keyword:{2}, code:{3})", strRef, strTitle, MatchResult.m_strKeyword, Code.ToString()));
ModelessPopup ManualPopup = new ModelessPopup(this);
ManualPopup.SetMessage(string.Format("{0}\n[{1}] {2}\n(keyword:{3}, code:{4})\n\n매수하시겠습니까?",
DateTime.Now.ToString("[hh:mm:ss]"),
strRef, strTitle, MatchResult.m_strKeyword, Code), Code);
ManualPopup.TopMost = true;
ManualPopup.Show();
}
else else
{ {
Util.Log(Util.LOG_TYPE.POSITIVE, string.Format("[{0}] {1} (keyword:{2}, code:{3})", strRef, strTitle, MatchResult.m_strKeyword, Code.ToString())); Util.Log(Util.LOG_TYPE.POSITIVE, string.Format("[{0}] {1} (keyword:{2}, code:{3})", strRef, strTitle, MatchResult.m_strKeyword, Code.ToString()));
@@ -197,27 +248,92 @@ namespace NewsCrawler
break; break;
} }
if(cbPriceCheck.Checked == true)
CheckPrice(iID, Code); CheckPrice(iID, Code);
} }
public void OnReceivedSupplyContract(string strCodeName, float fRate)
{
CodeList.CODE_VALUE Code = m_CodeList.GetCodeByName(strCodeName);
if(Code == null)
{
Util.Log(Util.LOG_TYPE.VERVOSE, string.Format("[공급계약체결] 종목을 찾을 수 없음({0}, {1}%", strCodeName, fRate));
return;
}
if(fRate < m_fSupplyContractRate)
{
Util.Log(Util.LOG_TYPE.VERVOSE, string.Format("[공급계약체결] 매출액 대비율 낮음({0}, {1}% / {2}%)", strCodeName, fRate, m_fSupplyContractRate));
return;
}
string strRef = "Dart API";
string strTitle = string.Format("공급계약체결 - {0} {1:n2}%", strCodeName, fRate);
if((Code.m_enType&CodeList.CODE_TYPE.DENIAL) == CodeList.CODE_TYPE.DENIAL)
Util.Log(Util.LOG_TYPE.DENIAL, string.Format("[{0}] {1}", strRef, strTitle));
else if((Code.m_enType&CodeList.CODE_TYPE.DUPLICATED) == CodeList.CODE_TYPE.DUPLICATED)
Util.Log(Util.LOG_TYPE.DUPLICATED, string.Format("[{0}] {1}", strRef, strTitle));
else if((Code.m_enType&CodeList.CODE_TYPE.MANUAL) == CodeList.CODE_TYPE.MANUAL)
{
Util.Log(Util.LOG_TYPE.MANUAL_CODE, string.Format("[{0}] {1}", strRef, strTitle));
ModelessPopup ManualPopup = new ModelessPopup(this);
ManualPopup.SetMessage(string.Format("{0}\n[{1}] {2}\n\n매수하시겠습니까?",
DateTime.Now.ToString("[hh:mm:ss]"),
strRef, strTitle), Code);
ManualPopup.TopMost = true;
ManualPopup.Show();
}
else
{
Util.Log(Util.LOG_TYPE.POSITIVE, string.Format("[{0}] {1}", strRef, strTitle));
BuyItem(Code);
}
m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName);
}
public void OnSupplyContractRateChanged(float fRate)
{
m_fSupplyContractRate = fRate;
Config.SetSupplyContractRate(fRate);
}
delegate bool IsDuplicatedURLDelegate(string strURL);
public bool IsDuplicatedURL(string strURL)
{
if(lvList.InvokeRequired)
{
lock(m_lvListLock)
return (bool)lvList.Invoke(new IsDuplicatedURLDelegate(IsDuplicatedURL), strURL);
}
else
{
lock(m_lvListLock)
return (strURL != "" && lvList.Items.Cast<ListViewItem>().Any(s => s.SubItems[chLink.Index].Text == strURL));
}
} }
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) public void InsertItem(string strTitle, string strName, string strCode, DateTime time, DateTime ResTime, string strURL, string strRef, double responseT, bool bInitial)
{ {
try try
{ {
if(this.InvokeRequired) if(this.InvokeRequired)
{ {
this.Invoke(new InsertListView(InsertItem), strTitle, strName, strCode, time, ResTime, strURL, strRef, responseT, bInitial); this.Invoke(m_InsertListViewDelegate, strTitle, strName, strCode, time, ResTime, strURL, strRef, responseT, bInitial);
} }
else else
{ {
if(strURL != "" && lvList.Items.Cast<ListViewItem>().Any(s => s.SubItems[chLink.Index].Text == strURL)) if(IsDuplicatedURL(strURL) == true)
return; return;
int iID = lvList.Items.Count+1; int iID = lvList.Items.Count+1;
if(bInitial == false)
ProcessSearchAndBuy(strTitle, strName, strCode, strRef, iID);
lock(m_lvListLock)
{
lvList.Items.Add(new ListViewItem(new string[] { lvList.Items.Add(new ListViewItem(new string[] {
iID.ToString(), iID.ToString(),
time.ToString("HH:mm:ss"), time.ToString("HH:mm:ss"),
@@ -228,567 +344,62 @@ namespace NewsCrawler
"", "",
"", "",
"", "",
"",
"",
strURL })); strURL }));
if(bInitial == false && chAutoSelect.Checked == true)
{
m_bBrowserReload = true;
} }
if(bInitial == false) if(bInitial == false)
{
foreach(ColumnHeader col in lvList.Columns)
{
if(!(col == chPriceS || col == chPriceLow || col == chPriceHigh))
col.Width = -2;
}
}
if(bInitial == false)
{
lvList.Sort(); lvList.Sort();
ProcessSearchAndBuy(strTitle, strName, strCode, strRef, iID);
}
} }
} }
catch(Exception ex) catch(Exception ex)
{ {
Util.Log(Util.LOG_TYPE.ERROR, ex.Message); Util.Log(Util.LOG_TYPE.ERROR, ex.Message + Environment.NewLine + ex.StackTrace);
} }
} }
bool ReadAsiaE(bool bInitial = false)
private void SystemTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
bool bHasNew = false; if(statusBar.InvokeRequired)
try
{ {
string strServerURL = "http://www.asiae.co.kr"; statusBar.BeginInvoke((MethodInvoker)delegate ()
WebRequest request = WebRequest.Create("http://www.asiae.co.kr/news/sokbo/sokbo_left.htm");
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(); statusBar.Items[3].Text = DateTime.Now.ToString("HH:mm:ss");
statusBar.Items[2].Text = m_CybosHelper.GetLimitRemainCountRQ().ToString();
using(Stream dataStream = response.GetResponseStream()) statusBar.Items[0].Text = m_CybosHelper.IsConnected() ? "연결됨" : "연결끊김";
{ });
using(StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("EUC-KR")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
responseFromServer = responseFromServer.Replace("\"\"", "\"");
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(responseFromServer);
string strXPath = "//div[contains(@class, 'txtform')]/ul/li";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
string strTitle1 = item.SelectSingleNode(".//a").GetAttributeValue("title", "");
string strTitle2 = item.SelectSingleNode(".//a").FirstChild.InnerText;
string strTitle = (strTitle1.Length > strTitle2.Length ? strTitle1 : strTitle2);
string strTime = item.SelectSingleNode(".//span").InnerText;
string strURL = strServerURL+item.SelectSingleNode(".//a").GetAttributeValue("href", "");
if(Regex.IsMatch(strTime, @"\d+/\d+")==true)
{
//Console.WriteLine("어제 기사 : " + item.InnerHtml);
continue;
}
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 ReadEtoday(bool bInitial = false)
{
bool bHasNew = false;
try
{
//string strServerURL = "http://www.etoday.co.kr";
WebRequest request = WebRequest.Create("http://www.etoday.co.kr/news/flash/flash_list.php?tab=1");
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")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(responseFromServer);
string strXPath = "//div[contains(@class, 'flash_tab_lst')]/ul/li";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
string strTitle = item.SelectSingleNode(".//a").InnerText;
string strTime = item.SelectSingleNode(".//span[contains(@class, 'flash_press')]").InnerText;
string strURL = item.SelectSingleNode(".//a").GetAttributeValue("href", "");
strURL="http://www.etoday.co.kr/news/section/newsview.php?idxno="+Regex.Replace(strURL, @"\D", "");
if(Regex.IsMatch(strTime, @"\d+/\d+")==true)
{
//Console.WriteLine("어제 기사 : " + item.InnerHtml);
continue;
}
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);
}
}
}
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
return bHasNew;
}
bool ReadDart(bool bInitial = false)
{
bool bHasNew = false;
try
{
string strServerURL = "https://dart.fss.or.kr";
WebRequest request = WebRequest.Create("https://dart.fss.or.kr/dsac001/mainAll.do");
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")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(responseFromServer);
string strXPath = "//div[@id='listContents']/div[contains(@class, 'table_list')]/table/tr";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
var rows = item.SelectNodes(".//td");
if(rows.Count < 3)
continue;
string strTitle = rows[2].InnerText;
strTitle=strTitle.Trim();
string strTime = item.SelectSingleNode(".//td[contains(@class, 'cen_txt')]").InnerText;
strTime=strTime.Trim();
string strURL = rows[2].SelectSingleNode(".//a").GetAttributeValue("href", "");
strURL=strURL.Trim();
strURL =strServerURL+strURL;
if(Regex.IsMatch(strTime, @"\d+/\d+")==true)
{
//Console.WriteLine("어제 기사 : " + item.InnerHtml);
continue;
}
InsertItem(strTitle, "", "",
DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture),
DateTime.Now,
strURL, "DART", timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
return bHasNew;
}
bool ReadKIND(bool bInitial = false)
{
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;
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 = 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;
}
InsertItem(strTitle, "", "",
DateTime.ParseExact(strTime, "HH:mm:ss", CultureInfo.CurrentCulture),
DateTime.Now,
strURL, "KIND", timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
return bHasNew;
}
bool ReadEdaily(bool bInitial = false)
{
bool bHasNew = false;
try
{
string strServerURL = "http://www.edaily.co.kr/news/realtime/realtime_NewsRead.asp";
WebRequest request = WebRequest.Create("http://www.edaily.co.kr/news/realtime/realtime_NewsList_1.asp");
request.Credentials=CredentialCache.DefaultCredentials;
request.Timeout=2000;
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")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(responseFromServer);
string strXPath = "//li[contains(@id, 'NewsIcon')]";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
string strTitle = item.SelectSingleNode(".//a").GetAttributeValue("title", "");
string strTime = item.SelectSingleNode(".//span").InnerText;
string strID = item.GetAttributeValue("id", "");
strID = strID.Substring("NewsIcon_".Length);
string strURL = strServerURL+"?newsid="+strID;
DateTime Time;
DateTime.TryParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture, DateTimeStyles.None, out Time);
if(Time > PrevTime)
break;
PrevTime = Time;
InsertItem(strTitle, "", "", Time, DateTime.Now, strURL, "이데일리", timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
return bHasNew;
}
bool ReadMoneyToday(bool bInitial = false)
{
bool bHasNew = false;
try
{
string strServerURL = "http://news.mt.co.kr/mtview.php?no=";
WebRequest request = WebRequest.Create("http://news.mt.co.kr/newsflash/newsflash.html");
request.Credentials=CredentialCache.DefaultCredentials;
request.Timeout=2000;
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")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(responseFromServer);
string strXPath = "//div[@id='articleList']//li[@class='bundle']";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach(var item in lists)
{
string strTitle = item.SelectSingleNode(".//a").InnerText;
string strTime = item.SelectSingleNode(".//span").InnerText;
string strID = item.SelectSingleNode(".//a").GetAttributeValue("href", "");
int iStart = strID.IndexOf('\'', 0);
iStart = strID.IndexOf('\'', iStart+1);
iStart = strID.IndexOf('\'', iStart+1);
int iEnd = strID.IndexOf('\'', iStart+1);
strID = strID.Substring(iStart+1, iEnd-iStart+1);
string strURL = strServerURL+strID;
DateTime Time;
DateTime.TryParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture, DateTimeStyles.None, out Time);
if(Time > PrevTime)
break;
PrevTime = Time;
InsertItem(strTitle, "", "", Time, DateTime.Now, strURL, "머니투데이", timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
return bHasNew;
}
bool ReadFinacialNews(bool bInitial = false)
{
bool bHasNew = false;
try
{
string strServerURL = "http://www.fnnews.com/news/";
WebRequest request = WebRequest.Create("http://www.fnnews.com/newsflash/today/data?type=json");
request.Credentials=CredentialCache.DefaultCredentials;
request.Timeout=2000;
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());
dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer);
foreach(var data in jObj)
{
string strTitle = data["title"];
string strTime = data["date"];
DateTime Time;
DateTime.TryParseExact(strTime, "yyyy.MM.dd HH:mm", CultureInfo.CurrentCulture, DateTimeStyles.None, out Time);
string strCode = data["code"];
string strURL = strServerURL+strCode;
if(Time.DayOfYear == Today.DayOfYear)
InsertItem(strTitle, "", "", Time, DateTime.Now, strURL, "파이낸셜뉴스", timer.Elapsed.TotalMilliseconds, bInitial);
}
}
}
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
return bHasNew;
}
private void UpdateBrowser()
{
if(lvList.InvokeRequired == true)
{
lvList.Invoke(new Action(UpdateBrowser));
} }
else else
{ {
if(chAutoSelect.Checked == true && m_bBrowserReload == true) statusBar.Items[3].Text = DateTime.Now.ToString("HH:mm:ss");
{ statusBar.Items[2].Text = m_CybosHelper.GetLimitRemainCountRQ().ToString();
if(lvList.SelectedItems.Count == 0 || lvList.SelectedItems[0].Index != lvList.Items.Count-1) statusBar.Items[0].Text = m_CybosHelper.IsConnected() ? "연결됨" : "연결끊김";
{ }
lvList.Items[lvList.Items.Count - 1].Selected = true;
lvList.Select();
if(lvList.SelectedItems.Count > 0)
lvList.SelectedItems[0].EnsureVisible();
} }
m_bBrowserReload = false;
}
}
}
private void CrawlTimer_Tick(object sender, EventArgs e) private void CrawlTimer_Tick(object sender, EventArgs e)
{ {
m_CrawlTimer.Enabled = false; m_CrawlTimer.Stop();
//Console.WriteLine(string.Format("timer thread {0}", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()));
if(chAutoReload.Checked == true) if(chAutoReload.Checked == true)
{ {
ReadKIND(); m_Crawler.ReadKIND();
ReadDart(); m_Crawler.ReadDart();
ReadAsiaE(); m_Crawler.ReadDartAPI();
ReadEtoday(); m_Crawler.ReadEtoday();
ReadEToday2(); m_Crawler.ReadEtoday2();
ReadEdaily(); m_Crawler.ReadAsiaE();
ReadMoneyToday(); m_Crawler.ReadEdaily();
ReadFinacialNews(); m_Crawler.ReadMoneyToday();
m_Crawler.ReadFinancialNews();
} }
UpdateBrowser();
m_CrawlTimer.Interval = m_iCrawlInterval; m_CrawlTimer.Interval = m_iCrawlInterval;
m_CrawlTimer.Enabled = true; m_CrawlTimer.Start();
} }
private void UpdateStartPrice(int iID, int iPrice) private void UpdateStartPrice(int iID, int iPrice)
@@ -815,20 +426,47 @@ namespace NewsCrawler
lvList.BeginInvoke((MethodInvoker)delegate () lvList.BeginInvoke((MethodInvoker)delegate ()
{ {
ListViewItem item = lvList.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chId.Index].Text == iID.ToString()); ListViewItem item = lvList.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chId.Index].Text == iID.ToString());
item.SubItems[chPriceLow.Index].Text = string.Format("{0:n0}({1:n}%)", iPriceLow, iPriceLow/(float)iPriceStart); item.SubItems[chPriceLow.Index].Text = string.Format("{0:n0}", iPriceLow);
item.SubItems[chPriceHigh.Index].Text = string.Format("{0:0}({1:n}%)", iPriceHigh, iPriceHigh/(float)iPriceStart); float fLowRate = (iPriceLow-iPriceStart)*100/(float)iPriceStart;
item.SubItems[chPriceLowP.Index].Text = string.Format("{0:n}", fLowRate);
if(fLowRate > 0)
item.SubItems[chPriceLowP.Index].ForeColor = Color.Red;
else if(fLowRate < 0)
item.SubItems[chPriceLowP.Index].ForeColor = Color.Blue;
item.SubItems[chPriceHigh.Index].Text = string.Format("{0:n0}", iPriceHigh);
float fLowHigh = (iPriceHigh-iPriceStart)*100/(float)iPriceStart;
item.SubItems[chPriceHighP.Index].Text = string.Format("{0:n}", fLowHigh);
if(fLowHigh > 0)
item.SubItems[chPriceHighP.Index].ForeColor = Color.Red;
else if(fLowHigh < 0)
item.SubItems[chPriceHighP.Index].ForeColor = Color.Blue;
}); });
} }
else else
{ {
ListViewItem item = lvList.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chId.Index].Text == iID.ToString()); ListViewItem item = lvList.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chId.Index].Text == iID.ToString());
item.SubItems[chPriceLow.Index].Text = string.Format("{0:n0}({1:n}%)", iPriceLow, iPriceLow/(float)iPriceStart); item.SubItems[chPriceLow.Index].Text = string.Format("{0:n0}", iPriceLow);
item.SubItems[chPriceHigh.Index].Text = string.Format("{0:0}({1:n}%)", iPriceHigh, iPriceHigh/(float)iPriceStart); float fLowRate = (iPriceLow-iPriceStart)*100/(float)iPriceStart;
item.SubItems[chPriceLowP.Index].Text = string.Format("{0:n}", fLowRate);
if(fLowRate > 0)
item.SubItems[chPriceLowP.Index].ForeColor = Color.Red;
else if(fLowRate < 0)
item.SubItems[chPriceLowP.Index].ForeColor = Color.Blue;
item.SubItems[chPriceHigh.Index].Text = string.Format("{0:n0}", iPriceHigh);
float fLowHigh = (iPriceHigh-iPriceStart)*100/(float)iPriceStart;
item.SubItems[chPriceHighP.Index].Text = string.Format("{0:n}", fLowHigh);
if(fLowHigh > 0)
item.SubItems[chPriceHighP.Index].ForeColor = Color.Red;
else if(fLowHigh < 0)
item.SubItems[chPriceHighP.Index].ForeColor = Color.Blue;
} }
} }
private void PriceCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void PriceCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
if(cbPriceCheck.Checked == false)
return;
m_PriceCheckTimer.Enabled = false; m_PriceCheckTimer.Enabled = false;
DateTime CurTime = DateTime.Now; DateTime CurTime = DateTime.Now;
@@ -839,9 +477,10 @@ namespace NewsCrawler
data.m_iPriceStart = m_CybosHelper.GetCurPrice(data.m_Code); data.m_iPriceStart = m_CybosHelper.GetCurPrice(data.m_Code);
UpdateStartPrice(data.m_iID, data.m_iPriceStart); UpdateStartPrice(data.m_iID, data.m_iPriceStart);
} }
else if(data.m_iPriceHigh == 0 && (CurTime - data.m_StartTime).Minutes >= 1) else if(data.m_iPriceHigh == 0 && (CurTime - data.m_StartTime).Minutes >= 5)
{ {
m_CybosHelper.GetLowHighPrice(data.m_Code, data.m_StartTime, 5, out data.m_iPriceLow, out data.m_iPriceHigh); m_CybosHelper.GetLowHighPrice(data.m_Code, data.m_StartTime, 5, out data.m_iPriceLow, out data.m_iPriceHigh);
data.m_iTryCnt++;
if(data.m_iPriceHigh > 0) if(data.m_iPriceHigh > 0)
UpdateLowHighPrice(data.m_iID, data.m_iPriceStart, data.m_iPriceLow, data.m_iPriceHigh); UpdateLowHighPrice(data.m_iID, data.m_iPriceStart, data.m_iPriceLow, data.m_iPriceHigh);
} }
@@ -853,7 +492,7 @@ namespace NewsCrawler
if(m_PriceCheckList.TryPeek(out data) == false) if(m_PriceCheckList.TryPeek(out data) == false)
break; break;
if(data.m_iPriceHigh == 0) if(data.m_iTryCnt < 3 && data.m_iPriceHigh == 0)
break; break;
m_PriceCheckList.TryDequeue(out data); m_PriceCheckList.TryDequeue(out data);
@@ -863,16 +502,6 @@ namespace NewsCrawler
m_PriceCheckTimer.Enabled = true; m_PriceCheckTimer.Enabled = true;
} }
private void lvList_SelectedIndexChanged(object sender, EventArgs e)
{
if(lvList.SelectedItems.Count <= 0)
return;
string strURL = lvList.SelectedItems[0].SubItems[chLink.Index].Text;
wbView.ScriptErrorsSuppressed = true;
//wbView.Navigate(strURL);
}
private void tbInterval_KeyPress(object sender, KeyPressEventArgs e) private void tbInterval_KeyPress(object sender, KeyPressEventArgs e)
{ {
if(e.KeyChar == Convert.ToChar(Keys.Enter)) if(e.KeyChar == Convert.ToChar(Keys.Enter))
@@ -894,6 +523,21 @@ namespace NewsCrawler
lvList.Sort(); lvList.Sort();
} }
private void lvList_DoubleClick(object sender, EventArgs e)
{
if(lvList.SelectedItems.Count < 1)
return;
string strLink = lvList.SelectedItems[0].SubItems[chLink.Index].Text;
try
{
System.Diagnostics.Process.Start(strLink);
} catch
{
}
}
private void btnConfig_Click(object sender, EventArgs e) private void btnConfig_Click(object sender, EventArgs e)
{ {
if(m_ConfigForm == null) if(m_ConfigForm == null)

View File

@@ -117,4 +117,10 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="statusBar.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>96</value>
</metadata>
</root> </root>

View File

@@ -93,6 +93,9 @@ namespace NewsCrawler
public static void Log(LOG_TYPE enType, string strLog) public static void Log(LOG_TYPE enType, string strLog)
{ {
if(strLog.Contains("인덱스"))
Console.WriteLine("ddddddddd");
if(Directory.Exists(GetLogPath()) == false) if(Directory.Exists(GetLogPath()) == false)
Directory.CreateDirectory(GetLogPath()); Directory.CreateDirectory(GetLogPath());