- 가격체크된 항목 csv로 저장
This commit is contained in:
219
ExcelHandler.cs
219
ExcelHandler.cs
@@ -1,119 +1,128 @@
|
||||
//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()
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// Excel.Application App = new Excel.Application();
|
||||
// if(App == null)
|
||||
// {
|
||||
// Util.Log(Util.LOG_TYPE.ERROR, "엑셀이 설치되지 않음");
|
||||
// m_bAvailable = false;
|
||||
// return;
|
||||
// }
|
||||
private void Create()
|
||||
{
|
||||
//try
|
||||
//{
|
||||
// Excel.Application App = new Excel.Application();
|
||||
// if(App == null)
|
||||
// {
|
||||
// Util.Log(Util.LOG_TYPE.ERROR, "엑셀이 설치되지 않음");
|
||||
// m_bAvailable = false;
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Excel._Workbook Workbook = App.Workbooks.Add(Missing.Value);
|
||||
// Excel._Worksheet Worksheet = Workbook.ActiveSheet;
|
||||
// Excel._Workbook Workbook = App.Workbooks.Add(Missing.Value);
|
||||
// Excel._Worksheet Worksheet = Workbook.ActiveSheet;
|
||||
|
||||
// Worksheet.Cells[1, 1] = "날짜";
|
||||
// Worksheet.Cells[1, 2] = "기사 시간";
|
||||
// Worksheet.Cells[1, 3] = "받은 시간";
|
||||
// Worksheet.Cells[1, 4] = "출처";
|
||||
// Worksheet.Cells[1, 5] = "제목";
|
||||
// Worksheet.Cells[1, 6] = "요청 시간";
|
||||
// Worksheet.Cells[1, 7] = "시가";
|
||||
// Worksheet.Cells[1, 8] = "저가";
|
||||
// Worksheet.Cells[1, 9] = "대비";
|
||||
// Worksheet.Cells[1, 10] = "고가";
|
||||
// Worksheet.Cells[1, 11] = "대비";
|
||||
// Worksheet.Cells[1, 12] = "링크";
|
||||
// Worksheet.Cells[1, 1] = "날짜";
|
||||
// Worksheet.Cells[1, 2] = "기사 시간";
|
||||
// Worksheet.Cells[1, 3] = "받은 시간";
|
||||
// Worksheet.Cells[1, 4] = "출처";
|
||||
// Worksheet.Cells[1, 5] = "제목";
|
||||
// Worksheet.Cells[1, 6] = "요청 시간";
|
||||
// Worksheet.Cells[1, 7] = "시가";
|
||||
// Worksheet.Cells[1, 8] = "저가";
|
||||
// Worksheet.Cells[1, 9] = "대비";
|
||||
// Worksheet.Cells[1, 10] = "고가";
|
||||
// Worksheet.Cells[1, 11] = "대비";
|
||||
// Worksheet.Cells[1, 12] = "링크";
|
||||
|
||||
// Workbook.SaveAs(m_strFileName, Excel.XlFileFormat.xlOpenXMLWorkbook, Missing.Value,
|
||||
// Missing.Value, false, false, Excel.XlSaveAsAccessMode.xlNoChange,
|
||||
// Excel.XlSaveConflictResolution.xlUserResolution, true,
|
||||
// Missing.Value, Missing.Value, Missing.Value);
|
||||
// Workbook.Close();
|
||||
// }
|
||||
// catch(Exception ex)
|
||||
// {
|
||||
// Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
|
||||
// }
|
||||
// }
|
||||
// Workbook.SaveAs(m_strFileName, Excel.XlFileFormat.xlOpenXMLWorkbook, Missing.Value,
|
||||
// Missing.Value, false, false, Excel.XlSaveAsAccessMode.xlNoChange,
|
||||
// Excel.XlSaveConflictResolution.xlUserResolution, true,
|
||||
// Missing.Value, Missing.Value, Missing.Value);
|
||||
// Workbook.Close();
|
||||
//}
|
||||
//catch(Exception ex)
|
||||
//{
|
||||
// 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;
|
||||
|
||||
// try
|
||||
// {
|
||||
// Excel.Application App = new Excel.Application();
|
||||
// if(App == null)
|
||||
// {
|
||||
// Util.Log(Util.LOG_TYPE.ERROR, "엑셀이 설치되지 않음");
|
||||
// m_bAvailable = false;
|
||||
// return false;
|
||||
// }
|
||||
// App.DisplayAlerts = false;
|
||||
if(File.Exists(m_strFileName) == false)
|
||||
Create();
|
||||
|
||||
// Excel._Workbook Workbook = App.Workbooks.Open(m_strFileName);
|
||||
// Excel._Worksheet Worksheet = Workbook.ActiveSheet;
|
||||
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));
|
||||
|
||||
// int iRow = Worksheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing).Row+1;
|
||||
// Worksheet.Cells[iRow, 1] = m_strToday;
|
||||
// Worksheet.Cells[iRow, 2] = strNewsTime;
|
||||
// Worksheet.Cells[iRow, 3] = strResTime;
|
||||
// Worksheet.Cells[iRow, 4] = strRef;
|
||||
// Worksheet.Cells[iRow, 5] = strTitle;
|
||||
// Worksheet.Cells[iRow, 6] = fReqTime;
|
||||
// Worksheet.Cells[iRow, 7] = iPriceS;
|
||||
// Worksheet.Cells[iRow, 8] = iPriceLow;
|
||||
// Worksheet.Cells[iRow, 9] = fPriceLowP;
|
||||
// Worksheet.Cells[iRow, 10] = iPriceHigh;
|
||||
// Worksheet.Cells[iRow, 11] = fPriceHighP;
|
||||
// Worksheet.Cells[iRow, 12] = strLink;
|
||||
//try
|
||||
//{
|
||||
// Excel.Application App = new Excel.Application();
|
||||
// if(App == null)
|
||||
// {
|
||||
// Util.Log(Util.LOG_TYPE.ERROR, "엑셀이 설치되지 않음");
|
||||
// m_bAvailable = false;
|
||||
// return false;
|
||||
// }
|
||||
// App.DisplayAlerts = false;
|
||||
|
||||
// Workbook.Save();
|
||||
// Workbook.Close();
|
||||
// }
|
||||
// catch(Exception ex)
|
||||
// {
|
||||
// Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// Excel._Workbook Workbook = App.Workbooks.Open(m_strFileName);
|
||||
// Excel._Worksheet Worksheet = Workbook.ActiveSheet;
|
||||
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
// int iRow = Worksheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing).Row+1;
|
||||
// Worksheet.Cells[iRow, 1] = m_strToday;
|
||||
// Worksheet.Cells[iRow, 2] = strNewsTime;
|
||||
// Worksheet.Cells[iRow, 3] = strResTime;
|
||||
// Worksheet.Cells[iRow, 4] = strRef;
|
||||
// Worksheet.Cells[iRow, 5] = strTitle;
|
||||
// Worksheet.Cells[iRow, 6] = fReqTime;
|
||||
// Worksheet.Cells[iRow, 7] = iPriceS;
|
||||
// Worksheet.Cells[iRow, 8] = iPriceLow;
|
||||
// Worksheet.Cells[iRow, 9] = fPriceLowP;
|
||||
// Worksheet.Cells[iRow, 10] = iPriceHigh;
|
||||
// Worksheet.Cells[iRow, 11] = fPriceHighP;
|
||||
// Worksheet.Cells[iRow, 12] = strLink;
|
||||
|
||||
// Workbook.Save();
|
||||
// Workbook.Close();
|
||||
//}
|
||||
//catch(Exception ex)
|
||||
//{
|
||||
// Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
|
||||
// return false;
|
||||
//}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
21
NewsForm.cs
21
NewsForm.cs
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user