Beispiel #1
0
        private async Task ParseDiaryAccess(AccountDto accountDto, CancellationToken cancellationToken)
        {
            using (var doc = await GetDoc(AccountPagesFileNames.DiaryAccess, cancellationToken))
            {
                if (doc == null)
                {
                    return;
                }
                var accessInput = doc.QuerySelector("input[name='access_mode']:checked");
                accountDto.JournalAccess = accessInput.GetAttribute("value");

                var checked18 = doc.QuerySelector("input[name='access_mode2']");
                if (checked18.HasAttribute("checked"))
                {
                    accountDto.JournalAccess = Convert.ToString(Convert.ToInt32(accountDto.JournalAccess) + Convert.ToInt32(checked18.GetAttribute("value")));
                }
                accountDto.JournalList.AddRange(doc.QuerySelector("#access_list").TextContent.Split("\n").Where(s => !string.IsNullOrEmpty(s)));
            }
        }
Beispiel #2
0
        private async Task ParseMainPage(AccountDto accountDto, CancellationToken cancellationToken)
        {
            using (var doc = await GetDoc(AccountPagesFileNames.DiaryMain, cancellationToken))
            {
                if (doc == null)
                {
                    return;
                }
                var href = doc.QuerySelector("a[title='профиль']")?.GetAttribute("href") ??
                           doc.QuerySelector("#main_menu")?
                           .QuerySelectorAll("a")
                           .FirstOrDefault(a => a.HasAttribute("href") && a.GetAttribute("href").Contains("/member/?"))?
                           .GetAttribute("href");

                accountDto.UserId = Regex.Replace(href, @"\/member\/\?(\d+)$", "$1");
                //accountDto.UserName = profileLink.TextContent;

                var journalLink  = doc.QuerySelector("#m_menu a") ?? doc.QuerySelector("#main_menu a");
                var journalMatch = Regex.Match(journalLink.GetAttribute("href"), @"https?:\/\/(.*)\.diary\.ru");
                if (journalLink.TextContent.Contains("ой дневник"))
                {
                    accountDto.Journal = "1";
                    if (journalMatch.Success)
                    {
                        accountDto.ShortName = journalMatch.Groups[1].Value;
                    }
                }
                else if (journalLink.TextContent.Contains("сообще"))
                {
                    accountDto.Journal = "2";
                    if (journalMatch.Success)
                    {
                        accountDto.ShortName = journalMatch.Groups[1].Value;
                    }
                }
                else if (journalLink.TextContent.Contains("авести"))
                {
                    accountDto.Journal = "0";
                }
            }
        }
Beispiel #3
0
        public async Task ParseAccountData(AccountDto accountDto, CancellationToken cancellationToken)
        {
            var methods = (from method in this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
                           let parameters = method.GetParameters()
                                            where parameters.Count() == 2 &&
                                            parameters[0].ParameterType == typeof(AccountDto) &&
                                            parameters[1].ParameterType == typeof(CancellationToken) &&
                                            method.ReturnType == typeof(Task)
                                            select method);

            var tasks = new List <Task>();

            try
            {
                foreach (var method in methods)
                {
                    var task = method.Invoke(this, new object[] { accountDto, cancellationToken }) as Task;
                    tasks.Add(task);
                }
                foreach (var task in tasks)
                {
                    await task;
                }
            }
            catch (AggregateException e)
            {
                foreach (var ee in e.InnerExceptions)
                {
                    _logger.LogError(ee, "Parsing error");
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Parsing error");
            }

            // this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
            // .Where(m => m.GetParameters)
        }
Beispiel #4
0
 private async Task ParseProfile(AccountDto accountDto, CancellationToken cancellationToken)
 {
     using (var doc = await GetDoc(AccountPagesFileNames.Profile, cancellationToken))
     {
         if (doc == null)
         {
             return;
         }
         accountDto.ByLine = doc.QuerySelector("input[name='usertitle']").GetAttribute("value");
         var month = doc.QuerySelector("select#month option[selected]")?.GetAttribute("value") ?? "0";
         var day   = doc.QuerySelector("select#day option[selected]")?.GetAttribute("value") ?? "0";
         var year  = doc.QuerySelector("select#year option[selected]")?.TextContent ?? "0";
         accountDto.Birthday = $"{year.PadLeft(4, '0')}-{month.PadLeft(2, '0')}-{day.PadLeft(2, '0')}";
         var sexVal = doc.QuerySelector("input[name='sex']:checked")?.GetAttribute("value");
         if (sexVal != null)
         {
             accountDto.Sex = sexVal == "1" ? "Мужской" : "Женский";
         }
         accountDto.Education = doc.QuerySelector("select#education option[selected]")?.TextContent ?? "";
         accountDto.Sfera     = doc.QuerySelector("select#sfera option[selected]")?.TextContent ?? "";
         accountDto.About     = doc.QuerySelector("#about").TextContent;
     }
 }