public override void Init() { int DaysDiff = -1; if (DateTime.Now.Hour >= 18) { DaysDiff = 0; } if (!String.IsNullOrEmpty(Setting.AppSettings("SpecifiedDate"))) { DaysDiff = Int32.Parse(Setting.AppSettings("SpecifiedDate")); } GetDate = GetDate.AddDays(DaysDiff); CheckDoneDirPath = AppDomain.CurrentDomain.BaseDirectory + @"\CheckDone\DeilyPriceGTSM\"; CheckDoneFileName = GetDate.ToString("yyyyMMdd") + ".txt"; CheckDoneFullPath = CheckDoneDirPath + CheckDoneFileName; if (!System.IO.Directory.Exists(CheckDoneDirPath)) { System.IO.Directory.CreateDirectory(CheckDoneDirPath); } DownloadDirPath = AppDomain.CurrentDomain.BaseDirectory + @"\DataSource\GTSMStockPrice\"; DownloadFileName = TokenGenerator.GetTimeStamp(3) + ".csv"; DownloadFullPath = DownloadDirPath + DownloadFileName; if (!System.IO.Directory.Exists(DownloadDirPath)) { System.IO.Directory.CreateDirectory(DownloadDirPath); } }
public DeilyPriceGTSMCrawlerServcies() { DownloadUrl = Setting.AppSettings("GTSMStockPriceURL"); UploadUrl = Setting.AppSettings("ReceiveByDeilyPriceURL"); GetDate = DateTime.Now; StockPricesList = new List <StockPriceDataModel>(); }
public override void CheckIsDone() { if (System.IO.File.Exists(CheckDoneFullPath)) { throw new Exception("[" + GetDate.ToString("yyyyMMdd") + "]Before Done, do nothing!"); } if (Setting.AppSettings("DeilyPriceGTSMAlwaysGetYN") != "Y") { if ((GetDate.Hour <= 18 && GetDate.Hour >= 8)) { throw new Exception("[" + GetDate.ToString("yyyyMMdd") + "]8~18交易時間禁止抓取!"); } } }
public static List <HighQualityListModel> QueryHighQualityListForSlot() { List <QueryHighQualityListForSlot_Result> SpHighQualityList = new List <QueryHighQualityListForSlot_Result>(); List <HighQualityListModel> HighQualityList = new List <HighQualityListModel>(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <QueryHighQualityList_Result, HighQualityListModel>(); }); IMapper iMapper = config.CreateMapper(); using (StockEntities db = new StockEntities()) { SpHighQualityList = db.QueryHighQualityListForSlot(0.05).ToList(); } SpHighQualityList.ForEach(t => { HighQualityListModel r = iMapper.Map <QueryHighQualityListForSlot_Result, HighQualityListModel>(t); HighQualityList.Add(r); }); for (int i = 0; i < HighQualityList.Count; i = i + 100) { var items = HighQualityList.Skip(i).Take(100); ReceiveByHighQualityListReqModel r = new ReceiveByHighQualityListReqModel(); r.HighQualityStock = items.ToList <HighQualityListModel>(); var jsonText = "{\"ReqParam\" : " + JsonConvert.SerializeObject(r) + @"}"; LogHelper.doLog("StableStockServices_QueryHighQualityListForSlot", "==發送(" + r.HighQualityStock.Count().ToString() + "筆)==\r\n" + jsonText); WebClient client = new WebClient(); client.Encoding = Encoding.UTF8; client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); client.Headers.Add("PowerAdmin", Setting.AppSettings("PowerAdmin")); var response = client.UploadData(Common.Tools.Setting.AppSettings("ReceiveByHighQualityList"), "POST", Encoding.UTF8.GetBytes(jsonText)); string resResult = Encoding.UTF8.GetString(response); LogHelper.doLog("StableStockServices_QueryHighQualityListForSlot", "==接收==\r\n" + resResult); } LogHelper.doLog("StableStockServices_QueryHighQualityListForSlot", JsonConvert.SerializeObject(HighQualityList)); return(HighQualityList); }
public DeilyStockNotiflyServices() { int DaysDiff = -1; if (DateTime.Now.Hour >= 19) { DaysDiff = 0; } if (!String.IsNullOrEmpty(Setting.AppSettings("SpecifiedDate"))) { DaysDiff = Int32.Parse(Setting.AppSettings("SpecifiedDate")); } GetDate = DateTime.Now.AddDays(DaysDiff); CheckDoneDirPath = AppDomain.CurrentDomain.BaseDirectory + @"\CheckDone\DeilyStockNotiflyServices\"; CheckDoneFileName = GetDate.ToString("yyyyMMdd") + ".txt"; CheckDoneFullPath = CheckDoneDirPath + CheckDoneFileName; }
private void button1_Click(object sender, EventArgs e) { String DownloadDirPath = AppDomain.CurrentDomain.BaseDirectory + @"\DataSource\TWSEStockPriceEveryDay\"; String DownloadFileName = TokenGenerator.GetTimeStamp(3) + ".csv"; String DownloadFullPath = DownloadDirPath + DownloadFileName; if (!System.IO.Directory.Exists(DownloadDirPath)) { System.IO.Directory.CreateDirectory(DownloadDirPath); } for (int i = 1095; i > 0; i--) { String YYYYMMDD = DateTime.Now.AddDays((0 - i)).ToString("yyyyMMdd"); DownloadDirPath = AppDomain.CurrentDomain.BaseDirectory + @"\DataSource\TWSEStockPriceEveryDay\"; DownloadFileName = YYYYMMDD + ".csv"; DownloadFullPath = DownloadDirPath + DownloadFileName; if (System.IO.File.Exists(DownloadFullPath)) { continue; } String DownloadUrl = Setting.AppSettings("TWSEStockPriceURL").Replace("@yyyyMMdd", YYYYMMDD); String DownloadData = ""; using (WebClient wClient = new WebClient()) DownloadData = wClient.DownloadString(DownloadUrl); //if (DownloadData.IndexOf(@"證券代號") < 0) //throw new Exception("錯誤的資料格式!"); //DownloadData = DownloadData.Substring(DownloadData.IndexOf(@"證券代號") - 1).Replace("=\"", "\""); System.IO.File.WriteAllText(DownloadFullPath, DownloadData); System.Threading.Thread.Sleep(3000); listBox1.Items.Add(YYYYMMDD); } }
public void DoNotifly() { string AdminUserId = Setting.AppSettings("LineAdminUserId"); string channelAccessToken = Setting.AppSettings("LineChannelAccessToken"); var bot = new Bot(channelAccessToken); try { if (CheckIsDone()) { LogHelper.doLog(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, "執行過了,do Nothing"); return; } List <HighQualityListModel> QueryQuality = StableStockServices.QueryQuality(); String StableTitle = $"==={GetDate.ToString("yyyy-MM-dd")}===\n保守型-到價提醒: \n "; String UnStableTitle = $"==={GetDate.ToString("yyyy-MM-dd")}===\n預估型-到價提醒: \n "; String StableContext = ""; String UnStableContext = ""; String LZUrl = "\nhttp://lazystock.azurewebsites.net"; QueryQuality.OrderBy(x => x.StockNum).ToList().ForEach(t => { if (t.StableIsBuy == "1") { StableContext += $"{t.StockNum}{t.StockName} \n "; } else if (t.UnStableIsBuy == "1") { UnStableContext += $"{t.StockNum}{t.StockName} \n "; } }); //List<String> users = new List<string>(); //string _userid = ""; foreach (String userid in Setting.AppSettings("LineNotiflyUserIds").Split(',')) { if (String.IsNullOrEmpty(userid)) { continue; } if (!String.IsNullOrEmpty(StableContext)) { bot.PushMessage(userid, StableTitle + StableContext + LZUrl); } if (!String.IsNullOrEmpty(UnStableContext)) { bot.PushMessage(userid, UnStableTitle + UnStableContext + LZUrl); } } if (!System.IO.Directory.Exists(CheckDoneDirPath)) { System.IO.Directory.CreateDirectory(CheckDoneDirPath); } System.IO.File.WriteAllText(this.CheckDoneFullPath, "done"); LogHelper.doLog(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, "發送成功!"); } catch (Exception e) { LogHelper.doLog(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, "[Exception]" + e.Message); try { bot.PushMessage(AdminUserId, $" {DateTime.Now.ToString()} ,群發發生錯誤"); } catch { } } }
public static void UploadData() { try { List <CalStockInfo> CalStockInfos = CalStockInfoRepo.GetAll().OrderBy(x => x.StockNum).ToList(); List <CalStockEPS_Divi> CalStockEPS_Divis = CalStockEPS_DiviRepo.GetAll().OrderBy(x => x.StockNum).ThenByDescending(n => n.Year).ToList(); //StockEntities _context = new StockEntities(); //List<CalStockInfo> CalStockInfos = _context.CalStockInfo.ToList<CalStockInfo>(); //List<CalStockEPS_Divi> CalStockEPS_Divis = _context.CalStockEPS_Divi.ToList<CalStockEPS_Divi>(); ReceiveByStockInfoReqModel StockInfos = new ReceiveByStockInfoReqModel(); StockInfos.StockInfos = new List <StockInfoResModel>(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <CalStockInfo, StockInfoResModel>().ForMember(x => x.EPS_Divi, opt => opt.Ignore()); }); IMapper iMapper = config.CreateMapper(); CalStockInfos.ForEach(t => { StockInfoResModel r = iMapper.Map <CalStockInfo, StockInfoResModel>(t); r.EPS_Divi = (from StockEPS_Divi in CalStockEPS_Divis where StockEPS_Divi.StockNum == t.StockNum select new EPS_DiviDataModel() { Year = StockEPS_Divi.Year, LastQ = StockEPS_Divi.LastQ, StockNum = StockEPS_Divi.StockNum, TotalEPS = StockEPS_Divi.TotalEPS, TotalDivi = StockEPS_Divi.TotalDivi, EachDiviFromEPS = StockEPS_Divi.EachDiviFromEPS }).ToList(); StockInfos.StockInfos.Add(r); }); for (int i = 0; i < StockInfos.StockInfos.Count; i = i + 2) { var items = StockInfos.StockInfos.Skip(i).Take(2); ReceiveByStockInfoReqModel r = new ReceiveByStockInfoReqModel(); r.StockInfos = items.ToList <StockInfoResModel>(); var jsonText = "{\"ReqParam\" : " + JsonConvert.SerializeObject(r) + @"}"; LogHelper.doLog("StockInfoServices", "==發送(" + r.StockInfos.Count().ToString() + "筆)==\r\n" + jsonText); WebClient client = new WebClient(); client.Encoding = Encoding.UTF8; client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); client.Headers.Add("PowerAdmin", Setting.AppSettings("PowerAdmin")); var response = client.UploadData(Common.Tools.Setting.AppSettings("ReceiveByStockInfoURL"), "POST", Encoding.UTF8.GetBytes(jsonText)); string resResult = Encoding.UTF8.GetString(response); LogHelper.doLog("StockInfoServices", "==接收==\r\n" + resResult); } } catch (Exception e) { LogHelper.doLog("StockInfoServices", "[Exception]" + e.Message); } }