Beispiel #1
0
        private static TGSessionsCalendarEntity MapToTGEntity(IEnumerable <Center> sessions18)
        {
            TGSessionsCalendarEntity msgDTO = new TGSessionsCalendarEntity();

            msgDTO.centers = new List <TGCenter>();
            foreach (var tgc in sessions18)
            {
                var tGSessions = new List <TGSession>();
                foreach (var ss in tgc.sessions)
                {
                    TGSession tGSession = new TGSession
                    {
                        available_capacity = ss.available_capacity,
                        date    = ss.date,
                        vaccine = ss.vaccine,
                        available_capacity_dose1 = ss.available_capacity_dose1,
                        available_capacity_dose2 = ss.available_capacity_dose2
                    };
                    if (tGSession.available_capacity > 0)
                    {
                        tGSessions.Add(tGSession);
                    }
                }
                TGCenter tGCenter = new TGCenter
                {
                    fee_type = tgc.fee_type,
                    name     = tgc.name
                };
                tGCenter.sessions = tGSessions;
                msgDTO.centers.Add(tGCenter);
            }

            return(msgDTO);
        }
Beispiel #2
0
        private static async Task SendSlotsMsgForPincodeAsync(int age, string dateString, string pin, ILogger log)
        {
            string url     = string.Format(GetEnvironmentVariable("cowinURL"), pin, dateString);
            bool   isDose1 = bool.Parse(GetEnvironmentVariable("isDose1"));

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            string responseString = string.Empty;

            try
            {
                using HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                using Stream stream            = response.GetResponseStream();
                using StreamReader reader      = new StreamReader(stream);
                responseString = await reader.ReadToEndAsync().ConfigureAwait(false);
            }
            catch (Exception e)
            {
                log.LogWarning(e.Message);
                return;
            }

            SessionsCalendarEntity sessionsEntity = JsonConvert.DeserializeObject <SessionsCalendarEntity>(responseString);
            var sessionList = sessionsEntity.centers;
            var sessions18  = sessionsEntity.centers.Where(x => x.sessions.Any(y => y.min_age_limit == age && ((isDose1 && y.available_capacity_dose1 > 0) || (!isDose1 && y.available_capacity_dose2 > 0)))).ToList();

            if (sessions18.Count() > 0)
            {
                TGSessionsCalendarEntity msgDTO        = MapToTGEntity(sessions18);
                StringBuilder            stringBuilder = new StringBuilder();
                for (int i = 0; i < msgDTO.centers.Count(); i++)
                {
                    foreach (var session in msgDTO.centers[i].sessions)
                    {
                        stringBuilder.AppendLine(msgDTO.centers[i].name);
                        stringBuilder.AppendLine(session.vaccine);
                        stringBuilder.AppendLine($"Total {session.available_capacity} slots on {session.date}");
                        stringBuilder.AppendLine($"(Dose 1: {session.available_capacity_dose1}, Dose2: {session.available_capacity_dose2})");
                        stringBuilder.AppendLine();
                    }
                }

                await SentTelegramMessageAsync(stringBuilder.ToString()).ConfigureAwait(false);
                await UploadStateToBlob().ConfigureAwait(false);
            }
        }