Example #1
0
        public IEnumerable <string> Parse(string text)
        {
            string tabletext = Parser.ExtractContent(text, Start, End, true, false);

            int maxIndexNumber = -1;

            foreach (Match match in _cardLineRegex.Matches(tabletext))
            {
                string row = match.Groups["row"].Value;
                IDictionary <string, string> columnInfos = ExtractColumnInfos(row);

                string number = Get(columnInfos, "number");
                if (!string.IsNullOrWhiteSpace(number))
                {
                    int indexNumber = int.Parse(number);
                    maxIndexNumber = indexNumber > maxIndexNumber ? indexNumber : maxIndexNumber;
                }
                Match m = _cardNameUrlRegex.Match(Get(columnInfos, "name"));
                if (!m.Success)
                {
                    throw new ParserException("Can't parse name for" + row);
                }

                yield return(m.Groups["url"].Value);
            }

            NextPageChecker.CheckHasNextPage(text, false);
        }
Example #2
0
        public IEnumerable <CardLanguageInfo> Parse(string text)
        {
            string newtext = Parser.ExtractContent(text, Start, End, true, false);

            bool header             = true;
            int  translateNameIndex = -1;
            int  languageNameIndex  = -1;

            foreach (string row in GetTableRow(newtext))
            {
                string trimedrow = row.Replace("\r", "").Replace("\n", "");
                if (trimedrow.Contains(@"<tr id=""ctl00_ctl00_ctl00_MainContent_SubContent_SubContent_languageList_noOtherLanguagesParent"">"))
                {
                    continue;
                }

                if (trimedrow.Contains(@"<tr id=""ctl00_ctl00_ctl00_MainContent_SubContent_SubContent_languageList_pagingControlsParent"">"))
                {
                    NextPageChecker.CheckHasNextPage(trimedrow, true);
                }

                string[] columns = trimedrow.Split(new[] { "</td>" }, StringSplitOptions.None);
                if (header)
                {
                    for (int i = 0; i < columns.Length; i++)
                    {
                        string column = columns[i];
                        if (column.Contains(">Translated Card Name<"))
                        {
                            translateNameIndex = i;
                        }
                        else if (column.Contains(">Language<"))
                        {
                            languageNameIndex = i;
                        }
                    }

                    if (languageNameIndex == -1 || translateNameIndex == -1)
                    {
                        throw new ParserException("Can't parse language page.");
                    }

                    header = false;
                    continue;
                }

                Match m = _cardNameRegex.Match(columns[translateNameIndex]);
                if (!m.Success)
                {
                    throw new ParserException("Can't find card name in foreign language");
                }

                string cardName = m.Groups["name"].Value.Trim();
                if (string.IsNullOrWhiteSpace(cardName))
                {
                    throw new ParserException("Card name in foreign language is null or empty");
                }

                m = _languageRegex.Match(columns[languageNameIndex]);
                if (!m.Success)
                {
                    throw new ParserException("Can't find foreign language name");
                }

                string languageName = m.Groups["name"].Value;
                if (string.IsNullOrWhiteSpace(languageName))
                {
                    throw new ParserException("Foreign language name is null or empty");
                }

                yield return(new CardLanguageInfo {
                    Language = languageName, Name = cardName
                });
            }
        }