Exemplo n.º 1
0
        public async Task<IEnumerable<BenzinStation>> Mine()
        {
            GetCookieAndToken();

            var piter = new GeoCoordinate("59.95", "30.316667");
            var stationsHtml = await GetStationsText(piter);
            var stations = GetStationsInfo(stationsHtml);


            var moscow = new GeoCoordinate("55.755833", "37.617778");
            stationsHtml = await GetStationsText(moscow);
            var moscowStations = GetStationsInfo(stationsHtml);

            // объединяем азс из Питера и Москвы
            var existStationIds = stations.Select(s => s.Url).ToList();
            foreach (var s in moscowStations)
                if (!existStationIds.Contains(s.Url))
                    stations.Add(s);

            var tasks = new List<Task>();
            foreach (var s in stations)
            {
                tasks.Add(Task.Run(async () =>
                {
                    await FillStationParams(s);
                }));
            }
            Task.WaitAll(tasks.ToArray());


            YandexGeocoderHelper.FillStationsCity(stations);

            return stations;
        }
Exemplo n.º 2
0
        async Task<String> GetStationsText(GeoCoordinate center)
        {
            var client = new RestClient("http://maps2.bp.com/geo_footprint_bpconsumer_locations/radial_results?asset_path=%2Fimages%2Fapp%2Fbpconsumer%2Ficons&country=RU&display_language=ru&filter_list=flag_UltimateDiesel%2Cflag_UltimateUnleaded%2Cflag_WildBeanCafe%2Cflag_MSSimplyFood%2Cflag_LPG%2Cflag_Open24Hours%2Cflag_Cashpoint%2Cflag_CarWash%2Cflag_Ultimate%2Cflag_MotorwaySite%2Cflag_Toilet%2Cflag_BPConnectStore%2Cflag_Restaurant%2Cflag_Lotto%2Cflag_JetWash%2Cflag_HighSpeedPump%2Cflag_Alcohol%2Cflag_Wifi%2Cflag_Shop%2Cflag_DisabledFacilities%2Cflag_SuperMarket%2Cflag_BakeryBistro%2Cflag_PetitBistro%2Cflag_AutomaticSite%2Cflag_Ultimate102%2Cflag_TruckWash%2Cflag_TruckSuitableSite%2Cflag_TruckParking%2Cflag_TruckDiesel%2Cflag_PumpRewards%2Cflag_Workshop%2Cflag_Tobacco%2Cflag_SpecialCarWash%2Cflag_ShopOpen24Hours%2Cflag_ReminderService%2Cflag_RedDiesel%2Cflag_OpenSunday%2Cflag_OpenSaturday%2Cflag_NaturalGas%2Cflag_LorryAndTruckTerminal%2Cflag_BunkerSite%2Cflag_BP%2Cflag_Bistro%2Cflag_Autogas%2Cflag_AralStore%2Cflag_Aral%2Cflag_AdbluePump%2Cflag_AdBlueCannister%2Cflag_AdBlue%2Cflag_AcceptsTollPayments%2Cflag_AcceptsRoutexCards%2Cflag_CardsCodes%2Cflag_RUC%2Cflag_Trailers%2Cflag_AASmartfuel%2Cflag_Ultimate98%2Cflag_TruckOnly%2Cflag_bonusclub%2Cflag_gobox%2Cflag_merkur%2Cflag_ultimatesuper%2Cflag_Opt%2Cflag_Shower%2Cflag_WashingMachine%2Cflag_DryCleaning%2Cflag_FreshPastry%2Cflag_TiresPumpUp%2Cflag_Regular92&location_js_call=renderSmartMarkerDirect&results_container=search_result_list&selection_filter=datasource+in+%280%2C+2%2C+4%2C+5%2C+8%29+AND+NOT+%28datasource+%3D+0+AND+Country+%3D+%22Austria%22%29");
            var request = new RestRequest(Method.POST);
            request.AddHeader("content-type", "application/x-www-form-urlencoded");
            request.AddHeader("X-Requested-With", "XMLHttpRequest");

            var formData = String.Format("searchfield=&override_filter=TRUE&lat={0}&lng={1}&swlat={2}&swlng={3}&nelat={4}&nelng={5}&authenticity_token={6}", center.Shirota, center.Dolgota, sw_lat, sw_lng, ne_lat, ne_lng, authencityToken);
            request.AddParameter("application/x-www-form-urlencoded", formData, ParameterType.RequestBody);

            CookieContainer _cookieJar = new CookieContainer();

            foreach (var cookie in cookies)
                _cookieJar.Add(cookie);

            client.CookieContainer = _cookieJar;

            IRestResponse response = await client.ExecuteTaskAsync(request);
            return response.Content;
        }