- 가격체크된 항목 csv로 저장

This commit is contained in:
2017-01-30 03:44:40 +09:00
parent 8c6d265ef9
commit a5d25b41fc
2 changed files with 125 additions and 115 deletions

View File

@@ -1,32 +1,32 @@
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Runtime.InteropServices;
//using System.Text;
//using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
//using Excel = Microsoft.Office.Interop.Excel;
//using System.Reflection;
//namespace NewsCrawler
//{
// public class ExcelHandler
// {
// bool m_bAvailable = true;
// string m_strFileName = "";
// string m_strToday = DateTime.Now.ToString("yyyy-MM-dd");
using System.Reflection;
namespace NewsCrawler
{
public class ExcelHandler
{
bool m_bAvailable = true;
string m_strFileName = "";
string m_strToday = DateTime.Now.ToString("yyyy-MM-dd");
// public ExcelHandler(string strFileName)
// {
// m_strFileName = strFileName;
// }
public ExcelHandler(string strFileName)
{
m_strFileName = strFileName;
}
// public bool IsAvailable()
// {
// return m_bAvailable;
// }
public bool IsAvailable()
{
return m_bAvailable;
}
// private void Create()
// {
private void Create()
{
//try
//{
// Excel.Application App = new Excel.Application();
@@ -63,17 +63,26 @@
//{
// Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
//}
// }
// public bool AddRow(string strNewsTime, string strResTime, string strRef, string strTitle, float fReqTime, int iPriceS, int iPriceLow, float fPriceLowP, int iPriceHigh, float fPriceHighP, string strLink)
// {
// lock(this)
// {
// if(m_bAvailable == false)
// return false;
string strMessage = "날짜, 기사 시간, 받은 시간, 요청 시간, 출처, 제목, 종목명, 시가, 저가, 대비, 고가, 대비, 링크";
File.AppendAllText(m_strFileName, strMessage+Environment.NewLine, new UTF8Encoding(true));
}
// if(File.Exists(m_strFileName) == false)
// Create();
public bool AddRow(string strNewsTime, string strResTime, float fReqTime, string strRef, string strTitle, string strCodeName,
int iPriceS, int iPriceLow, float fPriceLowP, int iPriceHigh, float fPriceHighP, string strLink)
{
lock(this)
{
if(m_bAvailable == false)
return false;
if(File.Exists(m_strFileName) == false)
Create();
string strMessage = string.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7:n0}, {8:n0}, {9:n2}, {10:n0}, {11:n2}, {12}",
m_strToday, strNewsTime, strResTime, fReqTime, strRef, strTitle, strCodeName,
iPriceS, iPriceLow, fPriceLowP, iPriceHigh, fPriceHighP, strLink);
File.AppendAllText(m_strFileName, strMessage+Environment.NewLine, new UTF8Encoding(true));
//try
//{
@@ -111,9 +120,9 @@
// Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
// return false;
//}
// }
}
// return true;
// }
// }
//}
return true;
}
}
}

View File

@@ -88,7 +88,7 @@ namespace NewsCrawler
Crawler m_Crawler = null;
//ExcelHandler m_Excel = null;
ExcelHandler m_Excel = null;
object m_lvListLock = new object();
@@ -153,7 +153,7 @@ namespace NewsCrawler
// col.Width = -2;
//}
//m_Excel = new ExcelHandler(Util.GetLogPath()+"/PriceCheck"+DateTime.Now.ToString("yyyy-MM-dd")+".xlsx");
m_Excel = new ExcelHandler(Util.GetLogPath()+"/PriceCheck"+DateTime.Now.ToString("yyyy-MM-dd")+".csv");
m_CrawlTimer.Elapsed+=CrawlTimer_Tick;
m_CrawlTimer.Interval = m_iCrawlInterval;
@@ -672,14 +672,15 @@ namespace NewsCrawler
if(Data.m_iTryCnt < 3 && Data.m_iPriceHigh == 0)
break;
//if(Data.m_bLog == false)
//{
// Data.m_bLog = m_Excel.AddRow(Data.m_NewsItem.m_NewsTime.ToString("HH:mm:ss:fff"), Data.m_NewsItem.m_ResTime.ToString("HH:mm:ss:fff"), Data.m_NewsItem.m_strRef, Data.m_NewsItem.m_strTitle, Data.m_NewsItem.m_fElapseT,
// Data.m_iPriceStart,
// Data.m_iPriceLow, (Data.m_iPriceLow-Data.m_iPriceStart)*100/(float)Data.m_iPriceStart,
// Data.m_iPriceHigh, (Data.m_iPriceHigh-Data.m_iPriceStart)*100/(float)Data.m_iPriceStart,
// Data.m_NewsItem.m_strURL);
//}
if(Data.m_bLog == false)
{
Data.m_bLog = m_Excel.AddRow(Data.m_NewsItem.m_NewsTime.ToString("HH:mm:ss:fff"), Data.m_NewsItem.m_ResTime.ToString("HH:mm:ss:fff"), Data.m_NewsItem.m_fElapseT,
Data.m_NewsItem.m_strRef, Data.m_NewsItem.m_strTitle, Data.m_NewsItem.m_Code.m_strName,
Data.m_iPriceStart,
Data.m_iPriceLow, (Data.m_iPriceLow-Data.m_iPriceStart)*100/(float)Data.m_iPriceStart,
Data.m_iPriceHigh, (Data.m_iPriceHigh-Data.m_iPriceStart)*100/(float)Data.m_iPriceStart,
Data.m_NewsItem.m_strURL);
}
if(Data.m_bLog == false)
break;