Пример #1
0
        public static async Task <CanyonBooksInfo> FetchCanyonBooks(CanyonInfo canyon, CanyonInfoConfig config, string urlFormat, string csvLocationFormat)
        {
            var csvPath = string.Format(csvLocationFormat, canyon.Id);

            if (File.Exists(csvPath))
            {
                return(JsonConvert.DeserializeObject <CanyonBooksInfo>(await File.ReadAllTextAsync(csvPath)));
            }

            var url     = string.Format(urlFormat, canyon.Id);
            var content = await HttpFetcher.FetchContent(url);

            var data = Regex.Match(content, "Livres? \\/ Topoguides?<\\/h2><\\/div>([\\S\\s]*)<div class=\"list-group-item\"><h2><span class=\"ic glyphicon-random\"><\\/span> Carte<\\/h2>").Groups[1].Value;

            var matches  = Regex.Matches(data, "<a href=\"([/A-z0-9.-]*)\"><h5>");
            var bookUrls = new List <string>();

            foreach (Match match in matches)
            {
                bookUrls.Add(match.Groups[1].Value);
            }
            var books = new CanyonBooksInfo
            {
                Url          = url,
                BookUrls     = bookUrls,
                ABookIsOwned = config.OwnedBooks.Any(x => bookUrls.Contains(x))
            };

            await File.WriteAllTextAsync(csvPath, JsonConvert.SerializeObject(books));

            return(books);
        }
Пример #2
0
        public static async Task <CanyonRouteInfo> FetchCanyonRoute(CanyonInfo canyon, CanyonInfoConfig config, string urlFormat, string csvLocationFormat)
        {
            var csvPath = string.Format(csvLocationFormat, canyon.Id);

            if (File.Exists(csvPath))
            {
                return(JsonConvert.DeserializeObject <CanyonRouteInfo>(await File.ReadAllTextAsync(csvPath)));
            }

            var url     = string.Format(urlFormat, config.CenterX, config.CenterY, canyon.CoordX, canyon.CoordY);
            var content = await HttpFetcher.FetchContent(url);

            var matrix = JsonConvert.DeserializeObject <RouteMatrix>(content);

            var routeInfo = new CanyonRouteInfo
            {
                Url      = url,
                Distance = matrix.Rows[0].Elements[0].Distance?.Value ?? 0,
                Duration = TimeSpan.FromSeconds(matrix.Rows[0].Elements[0].Duration?.Value ?? 0)
            };

            await File.WriteAllTextAsync(csvPath, JsonConvert.SerializeObject(routeInfo));

            return(routeInfo);
        }
Пример #3
0
        public static async Task <List <CanyonPointCsvInfo> > FetchCanyonPoints(CanyonInfo canyon, string urlFormat, string csvLocationFormat)
        {
            var csvPath = string.Format(csvLocationFormat, canyon.Id);

            if (File.Exists(csvPath))
            {
                return((await File.ReadAllLinesAsync(csvPath)).Select(x => new CanyonPointCsvInfo(x.Split(","))).ToList());
            }

            var content = await HttpFetcher.FetchContent(string.Format(urlFormat, canyon.Id));

            var match     = Regex.Matches(content, "var point = ({[^}]*});addMarker\\(point\\);");
            var pointData = match.Select(x => x.Value).ToList();
            var points    = new List <CanyonPointCsvInfo>();

            foreach (var point in pointData)
            {
                var parts = Regex.Match(point, "var point = {position: new google.maps.LatLng\\((.*),(.*)\\),type: '(.*)',remarque: '[^}]*};addMarker\\(point\\);");
                points.Add(new CanyonPointCsvInfo(parts.Groups.Values.Skip(1).Select(x => x.Value).ToArray()));
            }

            var text = "";

            foreach (var point in points)
            {
                text += $"{point.CoordX},{point.CoordY},{point.Type}\r\n";
            }
            await File.WriteAllTextAsync(csvPath, text);

            return(points);
        }
        public static async Task <CanyonDescription> FetchCanyonDescription(CanyonInfo canyon, string urlFormat, string csvLocationFormat)
        {
            var csvPath = string.Format(csvLocationFormat, canyon.Id);
            //if (File.Exists(csvPath))
            //    return JsonConvert.DeserializeObject<CanyonDescription>(await File.ReadAllTextAsync(csvPath));

            var url     = string.Format(urlFormat, canyon.Id);
            var content = await HttpFetcher.FetchContent(url);

            var data   = Regex.Match(content, "<div class=\"fichetechniqueintegree\">([\\S\\s]*)<\\/div>").Groups[1].Value;
            var resume = new CanyonDescription
            {
                Url               = url,
                Score             = Regex.Match(data, "<strong>([0-9.]*)</strong>/4").Groups[1].Value.ToNDouble(),
                AltitudeDeparture = Regex.Match(data, "Alti dép. ([0-9.]*)m").Groups[1].Value,
                HeightDifference  = Regex.Match(data, "Dénivelé ([0-9.]*)m").Groups[1].Value,
                Length            = Regex.Match(data, "Longueur ([0-9.]*)m").Groups[1].Value,
                MaxWaterfall      = Regex.Match(data, "Casc. max ([0-9.]*)m").Groups[1].Value,
                Quotation         = Regex.Match(data, "Cotation ([av0-7IV]*)").Groups[1].Value,
                RopeLength        = Regex.Match(data, "Corde ([0-9.]*)m").Groups[1].Value,
                Approach          = GetDuration(Regex.Match(data, "Approche: ([A-zÀ-ú0-9.]*)").Groups[1].Value),
                Descent           = GetDuration(Regex.Match(data, "Descente: ([A-zÀ-ú0-9.]*)").Groups[1].Value),
                Return            = GetDuration(Regex.Match(data, "Retour: ([A-zÀ-ú0-9.]*)").Groups[1].Value),
                Navette           = Regex.Match(data, "Navette: ([A-zÀ-ú0-9.]*)").Groups[1].Value
            };

            await File.WriteAllTextAsync(csvPath, JsonConvert.SerializeObject(resume));

            return(resume);
        }