Esempio n. 1
0
        public override List<StopTime> GetStopTimes(string stopID)
        {
            System.Net.WebClient client = new System.Net.WebClient();
            var jsonResult = client.DownloadString("http://api.onebusaway.org/api/where/arrivals-and-departures-for-stop/" + stopID + ".json?key=" + APIKey + "&version=2");

            List<StopTime> result = new List<StopTime>();

            var response = Json.Decode(jsonResult).data;

            foreach (var r in response.entry.arrivalsAndDepartures)
            {
                StopTime t = new StopTime();
                t.RouteShortName = r.routeShortName;
                t.RouteLongName = r.routeLongName;
                if (r.predicted.ToString().ToLower() == "true")
                {
                    t.ArrivalTime = Utilities.ConvertFromUnixTime(Convert.ToInt32(this.TransitAgency.TimeZone), r.predictedArrivalTime.ToString()).TimeOfDay;
                    t.DepartureTime = Utilities.ConvertFromUnixTime(Convert.ToInt32(this.TransitAgency.TimeZone), r.predictedDepartureTime.ToString()).TimeOfDay;
                    t.Type = "realtime";
                }
                else
                {
                    t.ArrivalTime = Utilities.ConvertFromUnixTime(Convert.ToInt32(this.TransitAgency.TimeZone), r.scheduledArrivalTime.ToString()).TimeOfDay;
                    t.DepartureTime = Utilities.ConvertFromUnixTime(Convert.ToInt32(this.TransitAgency.TimeZone), r.scheduledDepartureTime.ToString()).TimeOfDay;
                    t.Type = "scheduled";
                }

                if ((from x in result where x.RouteShortName == t.RouteShortName select x).Count() < 2)
                    result.Add(t);
            }

            return result;
        }
Esempio n. 2
0
        public override List<StopTime> GetStopTimes(string stopID)
        {
            System.Net.WebClient client = new System.Net.WebClient();

            DataSet ds = new DataSet();
            ds.ReadXml(client.OpenRead("http://www.ctabustracker.com/bustime/api/v1/getpredictions?key=" + APIKey + "&stpid=" + stopID));

            List<StopTime> result = new List<StopTime>();

            if (ds.Tables["prd"] == null)
            {
                return result;
            }

            foreach (DataRow r in ds.Tables["prd"].Rows)
            {
                StopTime t = new StopTime();
                t.RouteShortName = r["rt"].ToString();
                t.RouteLongName = r["rt"].ToString();
                t.ArrivalTime = DateTime.ParseExact(r["prdtm"].ToString(), "yyyyMMdd HH:mm", new System.Globalization.CultureInfo("en-US")).ToString("hh:mm tt");
                t.DepartureTime = t.ArrivalTime;
                t.Type = "realtime";

                if ((from x in result where x.RouteShortName == t.RouteShortName select x).Count() < 2)
                    result.Add(t);
            }

            return result;
        }
Esempio n. 3
0
        public override List<StopTime> GetStopTimes(string stopid)
        {
            System.Net.WebClient client = new System.Net.WebClient();

            GTFS engine = new GTFS(this.TransitAgency);
            Stop stop = engine.GetStop(stopid);

            DataSet ds = new DataSet();
            ds.ReadXml(client.OpenRead("http://myride.gocitybus.com/widget/Default1.aspx?pt=30&code=" + stop.Code));

            List<StopTime> result = new List<StopTime>();

            if (ds.Tables["Bus"] == null)
            {
                return result;
            }

            foreach (DataRow r in ds.Tables["Bus"].Rows)
            {
                StopTime t = new StopTime();

                t.RouteShortName = r["RouteName"].ToString().Substring(0, r["RouteName"].ToString().IndexOf(" ")).ToUpper().Trim(); if (t.RouteShortName.Length > 3) t.RouteShortName = t.RouteShortName.Substring(0, 3);
                t.RouteLongName = r["RouteName"].ToString().Replace(t.RouteShortName, "").Trim();

                var now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, this.TransitAgency.FriendlyTimeZone);

                if (r["TimeTillArrival"].ToString() == "DUE")
                    t.ArrivalTime = now.ToString("hh:mm tt");
                else
                    t.ArrivalTime = now.AddMinutes(Convert.ToInt32(r["TimeTillArrival"].ToString().Replace("min", "").Trim())).ToString("hh:mm tt");

                t.DepartureTime = t.ArrivalTime;
                t.Type = "realtime";

                result.Add(t);
            }

            return result;
        }
Esempio n. 4
0
        public override List<StopTime> GetStopTimes(string stopID)
        {
            System.Net.WebClient client = new System.Net.WebClient();

            DataSet ds = new DataSet();
            ds.ReadXml(client.OpenRead("http://api.bart.gov/api/etd.aspx?cmd=etd&key=" + APIKey + "&orig=" + stopID));

            List<StopTime> result = new List<StopTime>();

            foreach (DataRow r in ds.Tables["etd"].Rows)
            {
                foreach (DataRow s in ds.Tables["estimate"].Rows)
                {
                    if (s["etd_Id"].ToString() == r["etd_Id"].ToString())
                    {
                        StopTime t = new StopTime();

                        t.RouteShortName = r["abbreviation"].ToString();
                        t.RouteLongName = r["destination"].ToString();

                        var now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, this.TransitAgency.FriendlyTimeZone);

                        if (s["minutes"].ToString() == "Arrived")
                            t.ArrivalTime = now.ToString("hh:mm tt");
                        else
                            t.ArrivalTime = now.AddMinutes(Convert.ToInt32(s["minutes"].ToString().Trim())).ToString("hh:mm tt");

                        t.DepartureTime = t.ArrivalTime;
                        t.Type = "realtime";

                        if ((from x in result where x.RouteShortName == t.RouteShortName select x).Count() < 2)
                            result.Add(t);
                    }
                }
            }

            return result;
        }
Esempio n. 5
0
        public override List<StopTime> GetStopTimes(string stopID)
        {
            System.Net.WebClient client = new System.Net.WebClient();
            var jsonResult = client.DownloadString("http://api.routeshout.com/v1/rs.stops.getTimes?key=" + APIKey + "&agency=" + this.TransitAgency.AgencyID + "&stop=" + stopID);

            List<StopTime> result = new List<StopTime>();

            foreach (var r in Json.Decode(jsonResult).response)
            {
                StopTime t = new StopTime();
                t.RouteShortName = r.route_short_name;
                t.RouteLongName = r.route_kong_name;
                t.ArrivalTime = Convert.ToDateTime(r.arrival_time.ToString()).TimeOfDay;
                t.DepartureTime = Convert.ToDateTime(r.departure_time.ToString()).TimeOfDay;
                t.Type = Convert.ToInt32(r.type);

                if ((from x in result where x.RouteShortName == t.RouteShortName select x).Count() < 2)
                    result.Add(t);
            }

            return result;
        }
Esempio n. 6
0
        public override List<StopTime> GetStopTimes(string stopID)
        {
            System.Net.WebClient client = new System.Net.WebClient();
            var jsonResult = client.DownloadString("http://api.wmata.com/StationPrediction.svc/json/GetPrediction/" + stopID + "?api_key=" + APIKey);

            List<StopTime> result = new List<StopTime>();

            var data = Json.Decode(jsonResult);

            if (data != null)
            {
                foreach (var r in data.Trains)
                {
                    if (r.Min != "")
                    {
                        StopTime t = new StopTime();

                        t.RouteShortName = r.Line;
                        t.RouteLongName = r.Line;

                        var utc = new DateTimeOffset(DateTime.UtcNow, TimeSpan.Zero);
                        var now = utc.ToOffset(this.TransitAgency.FriendlyTimeZone.GetUtcOffset(utc));

                        if (r.Min.ToString() == "ARR" ||
                            r.Min.ToString() == "BRD")
                            t.ArrivalTime = now.DateTime.ToString("hh:mm tt");
                        else
                            t.ArrivalTime = now.AddMinutes(Convert.ToInt32(r.Min.ToString())).DateTime.ToString("hh:mm tt");

                        t.DepartureTime = t.ArrivalTime;
                        t.Type = "realtime";

                        if ((from x in result where x.RouteShortName == t.RouteShortName select x).Count() < 2)
                            result.Add(t);
                    }
                }
            }

            jsonResult = client.DownloadString("http://api.wmata.com/Bus.svc/json/JStopSchedule?stopId=" + stopID + "&api_key=" + APIKey);

            data = Json.Decode(jsonResult);

            if (data != null)
            {
                foreach (var r in data.ScheduleArrivals)
                {
                    StopTime t = new StopTime();
                    t.RouteShortName = r.RouteID;
                    t.RouteLongName = r.RouteID;
                    t.ArrivalTime = DateTime.ParseExact(r.ScheduleTime.ToString(), "s", new System.Globalization.CultureInfo("en-US")).TimeOfDay;
                    t.DepartureTime = t.ArrivalTime;
                    t.Type = "scheduled";

                    if ((from x in result where x.RouteShortName == t.RouteShortName select x).Count() < 2)
                        result.Add(t);
                }
            }

            return result;
        }
Esempio n. 7
0
        public override List<StopTime> GetStopTimes(string stopid)
        {
            List<StopTime> result = new List<StopTime>();

            var now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, this.TransitAgency.FriendlyTimeZone);

            var tod0 = now;
            var tod1 = now.AddHours(2);

            var stopTimes = db.GetStopTimes(tod0, tod1, agency.PartitionKey, stopid);

            foreach (var r in stopTimes)
            {
                StopTime t = new StopTime();
                t.RouteShortName = r.ShortName;
                t.RouteLongName = r.LongName;
                t.ArrivalTime = r.ArrivalTime.ToString("hh:mm tt");
                t.DepartureTime = r.DepartureTime.ToString("hh:mm tt");
                t.Type = "scheduled";

                result.Add(t);
            }

            return result;
        }