public static string GetReplyForMPLinks(Comment comment)
        {
            List <MPObject> foundMPObjects = new List <MPObject>();

            foreach (string url in ExtractMPLinks(WebUtility.HtmlDecode(comment.Body)))
            {
                MPObject mpObjectWithID = MountainProjectDataSearch.GetItemWithMatchingID(Utilities.GetID(url));
                if (mpObjectWithID != null)
                {
                    foundMPObjects.Add(mpObjectWithID);
                }
            }

            string response = "";

            if (foundMPObjects.Count == 0)
            {
                return(null);
            }

            foundMPObjects.ForEach(p => response += GetFormattedString(p, includeUrl: false) + Markdown.HRule);
            response += GetBotLinks(comment);

            return(response);
        }
        private static string GetPopularRoutes(Area area, ResultParameters parameters)
        {
            string result = "";

            List <Route> popularRoutes = new List <Route>();

            if (area.PopularRouteIDs.Count == 0) //MountainProject doesn't list any popular routes. Figure out some ourselves
            {
                popularRoutes = area.GetPopularRoutes(3);
            }
            else
            {
                area.PopularRouteIDs.ForEach(id => popularRoutes.Add(MountainProjectDataSearch.GetItemWithMatchingID(id, MountainProjectDataSearch.DestAreas) as Route));
            }

            foreach (Route popularRoute in popularRoutes)
            {
                result += $"\n- {Markdown.Link(popularRoute.Name, popularRoute.URL)} {GetRouteAdditionalInfo(popularRoute, parameters)}";
            }

            if (string.IsNullOrEmpty(result))
            {
                return("");
            }

            return("Popular routes:" + Markdown.NewLine + result + Markdown.NewLine);
        }
        public void TestGradeEquality()
        {
            InitMPData();

            for (int i = 0; i < testCriteria_gradeEquality.GetLength(0); i++)
            {
                string      inputUrl      = testCriteria_gradeEquality[i, 0].ToString();
                GradeSystem gradeSystem   = (GradeSystem)testCriteria_gradeEquality[i, 1];
                string      inputGrade    = testCriteria_gradeEquality[i, 2].ToString();
                Grade       expectedGrade = Grade.ParseString(inputGrade)[0];

                Route route = MountainProjectDataSearch.GetItemWithMatchingID(Utilities.GetID(Utilities.MPBASEURL + inputUrl)) as Route;

                Assert.IsTrue(route.Grades.Any(g => expectedGrade.Equals(g, true, true)));
            }
        }
Example #4
0
        private static string GetApproval(Dictionary <string, string> parameters, ApprovalRequest approvalRequest)
        {
            string result = "";

            if (parameters.ContainsKey("approveother"))
            {
                if (parameters.ContainsKey("option"))
                {
                    foreach (string approvedId in parameters["option"].Split(','))
                    {
                        MPObject matchingOption = approvalRequest.SearchResult.AllResults.Find(p => p.ID == approvedId) ?? MountainProjectDataSearch.GetItemWithMatchingID(approvedId);
                        if (matchingOption == null)
                        {
                            result += $"Option '{approvedId}' not found<br>";
                        }
                        else
                        {
                            approvalRequest.ApprovedResults.Add(matchingOption);
                        }
                    }
                }
                else
                {
                    return(ShowApproveOtherPicker(parameters, approvalRequest));
                }
            }
            else if (parameters.ContainsKey("approve"))
            {
                approvalRequest.ApprovedResults = new List <MPObject> {
                    approvalRequest.SearchResult.FilteredResult
                };
                approvalRequest.RelatedLocation = approvalRequest.SearchResult.RelatedLocation;
            }
            else if (parameters.ContainsKey("approveall"))
            {
                approvalRequest.ApprovedResults = approvalRequest.SearchResult.AllResults;
                approvalRequest.RelatedLocation = approvalRequest.SearchResult.RelatedLocation;
            }

            if (approvalRequest.IsApproved)
            {
                BotFunctions.PostsPendingApproval[parameters["postid"]] = approvalRequest;
                result = $"Approved:<br>{string.Join("<br>", approvalRequest.ApprovedResults.Select(r => $"&#8226; {r.Name} ({r.ID})"))}"; //Print out approved results as a bulleted list
            }

            return(WrapHtml($"<h1>{result}</h1>"));
        }
Example #5
0
        private static void AddNewItems()
        {
            Parsers.TotalTimer = totalTimer;
            List <Area> destAreas = Parsers.GetDestAreas();

            DateTime        lastBuild = File.GetLastWriteTime(serializationPath);
            string          rssUrl    = $"https://www.mountainproject.com/rss/new?selectedIds={string.Join(",", destAreas.Select(p => p.ID))}&routes=on&areas=on";
            SyndicationFeed feed      = null;

            using (XmlReader reader = XmlReader.Create(rssUrl))
            {
                feed = SyndicationFeed.Load(reader);
            }

            IEnumerable <string> newlyAddedItemUrls = feed.Items.Where(p => p.PublishDate > lastBuild).OrderBy(p => p.PublishDate).Select(p => p.Links[0].Uri.ToString());

            MountainProjectDataSearch.InitMountainProjectData(serializationPath);

            foreach (string newItemUrl in newlyAddedItemUrls)
            {
                string newId = Utilities.GetID(newItemUrl);

                if (MountainProjectDataSearch.GetItemWithMatchingID(newId) != null) //Item has already been added (probably via a recursive area add)
                {
                    continue;
                }

                MPObject newItem;
                if (newItemUrl.Contains(Utilities.MPAREAURL))
                {
                    newItem = new Area {
                        ID = newId
                    };
                    Parsers.ParseAreaAsync(newItem as Area).Wait();
                }
                else
                {
                    newItem = new Route {
                        ID = newId
                    };
                    Parsers.ParseRouteAsync(newItem as Route).Wait();
                }

                Area currentParent = null;
                bool itemAddedViaRecursiveParse = false;
                foreach (string parentId in newItem.ParentIDs) //Make sure all parents are populated
                {
                    MPObject matchingItem = MountainProjectDataSearch.GetItemWithMatchingID(parentId);
                    if (matchingItem == null)
                    {
                        Area newArea = new Area {
                            ID = parentId
                        };
                        Parsers.ParseAreaAsync(newArea).Wait();
                        currentParent.SubAreas.Add(newArea);
                        itemAddedViaRecursiveParse = true;
                        break;
                    }
                    else
                    {
                        currentParent = matchingItem as Area;
                    }
                }

                if (!itemAddedViaRecursiveParse)
                {
                    if (newItem is Area)
                    {
                        (MountainProjectDataSearch.GetItemWithMatchingID(newItem.ParentIDs.Last()) as Area).SubAreas.Add(newItem as Area);
                    }
                    else
                    {
                        (MountainProjectDataSearch.GetItemWithMatchingID(newItem.ParentIDs.Last()) as Area).Routes.Add(newItem as Route);
                    }
                }
            }

            destAreas = MountainProjectDataSearch.DestAreas;

            totalTimer.Stop();
            Console.WriteLine($"------PROGRAM FINISHED------ ({totalTimer.Elapsed})");
            Console.WriteLine();
            Console.WriteLine($"Total # of areas: {Parsers.TotalAreas}, total # of routes: {Parsers.TotalRoutes}");
            SerializeResults(destAreas);

            SendReport($"MountainProjectDBBuilder database updated SUCCESSFULLY in {totalTimer.Elapsed}", $"{newlyAddedItemUrls.Count()} new items:\n\n{string.Join("\n", newlyAddedItemUrls)}");
        }