Ejemplo n.º 1
0
        public PeopleSocials GetInstagramInfo(string code, string url)
        {
            string pathString = @"logs\Ins_" + code + ".html";
            string pathPeople = url;

            var client = new WebClient();

            client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36");
            client.Headers.Add("cache-control", "max-age=0");
            client.Headers.Add("upgrade-insecure-requests", "1");
            var text = client.DownloadString(pathPeople);
            var inx  = text.IndexOf("edge_followed_by");

            var result1 = text.Substring(inx, 50).Split('"');
            var number1 = int.Parse(Regex.Replace(result1[3], "[^0-9]", ""));
            var results = number1.ToString();

            File.WriteAllText(pathString.Replace("html", "txt"), results);

            File.WriteAllText(pathString, text);
            var peNew = new PeopleSocials();

            peNew.Follow = number1;
            return(peNew);
        }
        public async Task <IActionResult> DeleteSocialOfPeople([FromBody] PeopleSocials peopleSocials)
        {
            var isSignedIn = _signInManager.IsSignedIn(User);
            var message    = new MessageModel
            {
                IsSignedIn = isSignedIn
            };

            if (isSignedIn)
            {
                try
                {
                    peopleSocials = await _context.PeopleSocials.FindAsync(peopleSocials.Id);

                    _context.Entry(peopleSocials).State = EntityState.Deleted;
                    int value = await _context.SaveChangesAsync();

                    message.Succeeded = value > 0;
                    return(Ok(message));
                }
                catch (Exception ex)
                {
                    message.Message += " " + ex.Message;
                    return(BadRequest(message));
                }
            }
            else
            {
                message.Message += "you need login to excute this function";
                return(BadRequest(message));
            }
        }
        public long setTotal(PeopleSocials n)
        {
            long like   = n.Like ?? 0;
            long follow = n.Follow ?? 0;
            long view   = n.View ?? 0;
            long share  = n.Share ?? 0;

            return(like + share + follow + view);
        }
Ejemplo n.º 4
0
        public async Task <PeopleSocialsByDate> CrawlSocial(UserDbContext _context, PeopleSocials p)
        {
            Console.WriteLine("-- url: " + p.Url);
            var newItem = new PeopleSocialsByDate();
            var px      = GetInfo(DateTime.Now.Ticks.ToString(), p.Url);

            newItem.Like            = px.Like;
            newItem.Follow          = px.Follow;
            newItem.View            = px.View;
            newItem.Share           = px.Share;
            newItem.PeopleSocialsId = p.Id;
            return(newItem);
        }
Ejemplo n.º 5
0
        public PeopleSocials GetTwitterInfo(string code, string url)
        {
            string pathString = @"logs\tw_" + code + ".html";
            string pathPeople = url;

            var client = new WebClient();

            client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36");
            client.Headers.Add("cache-control", "max-age=0");
            client.Headers.Add("upgrade-insecure-requests", "1");
            var text = client.DownloadString(pathPeople);

            File.WriteAllText(pathString, text);
            var peNew = new PeopleSocials();

            return(peNew);
        }
        public async Task <IActionResult> GetAllSocialInfoByPeopleId([FromQuery] int peopleId)
        {
            var socials = await _context.PeopleSocials.Where(m => m.PeopleId == peopleId).Select(m => m.Id).ToListAsync();

            var socValues = await _context.PeopleSocialsByDates.Where(m => socials.Contains(m.PeopleSocialsId)).Select(m => new PeopleSocialsByDate
            {
                Id              = m.Id,
                Like            = m.Like,
                Share           = m.Share,
                View            = m.View,
                Follow          = m.Follow,
                CreatedDate     = m.CreatedDate,
                PeopleSocialsId = m.PeopleSocialsId
            }).OrderByDescending(m => m.CreatedDate).ToListAsync();

            List <PeopleSocials> results = new List <PeopleSocials>();

            for (var i = 0; i < socials.Count; i++)
            {
                var soc = new PeopleSocials
                {
                    Id = socials[i]
                };
                var values = new List <PeopleSocialsByDate>();
                for (var j = 0; j < socValues.Count; j++)
                {
                    if (socValues[j].PeopleSocialsId == socials[i])
                    {
                        values.Add(new PeopleSocialsByDate
                        {
                            Id          = socValues[j].Id,
                            Like        = socValues[j].Like,
                            Share       = socValues[j].Share,
                            View        = socValues[j].View,
                            Follow      = socValues[j].Follow,
                            CreatedDate = socValues[j].CreatedDate
                        });
                    }
                }
                soc.PeopleSocialsByDates = values;
                results.Add(soc);
            }
            return(Ok(results));
        }
        public async Task <IActionResult> SaveUpdatedSocial([FromBody] PeopleSocials social)
        {
            var isSignedIn = _signInManager.IsSignedIn(User);
            var message    = new MessageModel();

            message.IsSignedIn = isSignedIn;
            if (isSignedIn)
            {
                _context.Entry(social).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                message.Message = "Success!";
                return(Ok(message));
            }
            else
            {
                message.Message += "you need login to excute this function";
                return(BadRequest(message));
            }
        }
        public async Task <IActionResult> SaveSocialForPeople([FromBody] PeopleSocials psocial)
        {
            var isSignedIn = _signInManager.IsSignedIn(User);
            var message    = new MessageModel
            {
                IsSignedIn = isSignedIn
            };

            if (isSignedIn)
            {
                var item = await _context.PeopleSocials.FindAsync(psocial.Id);

                if (item != null)
                {
                    item.UpdatedDate           = DateTime.Now;
                    item.PeopleId              = psocial.PeopleId;
                    item.SocialId              = psocial.SocialId;
                    item.Share                 = psocial.Share;
                    item.Like                  = psocial.Like;
                    item.Follow                = psocial.Follow;
                    item.Index                 = psocial.Index;
                    item.View                  = psocial.View;
                    item.Url                   = psocial.Url;
                    _context.Entry(item).State = EntityState.Modified;
                }
                else
                {
                    psocial.CreatedDate = DateTime.Now;
                    _context.PeopleSocials.Add(psocial);
                }
                await _context.SaveChangesAsync();

                message.Message = "Success!";
                return(Ok(message));
            }
            else
            {
                message.Message += "you need login to excute this function";
                return(BadRequest(message));
            }
        }
        public async Task <IActionResult> GetDataFromFacebook([FromBody] PeopleSocials p)
        {
            var isSignedIn = _signInManager.IsSignedIn(User);
            var message    = new MessageModel
            {
                IsSignedIn = isSignedIn
            };
            InfoPeople info = new InfoPeople();

            if (isSignedIn)
            {
                try
                {
                    var item = await info.UpdateUser(_context, p);

                    if (item != null)
                    {
                        return(Ok(new
                        {
                            like = item.Like,
                            view = item.View,
                            share = item.Share,
                            follow = item.Follow
                        }));
                    }
                    message.Succeeded = false;
                    message.Message   = "Data or Url is invalid";
                    return(BadRequest(message));
                }
                catch (Exception ex)
                {
                    message.Message += ex.Message;
                    return(BadRequest(message));
                }
            }
            else
            {
                message.Message += "you need login to excute this function";
                return(BadRequest(message));
            }
        }
Ejemplo n.º 10
0
        public async Task <PeopleSocials> UpdateUser(UserDbContext _context, PeopleSocials p)
        {
            var px      = GetInfo(DateTime.Now.Ticks.ToString(), p.Url);
            var pupdate = await _context.PeopleSocials.FindAsync(p.Id);

            pupdate.Like   = px.Like;
            pupdate.Follow = px.Follow;
            pupdate.View   = px.View;
            pupdate.Share  = px.Share;
            _context.Entry(pupdate).State = EntityState.Modified;
            var num = await _context.SaveChangesAsync();

            if (num > 0)
            {
                return(pupdate);
            }
            else
            {
                return(null);
            }
        }