public void Execute(IJobExecutionContext context) { logger.Info("Start job Hangyezhishu"); string sqlstring = @"select * from hangyezhishu where record_date ='" + DateTime.Today.ToString("yyyy-MM-dd") + "' and business_type='行业资金'"; DataSet ds = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring, null); DataTable data = ds.Tables[0]; if (data.Rows.Count == 0) { var hangye1 = "http://q.10jqka.com.cn/thshy/index/field/199112/order/desc/page/1/ajax/1/"; var hangye2 = "http://q.10jqka.com.cn/thshy/index/field/199112/order/desc/page/2/ajax/1/"; SaveData(hangye1, "行业资金"); SaveData(hangye2, "行业资金"); } //string sqlstring2 = @"select * from hangyezhishu where record_date ='" + DateTime.Today.ToString("yyyy-MM-dd") + "' and business_type='概念资金'"; //DataSet ds2 = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring2, null); //DataTable data2 = ds2.Tables[0]; //if (data2.Rows.Count == 0) //{ // var ganlian1 = "http://data.10jqka.com.cn/funds/gnzjl/field/tradezdf/order/desc/page/1/ajax/1/"; // var ganlian2 = "http://data.10jqka.com.cn/funds/gnzjl/field/tradezdf/order/desc/page/2/ajax/1/"; // var ganlian3 = "http://data.10jqka.com.cn/funds/gnzjl/field/tradezdf/order/desc/page/3/ajax/1/"; // SaveData(ganlian1, "概念资金"); // SaveData(ganlian2, "概念资金"); // SaveData(ganlian3, "概念资金"); //} logger.Info("End job Hangyezhishu"); }
public void Execute(IJobExecutionContext context) { logger.Info("Start job Xuanguzuhe"); try { string sqlstring = string.Format(@"SELECT stock_code,stock_name,count(1) FROM tonghuashunxuangu2 WHERE record_date = '{0}' GROUP BY stock_code,stock_name ORDER BY count(1) DESC", DateTime.Today.ToString("yyyy-MM-dd")); DataSet ds = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring, null); DataTable data = ds.Tables[0]; List <string> zuheList = new List <string>(); string sqlstring3 = string.Format(@"SELECT * from xuanguzuhe"); DataSet ds3 = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring3, null); DataTable data3 = ds3.Tables[0]; for (int i = 0; i < data3.Rows.Count; i++) { zuheList.Add(data3.Rows[i]["ids"].ToString()); } sqlstring = string.Format(@"SELECT stock_code,stock_name,typeid FROM tonghuashunxuangu2 WHERE record_date = '{0}' order by typeid", DateTime.Today.ToString("yyyy-MM-dd")); DataSet ds2 = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring, null); DataTable data2 = ds2.Tables[0]; Parallel.For(0, data.Rows.Count, (i, loopState) => { var code = data.Rows[i]["stock_code"].ToString(); DataRow[] drs = data2.Select("stock_code='" + code + "'"); List <int> typeidList = new List <int>(); for (int j = 0; j < drs.Length; j++) { int typeid = int.Parse(drs[j]["typeid"].ToString()); if (!typeidList.Contains(typeid)) { typeidList.Add(typeid); } } string zuheids = string.Join(",", typeidList.ToArray()); if (!zuheList.Contains(zuheids)) { zuheList.Add(zuheids); string sqlstring2 = string.Format(@"Insert into xuanguzuhe(name,ids,number)values('选股组合','{0}',{1})", zuheids, typeidList.Count); Dbhelper.ExecuteNonQuery(Dbhelper.Conn, CommandType.Text, sqlstring2); } string sqlstring4 = string.Format(@"Insert into xuanguzuhegu(zuheids,stock_code,stock_name,record_date,record_time)values('{0}','{1}','{2}','{3}','{4}')", zuheids, drs[0]["stock_code"].ToString(), drs[0]["stock_name"].ToString(), DateTime.Today.ToString("yyyy-MM-dd"), DateTime.Now.ToString("HH:mm:ss")); Dbhelper.ExecuteNonQuery(Dbhelper.Conn, CommandType.Text, sqlstring4); }); } catch (Exception ex) { logger.Info("发生错误:" + ex.Message); } logger.Info("End job Xuanguzuhe"); }
public void Execute(IJobExecutionContext context) { try { string path = Environment.CurrentDirectory + "\\stock_data"; WebClient client = new WebClient(); string sqlstring = @"select DISTINCT stock_code from hangyestockinfo where stock_code not in(select DISTINCT stock_code from StockDataQuartz)"; DataSet ds = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring, null); DataTable data = ds.Tables[0]; List <string> nodatacode = new List <string>(); Console.WriteLine("The first time download data."); for (int i = 0; i < data.Rows.Count; i++) { Console.WriteLine(i.ToString() + "、" + data.Rows[i][0].ToString()); string url = "http://quotes.money.163.com/service/chddata.html?code=0" + data.Rows[i][0].ToString() + "&start=20000101&end=20161208&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP"; string fileName; if (HttpDownloadFile(client, url, path, data.Rows[i][0].ToString(), out fileName)) { nodatacode.Add(data.Rows[i][0].ToString()); } else { SaveFile(fileName); } } Console.WriteLine("The second time download data."); for (int i = 0; i < nodatacode.Count; i++) { Console.WriteLine(i.ToString() + "、" + nodatacode[i]); string url = "http://quotes.money.163.com/service/chddata.html?code=1" + nodatacode[i] + "&start=20000101&end=20161208&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP"; string fileName; if (HttpDownloadFile(client, url, path, nodatacode[i], out fileName)) { nodatacode.Add(nodatacode[i]); } else { SaveFile(fileName); } } } catch (Exception ex) { Console.WriteLine("An error occurred." + ex.Message); } Console.WriteLine("download data done"); Console.ReadKey(); }
public void Execute(IJobExecutionContext context) { logger.Info("Start job Shishidadan"); try { logger.Info("开始下载数据任务........"); string sqlstring = @"select DISTINCT stock_code from hangyestockinfo where stock_code not in (SELECT DISTINCT stock_code from shishidadan where record_date='" + DateTime.Today.ToString("yyyy-MM-dd") + "')"; DataSet ds = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring); DataTable data = ds.Tables[0]; List <string> nodatacode = new List <string>(); Dictionary <string, int> codepage = new Dictionary <string, int>(); logger.Info("获取股票代码,记录数:" + data.Rows.Count.ToString()); logger.Info("开始获取页数。"); Parallel.For(0, data.Rows.Count, (i, loopState) => { if (data.Rows[i][0] != null && data.Rows[i][0].ToString().Length > 1) { var code = data.Rows[i][0].ToString(); var url = "http://quotes.money.163.com/trade/ddtj_" + code + ".html?amount=1000000"; int page = GetPages(url); if (page > 0) { codepage.Add(code, page); } } }); logger.Info("开始下载数据。"); int ind = 0; Parallel.ForEach(codepage, (item, loopState) => { ind++; //logger.Info(string.Format("进度:{0}/{1}", ind, codepage.Count)); for (int i = 0; i < item.Value; i++) { var url = "http://quotes.money.163.com/trade/ddtj_" + item.Key + "," + i + ".html?amount=1000000"; GetContent(url, item.Key); } }); logger.Info("下载数据完成。"); } catch (Exception ex) { logger.Info("发生错误:" + ex.Message); } logger.Info("End job Shishidadan"); }
public void Execute(IJobExecutionContext context) { logger.Info("Start job Zhengu"); string sqlstring = @"select DISTINCT stock_code from hangyestockinfo where stock_code not in (SELECT DISTINCT stock_code from zhengu where record_date='" + DateTime.Today.ToString("yyyy-MM-dd") + "')"; DataSet ds = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring, null); DataTable data = ds.Tables[0]; for (int i = 0; i < data.Rows.Count; i++) { string URLAddress = "http://doctor.10jqka.com.cn/" + data.Rows[i][0].ToString() + "/"; SaveData(data.Rows[i][0].ToString(), URLAddress); } ; logger.Info("End job Zhengu"); }
public void Execute(IJobExecutionContext context) { logger.Info("Start job Tonghuashunxuangu2"); string sqlstring = @"select * from tonghuashunxuangu"; DataSet ds = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring, null); DataTable data = ds.Tables[0]; TonghuashunCommon common = new TonghuashunCommon(); List <string> proxyUrl = common.GetProxyURL(logger); for (int i = 0; i < data.Rows.Count; i++) { string url = data.Rows[i]["url"].ToString(); string id = data.Rows[i]["ID"].ToString(); common.SaveDataJSON(url, id, logger, "tonghuashunxuangu2", proxyUrl); } ; logger.Info("End job Tonghuashunxuangu2"); }
public async void Execute(IJobExecutionContext context) { logger.Info("Start job Tonghuashunxuangu"); string sqlstring = @"SELECT secondtitle FROM tonghuashunxuangu"; DataSet ds = Dbhelper.ExecuteDataset(Dbhelper.Conn, CommandType.Text, sqlstring, null); data = ds.Tables[0]; string URLAddress = "http://www.iwencai.com/stockpick?tid=stockpick&ts=1&qs=1"; //WebClient client = new WebClient(); //client.Encoding = System.Text.Encoding.GetEncoding("UTF-8"); try { TonghuashunCommon common = new TonghuashunCommon(); proxyUrl = common.GetProxyURL(logger); string html = await common.GetHtml(URLAddress, logger, proxyUrl, "UTF-8"); HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.LoadHtml(html); HtmlNode Node1 = htmlDoc.DocumentNode; var trnodes1 = Node1.SelectNodes("//*[@id=\"area_list\"]/div"); if (trnodes1 != null) { foreach (var item in trnodes1) { var firsttitle = item.SelectSingleNode("child::h4[1]").SelectSingleNode("child::span[1]").InnerText.Trim(); if (firsttitle == "火力推荐") { var hltj = Node1.SelectNodes("//*[@id=\"hltj_right_hc_query_li_st\"]/ul/li"); if (hltj != null) { foreach (var item2 in hltj) { var typename = item2.SelectSingleNode("child::span[1]").InnerText.Trim(); var secondtitle = item2.SelectSingleNode("child::div[1]").SelectSingleNode("child::a[1]").InnerText.Trim(); var url = item2.SelectSingleNode("child::div[1]").SelectSingleNode("child::a[1]").Attributes["href"].Value; SaveDataDB(firsttitle, typename, secondtitle, url); } } } if (firsttitle == "问句集锦") { var wjjj = Node1.SelectNodes("//*[@id=\"lm_zxwj\"]/dl"); if (wjjj != null) { foreach (var item2 in wjjj) { var secondtitle = item2.SelectSingleNode("child::dd[1]").SelectSingleNode("child::a[1]").InnerText.Trim(); var url = item2.SelectSingleNode("child::dd[1]").SelectSingleNode("child::a[1]").Attributes["href"].Value; SaveDataDB(firsttitle, "", secondtitle, url); } } var jdwj = Node1.SelectNodes("//*[@id=\"lm_jdwj\"]/dl"); if (jdwj != null) { foreach (var item2 in jdwj) { var secondtitle = item2.SelectSingleNode("child::dd[1]").SelectSingleNode("child::a[1]").InnerText.Trim(); var url = item2.SelectSingleNode("child::dd[1]").SelectSingleNode("child::a[1]").Attributes["href"].Value; SaveDataDB(firsttitle, "", secondtitle, url); } } } if (firsttitle == "技术指标") { var jszb = Node1.SelectNodes("//*[@id=\"area_list\"]/div[4]/div/div/div/div/div/dl"); jishuzhibiao(jszb, firsttitle); } if (firsttitle == "形态选股") { var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[5]/div/div/div/div/div/dl"); jishuzhibiao(xtxg, firsttitle); } if (firsttitle == "行情指标") { var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[7]/div/div/div/div/div/dl"); jishuzhibiao(xtxg, firsttitle); } if (firsttitle == "牛股抓选") { var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[8]/div/div/div/div/div/dl"); jishuzhibiao(xtxg, firsttitle); } if (firsttitle == "持股周期") { var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[9]/div/div/div/div/div/dl"); jishuzhibiao(xtxg, firsttitle); } if (firsttitle == "股本股东") { var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[10]/div/div/div/div/div/dl"); jishuzhibiao(xtxg, firsttitle); } if (firsttitle == "主力动向") { var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[11]/div/div/div/div/div/dl"); jishuzhibiao(xtxg, firsttitle); } if (firsttitle == "特色数据") { var xtxg = Node1.SelectNodes("//*[@id=\"area_list\"]/div[12]/div/div/div/div/div/dl"); jishuzhibiao(xtxg, firsttitle); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } logger.Info("End job Tonghuashunxuangu"); }