Пример #1
0
        //Get 10 toiec sentence
        public ListPostFB GetToiecExamList()
        {
            ListPostFB result           = new ListPostFB();
            var        listAllToiecExam = GetAll().Where(x => x.DapAn != null && x.DapAn != "");
            var        tempToiec        = listAllToiecExam.Skip(Math.Max(0, listAllToiecExam.Count() - 10)).ToList();

            foreach (var postData in tempToiec)
            {
                Model.Feeds.Datum temp = new Model.Feeds.Datum();
                temp.id        = postData.Id_Post;
                temp.imageURL  = postData.ImageUrl;
                temp.message   = postData.Content;
                temp.DapAn     = postData.DapAn;
                temp.GiaiThich = postData.GiaiThich;
                result.data.Add(temp);
            }
            return(result);
        }
Пример #2
0
        //xac dinh bai post chi co text
        public async Task <ListPostFB> GetListFeedTextOfGroup(string id = "1446400445645839")
        {
            int        numberSentences = 0;
            ListPostFB result          = new ListPostFB();

            //
            try
            {
                var    url        = "https://graph.facebook.com/v2.11/" + id + "/feed?limit=30&access_token=" + Token.Facebook;
                var    httpClient = new HttpClient();
                string json       = "";
                while (true)
                {
                    try
                    {
                        json = httpClient.GetStringAsync(url).Result;
                        break;
                    }
                    catch (Exception e)
                    {
                    }
                }
                var listPostFB = JsonConvert.DeserializeObject <ListPostFB>(json);
                foreach (var postFB in listPostFB.data)
                {
                    var postData = GetAll().Where(x => x.Id_Post == postFB.id).FirstOrDefault();
                    //ko kiem tra lại dữ liệu sau khi lưu vào database
                    if (postData != null)
                    {
                        if (postData.DapAn == null || postData.DapAn == "")
                        {
                            continue;
                        }
                        Model.Feeds.Datum temp = new Model.Feeds.Datum();
                        temp.id        = postData.Id_Post;
                        temp.imageURL  = postData.ImageUrl;
                        temp.message   = postData.Content;
                        temp.DapAn     = postData.DapAn;
                        temp.GiaiThich = postData.GiaiThich;
                        result.data.Add(temp);
                        numberSentences++;
                        if (numberSentences > 10)
                        {
                            break;
                        }
                        continue;
                    }


                    var imageOfPost = await GetImageByPost(postFB.id);

                    //Bài post phải là text
                    if (imageOfPost.full_picture == null)
                    {
                        postFB.DapAn = await DetectedAnswOfPost(postFB.id);

                        int countDapAn = postFB.DapAn.Count();
                        if (countDapAn == 0)
                        {
                        }
                        else
                        {
                            //Add to database
                            ToiecGroup item = new ToiecGroup();
                            item.Content   = postFB.message;
                            item.Id_Post   = postFB.id;
                            item.DapAn     = postFB.DapAn.Split('#').FirstOrDefault();
                            item.GiaiThich = postFB.DapAn.Split('#').LastOrDefault();
                            //
                            postFB.DapAn     = item.DapAn;
                            postFB.GiaiThich = item.GiaiThich;

                            //
                            Add(item);
                            Save();
                            //
                            result.data.Add(postFB);
                            numberSentences++;
                        }
                    }
                    //câu hỏi dạng hình ảnh
                    else
                    {
                        postFB.DapAn = await DetectedAnswOfPost(postFB.id);

                        int countDapAn = postFB.DapAn.Count();
                        if (imageOfPost.source == null || imageOfPost.source == "")
                        {
                            postFB.imageURL = imageOfPost.full_picture;
                        }
                        else
                        {
                            postFB.imageURL = imageOfPost.source;
                        }
                        if (countDapAn == 0)
                        {
                        }
                        else
                        {
                            //Add to database
                            ToiecGroup item = new ToiecGroup();
                            item.Content   = postFB.message;
                            item.ImageUrl  = postFB.imageURL;
                            item.Id_Post   = postFB.id;
                            item.DapAn     = postFB.DapAn.Split('#').FirstOrDefault();
                            item.GiaiThich = postFB.DapAn.Split('#').LastOrDefault();
                            Add(item);
                            Save();
                            //
                            result.data.Add(postFB);
                            numberSentences++;
                        }
                    }

                    dapAn[0] = 0;
                    dapAn[1] = 0;
                    dapAn[2] = 0;
                    dapAn[3] = 0;
                    if (numberSentences > 9)
                    {
                        break;
                    }
                }
            }
            catch (Exception e)
            {
            }
            return(result);
        }