Exemple #1
0
        void FillStation(String s, BenzinStation station)
        {
            int offset = 0;
            var number = ParseHelper.GetSubstring(s, "Номер:", "<br/>", 0, out offset);
            station.Name = number;
            // сдвигаем начало поиска
            ParseHelper.GetSubstring(s, "<b>", "</b>", 0, out offset);
            var address = ParseHelper.GetSubstring(s, "<br/>", "<br/>", offset, out offset);
            station.Address = address.Replace("Адрес:", "").Trim();
            var fuel = ParseHelper.GetSubstring(s, "<br/>", "<br/>", offset, out offset);
            fuel = fuel.Replace("Сорт топлива:", "");
            if (fuel.Contains("Газ"))
                station.FuelType |= FuelType.LPG;
            if (fuel.Contains("80"))
                station.FuelType |= FuelType.A80;
            if (fuel.Contains("92"))
                station.FuelType |= FuelType.A92;
            if (fuel.Contains("95"))
                station.FuelType |= FuelType.A95;
            if (fuel.Contains("ДТ"))
                station.FuelType |= FuelType.Diesel;

            var services = ParseHelper.GetSubstring(s, "<br/>", "<br/>", offset, out offset);
            services = services.Replace("Услуги:", "");
            if (services.Contains("агазин"))
                station.ServiceType |= ServiceType.Shop;
            if (services.Contains("ойка"))
                station.ServiceType |= ServiceType.Wash;
            if (services.Contains("афе"))
                station.ServiceType |= ServiceType.Cafe;
        }
Exemple #2
0
        List<BenzinStation> ParseHtml(String html)
        {
            var result = new List<BenzinStation>();

            var s = ParseHelper.GetSubstring(html, "Map.Data.stations = ", ";");
            var jsonStations = JsonConvert.DeserializeObject<StationJson[]>(s);

            foreach (var json in jsonStations)
            {
                var st = new BenzinStation()
                {
                    Name = json.label,
                    Address = json.address,
                    Dolgota = json.longitude,
                    Shirota = json.latitude,
                    Url = json.id
                };

                if (json.fu_80)
                    st.FuelType |= FuelType.A80;
                if (json.fu_92)
                    st.FuelType |= FuelType.A92;
                if (json.fu_95)
                    st.FuelType |= FuelType.A95;
                if (json.fu_dt)
                    st.FuelType |= FuelType.Diesel;

                if (json.se_coffee)
                    st.ServiceType |= ServiceType.Cafe;

                result.Add(st);
            }

            return result;
        }
Exemple #3
0
        List<BenzinStation> ParseStations(String json)
        {
            var result = new List<BenzinStation>();
            var data = JsonConvert.DeserializeObject<Data>(json);
            foreach (var stJson in data.sites)
            {
                var station = new BenzinStation()
                {
                    Address = stJson.state + ", " + stJson.street,
                    Dolgota = stJson.lng,
                    Shirota = stJson.lat,
                    Name = stJson.name,
                    Url = stJson.id
                };
                
                foreach (var service in stJson.services)
                {
                    if (service.Contains("Car Wash"))
                        station.ServiceType |= ServiceType.Wash;
                    if (service.Contains("Café"))
                        station.ServiceType |= ServiceType.Cafe;
                    if (service.Contains("Toilet"))
                        station.ServiceType |= ServiceType.WC;
                    if (service.Contains("Shop"))
                        station.ServiceType |= ServiceType.Shop;
                }
                
                foreach (var fuel in stJson.fuelServices)
                {
                    if (fuel.Contains("61293"))
                        station.FuelType |= FuelType.Diesel;
                    if (fuel.Contains("61336"))
                        station.FuelType |= FuelType.A95;
                    if (fuel.Contains("61294"))
                        station.FuelType |= FuelType.A95F;
                    if (fuel.Contains("61338"))
                        station.FuelType |= FuelType.A98F;
                }
                
                result.Add(station);
            }

            return result;
        }
Exemple #4
0
        List<BenzinStation> ParseHtml(String html)
        {
            var result = new List<BenzinStation>();
            var htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(html);

            var nav = htmlDoc.DocumentNode.SelectSingleNode("//nav");
            foreach (var li in nav.SelectNodes("//li[@class='b-left-menu_item']"))
            {
                var station = new BenzinStation()
                {
                    Address = li.GetAttributeValue("data-address", "")
                };
                
                if (String.IsNullOrEmpty(station.Address))
                    continue;

                station.Name = li.SelectSingleNode("//a").InnerText.Trim();
                if (li.GetAttributeValue("data-fuel-260", "") == "1")
                    station.FuelType |= FuelType.LPG;
                if (li.GetAttributeValue("data-fuel-261", "") == "1")
                    station.FuelType |= FuelType.A92;
                if (li.GetAttributeValue("data-fuel-262", "") == "1")
                {
                    station.FuelType |= FuelType.A92;
                    station.FuelType |= FuelType.A95;
                }
                if (li.GetAttributeValue("data-fuel-269", "") == "1")
                    station.FuelType |= FuelType.Diesel;

                if (li.GetAttributeValue("data-shop", "") == "1")
                    station.ServiceType |= ServiceType.Shop;

                var coordsText = li.GetAttributeValue("data-coords", "");
                var coords = ParseHelper.GetCoordinates(coordsText, " ", false);
                station.Dolgota = coords.Dolgota;
                station.Shirota = coords.Shirota;

                result.Add(station);
            }

            return result;
        }
Exemple #5
0
        async Task<List<BenzinStation>> GetStations(String cityUrl)
        {
            var result = new List<BenzinStation>();
            var html = await HttpHelper.HttpGet(cityUrl);

            int index = 0;

            while (true)
            {
                var coordString = ParseHelper.GetSubstring(html, "YMaps.GeoPoint(", ")", index, out index);
                if (String.IsNullOrEmpty(coordString))
                    break;

                var coords = ParseHelper.GetCoordinates(coordString, ",", false);
                var station = new BenzinStation() { Dolgota = coords.Dolgota, Shirota = coords.Shirota };
                FillStation(ParseHelper.GetSubstring(html, "placemark.description = '", "'", index, out index), station);
                result.Add(station);
            }

            return result;
        }
Exemple #6
0
        List<BenzinStation> GetStations(String json)
        {
            var result = new List<BenzinStation>();
            try
            {
                var mapJson = JsonConvert.DeserializeObject<MapJson>(json);

                foreach (var stationJson in mapJson.data)
                {
                    if (stationJson.country != "Russia")
                        continue;

                    var station = new BenzinStation()
                    {
                        Url = stationJson.id,
                        Name = stationJson.location,
                        Dolgota = stationJson.lng,
                        Shirota = stationJson.lat,
                        Address = stationJson.address1,
                    };

                    if (stationJson.flag_amenity_atm.HasValue && stationJson.flag_amenity_atm.Value)
                        station.ServiceType |= ServiceType.ATM;
                    if (stationJson.flag_amenity_carwash.HasValue && stationJson.flag_amenity_carwash.Value)
                        station.ServiceType |= ServiceType.Wash;
                    if (stationJson.flag_amenity_toilet.HasValue && stationJson.flag_amenity_toilet.Value)
                        station.ServiceType |= ServiceType.WC;
                    if ( (stationJson.flag_cafeteria.HasValue && stationJson.flag_cafeteria.Value) || (stationJson.flag_restaurant.HasValue && stationJson.flag_restaurant.Value) )
                        station.ServiceType |= ServiceType.Cafe;
                    if (stationJson.flag_hasShop.HasValue && stationJson.flag_hasShop.Value)
                        station.ServiceType |= ServiceType.Shop;

                    if (stationJson.note_json_fuel.Contains("10"))
                        station.FuelType |= FuelType.A95F;
                    if (stationJson.note_json_fuel.Contains("14"))
                        station.FuelType |= FuelType.A95;
                    if (stationJson.note_json_fuel.Contains("15"))
                        station.FuelType |= FuelType.A92;
                    if (stationJson.note_json_fuel.Contains("16"))
                        station.FuelType |= FuelType.Diesel;
                    if (stationJson.note_json_fuel.Contains("22"))
                        station.FuelType |= FuelType.A98F;

                        result.Add(station);
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error("Не удалось распарсить json:" + json, ex);
            }

            return result;
        }
Exemple #7
0
        async Task FillStationParams(BenzinStation station)
        {
            var text = await GetStationInfo(station.Url);

            var stationJson = JsonConvert.DeserializeObject<StationsJson>(text).data.First();

            if ( (stationJson.flag_Bistro.HasValue && stationJson.flag_Bistro.Value) ||
                 (stationJson.flag_PetitBistro.HasValue && stationJson.flag_PetitBistro.Value) ||
                 (stationJson.flag_WildBeanCafe.HasValue && stationJson.flag_WildBeanCafe.Value) )
                station.ServiceType |= ServiceType.Cafe;

            if ( stationJson.flag_CarWash.HasValue && stationJson.flag_CarWash.Value )
                station.ServiceType |= ServiceType.Wash;

            if (stationJson.flag_Cashpoint.HasValue && stationJson.flag_Cashpoint.Value)
                station.ServiceType |= ServiceType.ATM;

            if (stationJson.flag_Toilet.HasValue && stationJson.flag_Toilet.Value)
                station.ServiceType |= ServiceType.WC;

            if (stationJson.flag_Shop.HasValue && stationJson.flag_Shop.Value)
                station.ServiceType |= ServiceType.Shop;

            if (stationJson.flag_Regular92.HasValue && stationJson.flag_Regular92.Value)
                station.FuelType |= FuelType.A92;
            if (stationJson.flag_RegularDiesel.HasValue && stationJson.flag_RegularDiesel.Value)
                station.FuelType |= FuelType.Diesel;
            if (stationJson.flag_Ultimate98.HasValue && stationJson.flag_Ultimate98.Value)
                station.FuelType |= FuelType.A98F;
            if (stationJson.flag_UltimateDiesel.HasValue && stationJson.flag_UltimateDiesel.Value)
                station.FuelType |= FuelType.DieselF;
            if (stationJson.flag_UltimateUnleaded.HasValue && stationJson.flag_UltimateUnleaded.Value)
                station.FuelType |= FuelType.A95F;
            if (stationJson.flag_Unleaded95.HasValue && stationJson.flag_Unleaded95.Value)
                station.FuelType |= FuelType.A95;

            station.Dolgota = stationJson.lng;
            station.Shirota = stationJson.lat;
    
            station.Address = stationJson.city + stationJson.address1;
            station.Name = stationJson.location;
        }
Exemple #8
0
        List<BenzinStation> GetStationsInfo(String text)
        {
            var start = "<li";
            var end = "/li>";
            var startIndex = text.IndexOf(start);
            var endIndex = text.LastIndexOf(end) + end.Length;
            var html = text.Substring(startIndex, endIndex - startIndex);

            html = Regex.Unescape(html);
            html = html.Replace("\n", "");
            html = html.Replace("\r", "");
            while (html.Contains("  "))
                html = html.Replace("  ", " ");

            var htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(html);

            var stations = new List<BenzinStation>();
            foreach (var mainNode in htmlDoc.DocumentNode.SelectNodes(".//li[@class='search_result_list_item']"))
            {
                var station = new BenzinStation()
                {
                    Url = mainNode.Id.Replace("sr_", "")
                };

                foreach (var node in mainNode.SelectNodes("p"))
                {
                    station.Name = node.SelectSingleNode("strong").InnerText.Trim();
                    var s = node.InnerHtml.Replace("<br>", "").Replace("</br>", "").Replace("<strong>", "").Replace("</strong>", "").Trim().Remove(0, station.Name.Length + 1).Trim();
                    station.Address = node.InnerText.Remove(0, station.Name.Length + 1).Trim();
                }

                stations.Add(station);
            }

            return stations;
        }