Пример #1
0
        private void GetAvailableSlots(CovidVaccinationCenters covidVaccinationCenters)
        {
            string captcha = "";

            foreach (var cvc in covidVaccinationCenters.Centers)
            {
                foreach (var session in cvc?.Sessions)
                {
                    if (IsFiltrationCriteraSatisfied(cvc, session))
                    {
                        DisplaySlotInfo(cvc, session);

                        foreach (var slot in session.Slots)
                        {
                            Console.ResetColor();
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine($"Trying to Book Appointment for CVC: {cvc.Name} - PIN: {cvc.Pincode} - District: {cvc.DistrictName} - Date: {session.Date} - Slot: {slot}");
                            Console.ResetColor();

                            captcha = new Captcha(_configuration).GetCurrentCaptchaDetails();

                            IS_BOOKING_SUCCESSFUL = BookAvailableSlot(session.SessionId, slot, captcha);

                            if (IS_BOOKING_SUCCESSFUL == true)
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }
        private void GetAvailableSlots(CovidVaccinationCenters covidVaccinationCenters)
        {
            string captcha = "";

            foreach (var cvc in covidVaccinationCenters.Centers)
            {
                foreach (var session in cvc?.Sessions)
                {
                    if (session.MinAgeLimit >= Convert.ToInt16(_configuration["CoWinAPI:MinAgeLimit"]) &&
                        session.MinAgeLimit < Convert.ToInt16(_configuration["CoWinAPI:MaxAgeLimit"]) &&
                        session.AvailableCapacity >= Convert.ToInt16(_configuration["CoWinAPI:MinimumVaccineAvailability"]) &&
                        session.Vaccine == _configuration["CoWinAPI:VaccineType"] &&
                        cvc.FeeType == _configuration["CoWinAPI:VaccineFeeType"])
                    {
                        DisplaySlotInfo(cvc, session);

                        foreach (var slot in session.Slots)
                        {
                            Console.ResetColor();
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine($"Trying to Book Appointment for CVC: {cvc.Name} - PIN: {cvc.Pincode} - District: {cvc.DistrictName} - Date: {session.Date} - Slot: {slot}");
                            Console.ResetColor();

                            captcha = new Captcha(_configuration).GetCurrentCaptchaDetails();

                            var isBookingSuccessful = BookAvailableSlot(session.SessionId, slot, captcha);

                            if (isBookingSuccessful == true)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
        private void GetAvailableSlots(CovidVaccinationCenters covidVaccinationCenters)
        {
            string captcha = "";

            foreach (var cvc in covidVaccinationCenters.Centers)
            {
                foreach (var session in cvc.Sessions)
                {
                    if (IsFiltrationCriteriaSatisfied(cvc, session))
                    {
                        if (session.Slots.Count > 0)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine($"[INFO] HURRAY! Slots Available for search criteria: Age {_configuration["CoWinAPI:MinAgeLimit"]}-{_configuration["CoWinAPI:MaxAgeLimit"]} - PIN: {cvc.Pincode} - District: {cvc.DistrictName} - Date: {session.Date} - Center : {cvc.Name}");
                            Console.ResetColor();
                            DisplaySlotInfo(cvc, session);
                        }

                        // Processing of Slot Booking in Reverse Order so that chances are higher to get the slot
                        for (int i = session.Slots.Count - 1; i >= 0; i--)
                        {
                            var stopwatch = new Stopwatch();
                            stopwatch.Start();

                            Console.ResetColor();
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine($"[INFO] Trying to Book Appointment for CVC: {cvc.Name} - PIN: {cvc.Pincode} - District: {cvc.DistrictName} - Date: {session.Date} - Slot: {session.Slots[i]}");
                            Console.ResetColor();

                            captcha = new Captcha(_configuration).GetCurrentCaptchaDetails();

                            IS_BOOKING_SUCCESSFUL = BookAvailableSlot(session.SessionId, session.Slots[i], captcha);

                            if (IS_BOOKING_SUCCESSFUL == true)
                            {
                                stopwatch.Stop();
                                TimeSpan ts          = stopwatch.Elapsed;
                                var      captchaMode = Convert.ToBoolean(_configuration["CoWinAPI:Auth:AutoReadCaptcha"]) == true ? "AI AutoCaptcha" : "Manual Captcha";
                                new Notifier().Notify($"*SLOT BOOKED SUCCESSFULLY +1* \n\n" +
                                                      $"*LocalAppVersion* : `{ new VersionChecker(_configuration).GetCurrentVersionFromSystem()}`\n" +
                                                      $"*BookedOn* : `{ DateTime.Now}`\n" +
                                                      $"*TimeTakenToBook* : `{ts.TotalSeconds} seconds`\n" +
                                                      $"*CaptchaMode* : `{captchaMode}`\n" +
                                                      $"*Latitude* : `{ cvc.Lat}`\n" +
                                                      $"*Longitude* : `{ cvc.Long}`\n" +
                                                      $"*PINCode* : `{cvc.Pincode}`\n" +
                                                      $"*District* : `{ cvc.DistrictName}`\n" +
                                                      $"*State* : `{ cvc.StateName}`\n" +
                                                      $"*BeneficiaryCount* : `{ beneficiaries.Count}`\n" +
                                                      $"*AgeGroup* : `{_configuration["CoWinAPI:MinAgeLimit"]} - {_configuration["CoWinAPI:MaxAgeLimit"]}`\n");
                                return;
                            }
                            stopwatch.Stop();
                        }
                    }
                    else
                    {
                        Console.WriteLine($"[INFO] Sorry! No Slots Available for search criteria: Age {_configuration["CoWinAPI:MinAgeLimit"]}-{_configuration["CoWinAPI:MaxAgeLimit"]} - PIN: {cvc.Pincode} - District: {cvc.DistrictName} - Date: {session.Date} - Center : {cvc.Name}");
                        Console.ResetColor();
                    }
                }
            }
        }
        private void GetAvailableSlots(CovidVaccinationCenters covidVaccinationCenters)
        {
            List <Center> vaccinationCentres = covidVaccinationCenters.Centers;

            if (_vaccinationCentresToSearch.Count != 0 && Convert.ToBoolean(_configuration["CoWinAPI:IsSearchToBeDoneForVaccinationCentreName"]) == true)
            {
                vaccinationCentres = covidVaccinationCenters.Centers.Where(x => _vaccinationCentresToSearch.Any(centrename => centrename == x.Name.ToUpper().Trim())).ToList();
            }

            if (vaccinationCentres.Count == 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine($"[WARNING] Sorry! No Vaccination Centers available for your search criteria");
                Console.ResetColor();
                return;
            }

            foreach (var cvc in vaccinationCentres)
            {
                foreach (var session in cvc.Sessions)
                {
                    if (IsFiltrationCriteriaSatisfied(cvc, session))
                    {
                        if (session.Slots.Count > 0)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine($"[INFO] HURRAY! Slots Available for search criteria: Age {_configuration["CoWinAPI:MinAgeLimit"]}-{_configuration["CoWinAPI:MaxAgeLimit"]} - PIN: {cvc.Pincode} - District: {cvc.DistrictName} - Date: {session.Date} - Center : {cvc.Name}");
                            Console.ResetColor();
                            DisplaySlotInfo(cvc, session);
                        }

                        // Processing of Slot Booking in Reverse Order so that chances are higher to get the slot
                        for (int i = session.Slots.Count - 1; i >= 0; i--)
                        {
                            var stopwatch = new Stopwatch();
                            stopwatch.Start();

                            Console.ResetColor();
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine($"[INFO] Trying to Book Appointment for CVC: {cvc.Name} - PIN: {cvc.Pincode} - District: {cvc.DistrictName} - Date: {session.Date} - Slot: {session.Slots[i]}");
                            Console.ResetColor();

                            string captcha = new Captcha(_configuration).GetCurrentCaptchaDetails();
                            IS_BOOKING_SUCCESSFUL = BookAvailableSlot(session.SessionId, session.Slots[i], captcha);

                            if (IS_BOOKING_SUCCESSFUL == true)
                            {
                                stopwatch.Stop();
                                TimeSpan ts              = stopwatch.Elapsed;
                                var      captchaMode     = Convert.ToBoolean(_configuration["CoWinAPI:Auth:AutoReadCaptcha"]) == true ? "AI AutoCaptcha" : "Manual Captcha";
                                var      bookDate        = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
                                var      appVersion      = new VersionChecker(_configuration).GetCurrentVersionFromSystem();
                                var      uniqueId        = Guid.NewGuid();
                                var      timeTakenToBook = ts.TotalSeconds;
                                var      source          = System.Runtime.InteropServices.OSPlatform.Windows.ToString();

                                var telemetryModel = new TelemetryModel
                                {
                                    UniqueId   = uniqueId,
                                    AppVersion = appVersion.ToString().Trim(),
                                    Source     = source.Trim(),
                                    BookedOn   = DateTime.ParseExact(bookDate, "dd-MM-yyyy HH:mm:ss", new CultureInfo("en-US")),
                                    TimeTakenToBookInSeconds = timeTakenToBook,
                                    CaptchaMode      = captchaMode.Trim(),
                                    Latitude         = Convert.ToInt32(cvc.Lat),
                                    Longitude        = Convert.ToInt32(cvc.Long),
                                    PINCode          = Convert.ToInt32(cvc.Pincode),
                                    District         = cvc.DistrictName.Trim(),
                                    State            = cvc.StateName.Trim(),
                                    BeneficiaryCount = beneficiaries.Count,
                                    MinimumAge       = Convert.ToInt32(_configuration["CoWinAPI:MinAgeLimit"]),
                                    MaximumAge       = Convert.ToInt32(_configuration["CoWinAPI:MaxAgeLimit"]),
                                };

                                var telemetryMetadata = JsonConvert.SerializeObject(telemetryModel);

                                new Telemetry(_configuration).SendStatistics(telemetryMetadata);

                                new Notifier().Notify($"*SLOT BOOKED SUCCESSFULLY +1* \n\n" +
                                                      $"*LocalAppVersion* : `{ appVersion }`\n" +
                                                      $"*BookedOn* : `{ bookDate }`\n" +
                                                      $"*TimeTakenToBook* : `{ timeTakenToBook } seconds`\n" +
                                                      $"*CaptchaMode* : `{captchaMode}`\n" +
                                                      $"*Latitude* : `{ cvc.Lat}`\n" +
                                                      $"*Longitude* : `{ cvc.Long}`\n" +
                                                      $"*PINCode* : `{cvc.Pincode}`\n" +
                                                      $"*District* : `{ cvc.DistrictName}`\n" +
                                                      $"*State* : `{ cvc.StateName}`\n" +
                                                      $"*BeneficiaryCount* : `{ beneficiaries.Count}`\n" +
                                                      $"*AgeGroup* : `{_configuration["CoWinAPI:MinAgeLimit"]} - {_configuration["CoWinAPI:MaxAgeLimit"]}`\n" +
                                                      $"*Source* : `{ source }`\n" +
                                                      $"*UniqueId* : `{ uniqueId }`\n");
                                return;
                            }
                            stopwatch.Stop();
                        }
                    }
                    else
                    {
                        Console.WriteLine($"[INFO] Sorry! No Slots Available for search criteria: Age {_configuration["CoWinAPI:MinAgeLimit"]}-{_configuration["CoWinAPI:MaxAgeLimit"]} - PIN: {cvc.Pincode} - District: {cvc.DistrictName} - Date: {session.Date} - Center : {cvc.Name}");
                        Console.ResetColor();
                    }
                }
            }
        }
        private void GetAvailableSlots(CovidVaccinationCenters covidVaccinationCenters)
        {
            List <Session> vaccinationCentres = covidVaccinationCenters.Sessions;

            if (_vaccinationCentresToSearch.Count != 0 && Convert.ToBoolean(_configuration["CoWinAPI:IsSearchToBeDoneForVaccinationCentreName"]) == true)
            {
                vaccinationCentres = covidVaccinationCenters.Sessions.Where(x => _vaccinationCentresToSearch.Any(centrename => centrename == x.Name.ToUpper().Trim())).ToList();
            }

            if (vaccinationCentres?.Count == 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine($"[WARNING] Sorry! No Vaccination Centers available for your search criteria");
                Console.ResetColor();
                return;
            }

            var filteredVaccinationCentres = FilterVaccinationCentres(vaccinationCentres);

            var sortedVaccinationCentres = SortVaccinationCentres(filteredVaccinationCentres);

            foreach (var session in sortedVaccinationCentres)
            {
                if (session.Slots.Count > 0)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine($"[INFO] HURRAY! Slots Available for search criteria: Age {_configuration["CoWinAPI:MinAgeLimit"]}-{_configuration["CoWinAPI:MaxAgeLimit"]} - PIN: {session.Pincode} - District: {session.DistrictName} - Date: {session.Date} - Center : {session.Name}");
                    Console.ResetColor();
                    DisplaySlotInfo(session);

                    // Processing of Slot Booking in Reverse Order so that chances are higher to get the slot
                    if (_configuration["CoWinAPI:SlotPreference"].ToUpper().Trim() == PreferredSlot.LastSlot)
                    {
                        session.Slots.Reverse();
                    }
                    else if (_configuration["CoWinAPI:SlotPreference"].ToUpper().Trim() == PreferredSlot.RandomSlot)
                    {
                        session.Slots = session.Slots.OrderBy(x => Guid.NewGuid()).ToList();
                    }

                    foreach (var slot in session.Slots)
                    {
                        var stopwatch = new Stopwatch();
                        stopwatch.Start();

                        Console.ResetColor();
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine($"[INFO] Trying to Book Appointment for session: {session.Name} - PIN: {session.Pincode} - District: {session.DistrictName} - Date: {session.Date} - Slot: {slot}");
                        Console.ResetColor();

                        IS_BOOKING_SUCCESSFUL = BookAvailableSlot(session.SessionId, slot);
                        if (IS_BOOKING_SUCCESSFUL == true)
                        {
                            stopwatch.Stop();
                            SendNotification(session, stopwatch);
                            DownloadAppointmentSlip();
                            return;
                        }
                        stopwatch.Stop();
                    }
                }
                else
                {
                    Console.WriteLine($"[INFO] Sorry! No Slots Available for search criteria: Age {_configuration["CoWinAPI:MinAgeLimit"]}-{_configuration["CoWinAPI:MaxAgeLimit"]} - PIN: {session.Pincode} - District: {session.DistrictName} - Date: {session.Date} - Center : {session.Name}");
                    Console.ResetColor();
                }
            }
        }