コード例 #1
0
        private static async Task <TrackerResponse> CalendarByDistrict(string districtID)
        {
            // Create availableSessions List which will hold the results
            List <AvailableSession> availableSessions = new List <AvailableSession>();
            int availableCount     = 0;
            int availableLt45Count = 0;

            //Call the calendarByDistrict api
            var streamTask = Client.GetStreamAsync(
                "https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?" +
                "district_id=" + districtID +
                "&date=" + DateTime.Now.ToString("dd-MM-yyyy"));

            var availableCenters = await JsonSerializer.DeserializeAsync <CalendarByDistrictResponse>(await streamTask);

            foreach (var center in availableCenters.Centers)
            {
                foreach (var session in center.Sessions)
                {
                    if (session.Available_capacity != 0)
                    {
                        availableCount++;
                        if (session.Min_age_limit < 45)
                        {
                            availableLt45Count++;
                        }

                        availableSessions.Add(new AvailableSession
                        {
                            Name = center.Name,
                            Available_capacity = session.Available_capacity,
                            Min_age_limit      = session.Min_age_limit,
                        });
                    }
                }
            }

            TrackerResponse result = new TrackerResponse()
            {
                AvailableCount          = availableCount,
                AvailableCountCountLt45 = availableLt45Count,
                AvailableSessions       = availableSessions
            };

            return(result);
        }
コード例 #2
0
        private static async Task Main(string[] args)
        {
            if (args.Length == 1 && HelpRequired(args[0]))
            {
                DisplayHelp();
            }
            else
            {
                if (args.Length != 4)
                {
                    Console.WriteLine("Insufficient arguments...");
                    DisplayHelp();
                    Environment.Exit(0);
                }

                Console.WriteLine("Checking available slots...");

                Client.DefaultRequestHeaders.Accept.Clear();
                Client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                // District ID comes from the command line argument
                TrackerResponse trackerResponse = await CalendarByDistrict(args[0]);

                if (trackerResponse.AvailableCount != 0)
                {
                    string mailContent = $"Available slots: {trackerResponse.AvailableCount} | Available slots for Age < 45: {trackerResponse.AvailableCountCountLt45} <br> <br> {Environment.NewLine}";
                    foreach (AvailableSession session in trackerResponse.AvailableSessions)
                    {
                        mailContent += $"Name: {session.Name} | Available capacity: {session.Available_capacity} | Min age limit: {session.Min_age_limit} <br> {Environment.NewLine}";
                    }
                    Console.WriteLine(mailContent);

                    await NotifyUser(args[1], args[2], args[3], mailContent);
                }
                else
                {
                    Console.WriteLine("No available slots.");
                }
            }
        }