public void runOnce(object inputVo) { try { Thread cur_thread = Thread.CurrentThread; int i = cur_thread.ManagedThreadId; Debug.WriteLine("start : {0}", i); InputVo inputData = (InputVo)inputVo; searchVo.kreamUrl = inputData.kreamUrl; searchVo.stockXUrl = inputData.stockXUrl; searchVo.threadNo = inputData.no; MstInfo mstInfo = processingDataService.comparingData(searchVo); searchVo.mstInfo = mstInfo; _httpClient = new HttpClient(); //string url = "https://discordapp.com/api/webhooks/797639331011231744/GN1RSE99hoWUw4ga9PdJi2XuQp9ZvNyi-jajXfQtKdA5e7G1lxIvDFfIyEZQQV85E3kD"; string url = "https://discord.com/api/webhooks/797639847309213706/nTgGce1csWdzq4kH912JMD5T99KJVNfqKik8zJ48qPPd924ThOOPGj65ZH1FWbE_V4RT"; searchVo.webHookUrl = url; Webhook webhook = processingDataService.makeMstContent(searchVo); webhook.Username = "******"; var content = new StringContent(JsonConvert.SerializeObject(webhook), Encoding.UTF8, "application/json"); var response = _httpClient.PostAsync(url, content).Result; searchVo.mstInfo = null; } catch (Exception e) { Debug.WriteLine("error!!!"); this.state = "error"; this.Dispose(); } }
private void exec(object sender, EventArgs e) { // [Thread start] //getting rawData => processingData => MstInfo //form2(input) SearchVo searchVo = new SearchVo(); //form3(exec): 상세 MstInfo mstInfo = processingDataService.comparingData(searchVo); searchVo.mstInfo = mstInfo; //webhook start //SearchVo searchVo = new SearchVo(); _httpClient = new HttpClient(); string url = "https://discordapp.com/api/webhooks/797639331011231744/GN1RSE99hoWUw4ga9PdJi2XuQp9ZvNyi-jajXfQtKdA5e7G1lxIvDFfIyEZQQV85E3kD"; searchVo.webHookUrl = url; Webhook webhook = processingDataService.makeMstContent(searchVo); webhook.Username = "******"; var content = new StringContent(JsonConvert.SerializeObject(webhook), Encoding.UTF8, "application/json"); var response = _httpClient.PostAsync(url, content).Result; string test = ""; /* * //sending to discord START * WebClient dwebClient = new WebClient(); * //string url = "https://discordapp.com/api/webhooks/797639331011231744/GN1RSE99hoWUw4ga9PdJi2XuQp9ZvNyi-jajXfQtKdA5e7G1lxIvDFfIyEZQQV85E3kD"; * NameValueCollection discordValues = new NameValueCollection(); * * Webhook web = processingDataService.makeMstContent(searchVo); * * discordValues.Add("username", "yuhaFromC#"); * discordValues.Add("content", content); * * dwebClient.UploadValues(url,discordValues); * //sending to discord END */ //24시간 단위 //[Thread End] --특정 스레드 종료 버튼을 누른 경우 return; }
public void exectimerThread(object sender, ElapsedEventArgs e) { try { MstInfo mstInfo = processingDataService.comparingData(searchVo); searchVo.mstInfo = mstInfo; _httpClient = new HttpClient(); //string url = "https://discordapp.com/api/webhooks/797639331011231744/GN1RSE99hoWUw4ga9PdJi2XuQp9ZvNyi-jajXfQtKdA5e7G1lxIvDFfIyEZQQV85E3kD"; string url = "https://discord.com/api/webhooks/797639847309213706/nTgGce1csWdzq4kH912JMD5T99KJVNfqKik8zJ48qPPd924ThOOPGj65ZH1FWbE_V4RT"; searchVo.webHookUrl = url; Webhook webhook = processingDataService.makeMstContent(searchVo); webhook.Username = "******"; var content = new StringContent(JsonConvert.SerializeObject(webhook), Encoding.UTF8, "application/json"); var response = _httpClient.PostAsync(url, content).Result; searchVo.mstInfo = null; } catch (Exception ex) { Debug.WriteLine("error!!"); this.state = "error"; this.Dispose(); } }
/* * author : yuha * funcName : comparingData * summary : 가격비교 * input : searchVo * return : MstInfo */ public MstInfo comparingData(SearchVo searchVo) { Dictionary <string, string> usKrSizeMap = sizeConstantMap.getUsKrSizeMap(); float usdKrw = gettingInfoService.getUseKrw(); searchVo.usdkrw = usdKrw; MstInfo mstInfo = new MstInfo(); Debug.WriteLine("test0"); Dictionary <string, DetailInfo> stockXInfoMap = gettingInfoService.crawlingFromStockx(searchVo); Dictionary <string, DetailInfo> kreamInfoMap = gettingInfoService.crawlingFromkream(searchVo); Dictionary <string, DetailInfo> detailInfoMap = new Dictionary <string, DetailInfo>(); string sizeType = searchVo.sizeType.Replace(" ", ""); foreach (string key in stockXInfoMap.Keys) { DetailInfo detailInfo = new DetailInfo(); /*kreamX 최근 판매가 널인경우 추가 2021-02-18*/ if (kreamInfoMap.ContainsKey(key) && (int)kreamInfoMap[key].kreamLatestKrPrice == 0) { detailInfo.latestYn = "N"; } else { detailInfo.latestYn = "Y"; } /*kreamX 최근 판매가 널인경우 추가 끝 2021-02-18*/ int difference = 0; detailInfo.sizeLabel = "US " + key + sizeType + " , " + stockXInfoMap[key].krSize; // us 4, 220 detailInfo.stockXUsPriceLabel = "$" + stockXInfoMap[key].stockXUsPrice.ToString(); detailInfo.stockXLatestUsPriceLabel = "$" + stockXInfoMap[key].stockXLatestUsPrice.ToString(); detailInfo.stockXKrPriceLabel = "₩" + String.Format("{0:#,###}", (int)stockXInfoMap[key].stockXKrPrice); detailInfo.stockXLatestKrPriceLabel = "₩" + String.Format("{0:#,###}", (int)stockXInfoMap[key].stockXLatestKrPrice); difference = 0 - (int)stockXInfoMap[key].stockXKrPrice; int latestDifference = 0 - (int)stockXInfoMap[key].stockXLatestKrPrice; if (kreamInfoMap.ContainsKey(key)) { detailInfo.kreamKrPriceLabel = "₩" + String.Format("{0:#,###}", (int)kreamInfoMap[key].kreamKrPrice); detailInfo.kreamKrLatestPriceLabel = "₩" + String.Format("{0:#,###}", (int)kreamInfoMap[key].kreamLatestKrPrice); difference += (int)kreamInfoMap[key].kreamKrPrice; latestDifference += (int)kreamInfoMap[key].kreamLatestKrPrice; if (difference > 0) { detailInfo.differenceLabel = "₩" + String.Format("{0:#,###}", Math.Abs(difference)); detailInfo.roiLabel = ((int)(((difference / kreamInfoMap[key].kreamKrPrice)) * 100)).ToString() + "%"; detailInfo.latestRoiLabel = ((int)(((latestDifference / kreamInfoMap[key].kreamLatestKrPrice)) * 100)).ToString() + "%"; detailInfoMap.Add(key, detailInfo); } else { detailInfo.differenceLabel = "No Result"; detailInfo.roiLabel = "No Result"; } } else { detailInfo.kreamKrPriceLabel = "No Result"; difference = 0; detailInfo.differenceLabel = "No Result"; detailInfo.roiLabel = "No Result"; } detailInfo.difference = difference; //detailInfoMap.Add(key, detailInfo); } mstInfo.thumbnailUrl = searchVo.thumbnailUrl; mstInfo.detailInfoMap = detailInfoMap; mstInfo.prdNm = stockXInfoMap.First().Value.prdNm; gettingInfoService.quitDriver(); mstInfo.thumbnailUrl = searchVo.thumbnailUrl; return(mstInfo); }
/* * author : yuha * funcName : makeMstContent * summary : 웹훅 string content 생성 * input : SearchVo * return : string */ public Webhook makeMstContent(SearchVo searchVo) { Webhook webhook = new Webhook(searchVo.webHookUrl); MstInfo mstInfo = searchVo.mstInfo; Dictionary <string, DetailInfo> detailMap = mstInfo.detailInfoMap; List <Embed> embeds = new List <Embed>(); List <EmbedField> fileds = new List <EmbedField>(); Embed embed1 = new Embed(); EmbedThumbnail thumbnail = new EmbedThumbnail(); string title = "product name : [" + mstInfo.prdNm + "]\n"; string description = "stockX url : [stockX](" + searchVo.stockXUrl + ")\nkream url : [kream](" + searchVo.kreamUrl + ")"; string thumbnailUrl = mstInfo.thumbnailUrl; thumbnail.Url = thumbnailUrl; if (detailMap.Count > 0) { foreach (string key in detailMap.Keys) { EmbedField field = new EmbedField(); field.Name = detailMap[key].sizeLabel; if (detailMap[key].latestYn.Equals("N")) { /*kreamX 최근 판매가 널인경우 추가 2021-02-18*/ field.Value += detailMap[key].stockXUsPriceLabel + " | " + detailMap[key].stockXKrPriceLabel + " | " + detailMap[key].kreamKrPriceLabel + " | " + detailMap[key].differenceLabel + " | " + detailMap[key].roiLabel; } else { field.Value += detailMap[key].stockXUsPriceLabel + "(" + detailMap[key].stockXLatestUsPriceLabel + ")" + " | " + detailMap[key].stockXKrPriceLabel + "(" + detailMap[key].stockXLatestKrPriceLabel + ")" + " | " + detailMap[key].kreamKrPriceLabel + "(" + detailMap[key].kreamKrLatestPriceLabel + ")" + " | " + detailMap[key].differenceLabel + " | " + detailMap[key].roiLabel + "(" + detailMap[key].latestRoiLabel + ")"; } fileds.Add(field); } embed1.Fields = fileds; } else { description += "\n\n**No Mapped fields**"; } embed1.Title = title; embed1.Description = description; embed1.Thumbnail = thumbnail; embeds.Add(embed1); webhook.Embeds = embeds; /* * string content = ""; * * content = "product name : [" + mstInfo.prdNm + "]\n"; * Dictionary<string, DetailInfo> detailMap = mstInfo.detailInfoMap; * content += "[size] | [stockX_price] | [stockX_Krprice] | [kream_Krprice] | [difference_price] \n"; * foreach (string key in detailMap.Keys) * { * content += detailMap[key].sizeLabel + " | " + detailMap[key].stockXUsPriceLabel + " | " + detailMap[key].stockXKrPriceLabel + * " | " + detailMap[key].kreamKrPriceLabel + " | " + detailMap[key].differenceLabel + "\n"; * } */ return(webhook); }