コード例 #1
0
        public async Task <bool> DownloadPage(PF2WebListItem item, Action <DownloadPageRes> callback)
        {
            DownloadPageRes res = new DownloadPageRes();

            res.Item = item;

            string infoname = item.FileName;

            string text;



            if (File.Exists(infoname))
            {
                res.Result = false;
            }
            else
            {
                HttpResponseMessage resp = await client.GetAsync(item.Url);

                text = await resp.Content.ReadAsStringAsync();

                text.SpitFile(infoname);


                Thread.Sleep(500);
                res.Result = true;
            }

            callback.Invoke(res);

            return(res.Result);
        }
コード例 #2
0
        public async Task <List <PF2WebListItem> > GetSourcePage()
        {
            var list = new List <PF2WebListItem>();

            HttpResponseMessage resp = await client.GetAsync("https://pf2.d20pfsrd.com/srd-content-source/pf2bestiary/");

            string text = await resp.Content.ReadAsStringAsync();



            var m = Regex.Matches(text, pagematch);



            foreach (Match mo in m)
            {
                var x = new PF2WebListItem()
                {
                    Name      = mo.Value("name"),
                    Type      = mo.Value("type"),
                    Url       = mo.Value("page"),
                    Publisher = mo.Value("pubname"),
                    Source    = mo.Value("source")
                };
                list.Add(x);
            }


            return(list);
        }
コード例 #3
0
        public async Task <GetInfoRes> GetInfo(PF2WebListItem item, Action <GetInfoRes> callback = null)
        {
            ConsoleHelper.WriteLine(">>>  " + item.Name);

            GetInfoRes res = new GetInfoRes();

            try
            {
                res.Item = item;

                string text = await LoadPrefixedPage(item);


                string matchtext = MatchText;



                res.List = new List <PF2WebMonsterInfo>();
                ConsoleHelper.WriteLine("   >>> " + item.Name);


                MatchCollection ma = Regex.Matches(text, matchtext);

                using (var s = File.Open(item.Name + ".txt", FileMode.Create))
                    using (var r = new StreamWriter(s))
                    {
                        int foo = 0;

                        foreach (Match m in ma)
                        {
                            PF2WebMonsterInfo info = new PF2WebMonsterInfo();
                            info.Name = m.Value("name") ?? m.Value("name2") ?? m.Value("name3");


                            info.Type = m.Values("trait");
                            res.List.Add(info);

                            if (foo > 0)
                            {
                                r.WriteLine("--------");
                            }
                            foo++;


                            r.WriteLine(info.Name);
                        }
                    }

                res.Result = res.List.Count > 0;
            }
            catch (Exception ex)
            {
                ConsoleHelper.WriteLine("X*X*X*X*X------" + item.Name);
            }
            callback?.Invoke(res);


            return(res);
        }
コード例 #4
0
        public async Task <List <PF2WebListItem> > GetMonsters()
        {
            var list = new List <PF2WebListItem>();

            StringBuilder match = new StringBuilder();

            match.OpenRow();
            match.MakeUrlCell("url", "name", false);
            match.MultiUrlCell("familyurl", "family", optional: true);
            match.MakeTextCell(name: "level");
            match.MakeUrlCell("publisherurl", "publisher", true);
            match.MakeUrlCell("sourceurl", "source", true);
            match.CloseRow();

            string text;

            if (File.Exists(monsteroutname))
            {
                text = await monsteroutname.LoadFileAsync();
            }
            else
            {
                HttpResponseMessage resp = await client.GetAsync("https://pf2.d20pfsrd.com/monster");

                text = await resp.Content.ReadAsStringAsync();

                text.SpitFile(monsteroutname);
            }



            string mt = match.ToString();

            var m = Regex.Matches(text, mt);



            using (var s = File.Open("lasturl.txt", FileMode.Create))
                using (var r = new StreamWriter(s))
                {
                    r.WriteLine(mt);
                }
            foreach (Match mo in m)
            {
                var x = new PF2WebListItem()
                {
                    Name      = mo.Value("name"),
                    Family    = mo.Value("family"),
                    Url       = mo.Value("url"),
                    Publisher = mo.Value("publisher"),
                    Source    = mo.Value("source"),
                    Level     = mo.Value("level")
                };
                list.Add(x);
            }


            return(list);
        }
コード例 #5
0
        public async Task <string> LoadPrefixedPage(PF2WebListItem item)
        {
            if (File.Exists(item.BuildFileName))
            {
                return(await item.BuildFileName.LoadFileAsync());
            }

            else
            {
                string text = await LoadPageText(item);

                ConsoleHelper.WriteLine(item.BuildFileName);

                text = text.PrefixEscapes();

                await text.SpitFileAsync(item.BuildFileName);

                return(text);
            }
        }
コード例 #6
0
 public async Task <string> LoadPageText(PF2WebListItem item)
 {
     return(await item.FileName.LoadFileAsync());
 }
コード例 #7
0
 public string BuildFileName(PF2WebListItem item)
 {
     return(item.Name + ".b.html");
 }