Exemple #1
0
        public static TimeTable ArrivalTimes(string category, string token, string root_url)
        {
            TimeTable model = ReadCSV(category, root_url);

            model.EMTToken = token;
            model.Category = category;

            EMTClient   emt = new EMTClient();   // buses
            AEMETClient met = new AEMETClient(); // weather

            model.Stops.SafeForEach(stop => {
                string[] lines       = model.LinesByStop(stop);
                List <BusLine> times = emt.TimeArrivalBus(stop, lines, model.EMTToken);
                model.UpdateTimes(times);
            });

            model.Temp = met.ReadTemp().ToString();

            return(model);
        }
Exemple #2
0
        public static TimeTable ReadCSV(string cat, string root_url)
        {
            TimeTable ret = new TimeTable();

            ret.Category = cat.Safe();

            WebClient client = new WebClient();

            string url = $"{root_url}/csv/buses.csv";
            //string url = "http://busmon.westeurope.cloudapp.azure.com/csv/buses.csv";

            Stream       stream  = client.OpenRead(url);
            StreamReader reader  = new StreamReader(stream);
            String       content = reader.ReadToEnd();

            ret.Lines = new List <BusLine>();
            content.SafeSplit(Environment.NewLine).SafeForEach((line, idx) => {
                // # es comentario
                if (!line.TrimStart().StartsWith("#"))
                {
                    string category = line.SafeSplit("|").SafeIndexer(0);
                    if (category.SameText(cat))
                    {
                        BusLine bl = new BusLine()
                        {
                            Stop = line.SafeSplit("|").SafeIndexer(1),
                            Line = line.SafeSplit("|").SafeIndexer(2),
                            Desc = line.SafeSplit("|").SafeIndexer(3).RemoveDiacritics()
                        };

                        ret.Lines.Add(bl);
                    }
                }
            });

            //var fileContents = System.IO.File.ReadAllText( .MapPath(@"~/csv/buses.csv"));

            return(ret);
        }