Beispiel #1
0
        public async Task <UtilSchData> GetSellerFullSchForDate(string utilId, DateTime targetDt)
        {
            // https://stackoverflow.com/questions/32860666/httpclient-scrape-data-from-website-with-login-c-sharp
            int rev = await GetMaxRevForDate(targetDt);

            UtilSchData schData = new UtilSchData();

            if (rev == -1)
            {
                return(null);
            }
            string         url     = $"https://wbes.wrldc.in/ReportFullSchedule/GetFullInjSummary?scheduleDate={targetDt.ToString("dd-MM-yyyy")}&sellerId={utilId}&revisionNumber={rev}&regionId=2&byDetails=0&isDrawer=0&isBuyer=0";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36";
            request.Accept    = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
            request.KeepAlive = true;
            //SET AUTOMATIC DECOMPRESSION
            request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            using (WebResponse response = request.GetResponse())
            {
                using StreamReader sr = new StreamReader(response.GetResponseStream());
                string res = sr.ReadToEnd();
                string dataStartSearchStr = "var data = JSON.parse(";
                string dataEndSearchStr   = "]]";
                int    dataStartInd       = res.IndexOf("var data = JSON.parse(") + dataStartSearchStr.Length;
                int    dataEndInd         = res.IndexOf(dataEndSearchStr, dataStartInd) - 1;
                // get the data string in the format [[...],[...],[...]]
                string dataStr = res.Substring(dataStartInd, dataEndInd - dataStartInd + 1);
                dataStr = dataStr.Replace("\\\"", "");
                // remove the first and last characters to get string as [],[],[],[]
                dataStr = dataStr.Substring(1, dataStr.Length - 2);
                // get row strings in the form "","","",""
                List <string> dataRows = dataStr.Split("],").Select(s => s[1..]).Skip(1).Take(96).ToList();
Beispiel #2
0
        public async Task GetDownMarginsForDateTestAsync()
        {
            WbesLiveDataService service = new WbesLiveDataService(_config);
            UtilSchData         schData = await service.GetDownMarginsForDate("6477e23c-660e-4587-92d2-8e3488bc8262", DateTime.Now);

            Assert.IsTrue(schData != null);
            Assert.IsTrue(schData.SchVals.Count == 96);
        }
Beispiel #3
0
        public void GetOnbarInstalledCapacityForDatesTest()
        {
            WbesLiveDataService service = new WbesLiveDataService(_config);
            UtilSchData         schData = service.GetOnbarInstalledCapacityForDates("6477e23c-660e-4587-92d2-8e3488bc8262", DateTime.Now, DateTime.Now);

            Assert.IsTrue(schData != null);
            Assert.IsTrue(schData.SchVals.Count == 96);
        }
Beispiel #4
0
        public async Task GetDownMarginsForDatesTestAsync()
        {
            WbesLiveDataService service = new WbesLiveDataService(_config);
            int         numDays         = 3;
            UtilSchData schData         = await service.GetDownMarginsForDates("6477e23c-660e-4587-92d2-8e3488bc8262", DateTime.Now.AddDays(-1 * (numDays - 1)), DateTime.Now);

            Assert.IsTrue(schData != null);
            Assert.IsTrue(schData.SchVals.Count == 96 * numDays);
        }