private static void fetchdata(Discovery itemdis)
        {
            MongoRepository mongoreppo = new MongoRepository("AdvanceSerachData");

            try
            {
                string youtubesearchurl = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=15&order=relevance&q=" + itemdis.SearchKeyword + "&key=AIzaSyBmQ1X1UBnKi3V78EkLuh7UHk5odrGfp5M";
                string response         = WebRequst(youtubesearchurl);
                var    Jdata            = Newtonsoft.Json.Linq.JObject.Parse(response);

                foreach (var item in Jdata["items"])
                {
                    Domain.Socioboard.Models.Mongo.AdvanceSerachData _AdvanceSerachData = new Domain.Socioboard.Models.Mongo.AdvanceSerachData();
                    _AdvanceSerachData.Id          = ObjectId.GenerateNewId();
                    _AdvanceSerachData.strId       = ObjectId.GenerateNewId().ToString();
                    _AdvanceSerachData.domainType  = "https://www.youtube.com/";
                    _AdvanceSerachData.postType    = Domain.Socioboard.Enum.AdvanceSearchpostType.video;
                    _AdvanceSerachData.networkType = Domain.Socioboard.Enum.NetworkType.youtube;
                    try
                    {
                        _AdvanceSerachData.userName = item["snippet"]["channelTitle"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.userName = "";
                    }
                    try
                    {
                        _AdvanceSerachData.postId = item["id"]["videoId"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.postId = "";
                    }
                    try
                    {
                        _AdvanceSerachData.title = item["snippet"]["title"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.title = "";
                    }
                    try
                    {
                        _AdvanceSerachData.videourl = "https://www.youtube.com/watch?v=" + _AdvanceSerachData.postId;
                        long    fbengagementCount = TwitterAdvanceSearch.fbShareCount(_AdvanceSerachData.videourl);
                        long    redditShare       = TwitterAdvanceSearch.redditShareCount(_AdvanceSerachData.videourl);
                        string  datacount         = TwitterAdvanceSearch.getdonreachdatafromUrl("https://free.donreach.com/shares?providers=facebook,twitter,google,pinterest,linkedin,reddit&url=" + _AdvanceSerachData.videourl);
                        JObject shareData         = JObject.Parse(datacount);
                        long    pinshare          = Convert.ToInt32(shareData["shares"]["pinterest"].ToString());
                        long    linshare          = Convert.ToInt32(shareData["shares"]["linkedin"].ToString());
                        long    gplusshare        = Convert.ToInt32(shareData["shares"]["google"].ToString());
                        long    twittershare      = Convert.ToInt32(shareData["shares"]["twitter"].ToString());
                        _AdvanceSerachData.postUrl           = _AdvanceSerachData.videourl;
                        _AdvanceSerachData.pinShareCount     = pinshare;
                        _AdvanceSerachData.gplusShareCount   = gplusshare;
                        _AdvanceSerachData.linShareCount     = linshare;
                        _AdvanceSerachData.twtShareCount     = twittershare;
                        _AdvanceSerachData.redditShareCount  = redditShare;
                        _AdvanceSerachData.fbengagementCount = fbengagementCount;
                        _AdvanceSerachData.totalShareCount   = Convert.ToInt64(pinshare + gplusshare + linshare + twittershare + redditShare + fbengagementCount);
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.videourl = "";
                    }
                    try
                    {
                        _AdvanceSerachData.postdescription = item["snippet"]["description"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.postdescription = "";
                    }
                    try
                    {
                        _AdvanceSerachData.postedTime = SBHelper.ConvertToUnixTimestamp((DateTime.Parse(item["snippet"]["publishedAt"].ToString())));
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.postedTime = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                    }
                    int count = mongoreppo.Counts <Domain.Socioboard.Models.Mongo.AdvanceSerachData>(t => t.postUrl == _AdvanceSerachData.postUrl);
                    if (count == 0)
                    {
                        mongoreppo.Add <Domain.Socioboard.Models.Mongo.AdvanceSerachData>(_AdvanceSerachData);
                    }
                    else
                    {
                        var update = Builders <Domain.Socioboard.Models.Mongo.AdvanceSerachData> .Update.Set(t => t.linShareCount, _AdvanceSerachData.linShareCount).Set(t => t.pinShareCount, _AdvanceSerachData.pinShareCount)
                                     .Set(t => t.redditShareCount, _AdvanceSerachData.redditShareCount)
                                     .Set(t => t.twtShareCount, _AdvanceSerachData.twtShareCount)
                                     .Set(t => t.gplusShareCount, _AdvanceSerachData.gplusShareCount)
                                     .Set(t => t.fbengagementCount, _AdvanceSerachData.fbengagementCount)
                                     .Set(t => t.totalShareCount, _AdvanceSerachData.totalShareCount);

                        mongoreppo.Update <Domain.Socioboard.Models.Mongo.AdvanceSerachData>(update, t => t.postUrl == _AdvanceSerachData.postUrl);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        private static void fetchdata(Discovery itemdis)
        {
            MongoRepository mongoreppo = new MongoRepository("AdvanceSerachData");

            try
            {
                string _dailymotionpostRestUrl = "https://api.dailymotion.com/videos/?search=" + itemdis.SearchKeyword + "&fields=id,title,created_time,url,description,owner.username, owner.screenname, owner.fullname,owner.url, owner.avatar_25_url, owner.avatar_60_url, owner.avatar_80_url, owner.avatar_120_url, owner.avatar_190_url, owner.avatar_240_url, owner.avatar_360_url, owner.avatar_480_url, owner.avatar_720_url";

                string response = WebRequst(_dailymotionpostRestUrl);

                var jdata = Newtonsoft.Json.Linq.JObject.Parse(response);

                foreach (var item in jdata["list"])
                {
                    Domain.Socioboard.Models.Mongo.AdvanceSerachData _AdvanceSerachData = new Domain.Socioboard.Models.Mongo.AdvanceSerachData();
                    _AdvanceSerachData.Id          = ObjectId.GenerateNewId();
                    _AdvanceSerachData.strId       = ObjectId.GenerateNewId().ToString();
                    _AdvanceSerachData.domainType  = "http://www.dailymotion.com/in";
                    _AdvanceSerachData.postType    = Domain.Socioboard.Enum.AdvanceSearchpostType.video;
                    _AdvanceSerachData.networkType = Domain.Socioboard.Enum.NetworkType.dailymotion;
                    try
                    {
                        _AdvanceSerachData.userName = item["owner.username"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.userName = "";
                    }
                    try
                    {
                        _AdvanceSerachData.postId = item["id"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.postId = "";
                    }
                    try
                    {
                        _AdvanceSerachData.title = item["title"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.title = "";
                    }
                    try
                    {
                        _AdvanceSerachData.videourl = item["url"].ToString();
                        long fbengagementCount = TwitterAdvanceSearch.fbShareCount(_AdvanceSerachData.videourl);
                        long redditShare       = TwitterAdvanceSearch.redditShareCount(_AdvanceSerachData.videourl);

                        //https://free.donreach.com/shares?providers=facebook,twitter,google,pinterest,linkedin,reddit&url=
                        //string datacount = TwitterAdvanceSearch.getdonreachdatafromUrl("https://api.donreach.com/shares?providers=facebook,google,twitter&url=" + _AdvanceSerachData.videourl);
                        //JObject shareData = JObject.Parse(datacount);
                        //long pinshare = Convert.ToInt32(shareData["shares"]["pinterest"].ToString());
                        //long linshare = Convert.ToInt32(shareData["shares"]["linkedin"].ToString());
                        //long gplusshare = Convert.ToInt32(shareData["shares"]["google"].ToString());
                        //long twittershare = Convert.ToInt32(shareData["shares"]["twitter"].ToString());

                        long pinshare     = TwitterAdvanceSearch.pinShareCount(_AdvanceSerachData.videourl);
                        long linshare     = TwitterAdvanceSearch.linShareCount(_AdvanceSerachData.videourl);
                        long twittershare = 0;
                        long gplusshare   = TwitterAdvanceSearch.GetPlusOnes(_AdvanceSerachData.videourl);

                        _AdvanceSerachData.postUrl           = _AdvanceSerachData.videourl;
                        _AdvanceSerachData.pinShareCount     = pinshare;
                        _AdvanceSerachData.gplusShareCount   = gplusshare;
                        _AdvanceSerachData.linShareCount     = linshare;
                        _AdvanceSerachData.twtShareCount     = twittershare;
                        _AdvanceSerachData.redditShareCount  = redditShare;
                        _AdvanceSerachData.fbengagementCount = fbengagementCount;
                        _AdvanceSerachData.totalShareCount   = Convert.ToInt64(pinshare + gplusshare + linshare + twittershare + redditShare + fbengagementCount);
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.videourl = "";
                    }
                    try
                    {
                        _AdvanceSerachData.postdescription = item["description"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.postdescription = "";
                    }
                    try
                    {
                        _AdvanceSerachData.postedTime = double.Parse(item["created_time"].ToString());
                    }
                    catch (Exception ex)
                    {
                        _AdvanceSerachData.postedTime = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                    }
                    int count = mongoreppo.Counts <Domain.Socioboard.Models.Mongo.AdvanceSerachData>(t => t.postUrl == _AdvanceSerachData.postUrl);
                    if (count == 0)
                    {
                        mongoreppo.Add <Domain.Socioboard.Models.Mongo.AdvanceSerachData>(_AdvanceSerachData);
                    }
                    else
                    {
                        var update = Builders <Domain.Socioboard.Models.Mongo.AdvanceSerachData> .Update.Set(t => t.linShareCount, _AdvanceSerachData.linShareCount).Set(t => t.pinShareCount, _AdvanceSerachData.pinShareCount)
                                     .Set(t => t.redditShareCount, _AdvanceSerachData.redditShareCount)
                                     .Set(t => t.twtShareCount, _AdvanceSerachData.twtShareCount)
                                     .Set(t => t.gplusShareCount, _AdvanceSerachData.gplusShareCount)
                                     .Set(t => t.fbengagementCount, _AdvanceSerachData.fbengagementCount)
                                     .Set(t => t.totalShareCount, _AdvanceSerachData.totalShareCount);

                        mongoreppo.Update <Domain.Socioboard.Models.Mongo.AdvanceSerachData>(update, t => t.postUrl == _AdvanceSerachData.postUrl);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        public static void CreateTodayReports(string profileId, long userId, Helper.Cache _redisCache, Helper.AppSettings settings)
        {
            List <MongoMessageModel>   lstTwitterMessages       = TwitterReportsRepository.GetTodayMessages(profileId, userId, _redisCache, settings);
            List <MongoDirectMessages> lstTwitterDirectMessages = TwitterReportsRepository.GetTodayDirectMessages(profileId, userId, _redisCache, settings);
            MongoRepository            mongorepo = new MongoRepository("MongoTwitterDailyReports", settings);

            MongoTwitterDailyReports todayReports = new MongoTwitterDailyReports();

            todayReports.mentions     = lstTwitterMessages.Count(t => t.type == Domain.Socioboard.Enum.MessageType.TwitterMention);
            todayReports.newFollowers = lstTwitterMessages.Count(t => t.type == Domain.Socioboard.Enum.MessageType.TwitterFollower);
            todayReports.retweets     = lstTwitterMessages.Count(t => t.type == Domain.Socioboard.Enum.MessageType.TwitterRetweet);
            todayReports.timeStamp    = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
            //todayReports.newFollowing = lstTwitterMessages.Count(t=>t.type == Domain.Socioboard.Enum.MessageType.)
            todayReports.directMessagesReceived = lstTwitterDirectMessages.Count(t => t.type == Domain.Socioboard.Enum.MessageType.TwitterDirectMessageReceived);
            todayReports.directMessagesSent     = lstTwitterDirectMessages.Count(t => t.type == Domain.Socioboard.Enum.MessageType.TwitterDirectMessageSent);
            todayReports.profileId = profileId;
            todayReports.id        = ObjectId.GenerateNewId();
            DateTime dayStart = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 0, 0, 0, DateTimeKind.Utc);
            DateTime dayEnd   = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 59, DateTimeKind.Utc);
            var      result   = mongorepo.Find <MongoTwitterDailyReports>(t => (t.timeStamp > SBHelper.ConvertToUnixTimestamp(dayStart)) && (t.timeStamp < SBHelper.ConvertToUnixTimestamp(dayEnd)));
            var      task     = Task.Run(async() =>
            {
                return(await result);
            });
            IList <MongoTwitterDailyReports> lstDailyReports = task.Result;

            if (lstDailyReports != null && lstDailyReports.Count() > 0)
            {
                lstDailyReports.First().mentions               = todayReports.mentions;
                lstDailyReports.First().newFollowers           = todayReports.newFollowers;
                lstDailyReports.First().newFollowing           = todayReports.newFollowing;
                lstDailyReports.First().profileId              = profileId;
                lstDailyReports.First().timeStamp              = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                lstDailyReports.First().directMessagesSent     = todayReports.directMessagesSent;
                lstDailyReports.First().directMessagesReceived = todayReports.directMessagesReceived;
                mongorepo.UpdateReplace(lstDailyReports.First(), t => t.id == lstDailyReports.First().id);
            }
            else
            {
                mongorepo.Add <MongoTwitterDailyReports>(todayReports);
            }
        }
        public static List <MongoMessageModel> GetInstagramFollwerFollowing(string profileId, int daysCount)
        {
            var mongoRepo = new MongoRepository("MongoMessageModel");
            var dayStart  = new DateTime(DateTime.UtcNow.AddDays(-(daysCount)).Year, DateTime.UtcNow.AddDays(-(daysCount)).Month, DateTime.UtcNow.AddDays(-(daysCount)).Day, 0, 0, 0, DateTimeKind.Utc);
            var dayEnd    = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 59, DateTimeKind.Utc);
            var ret       = mongoRepo.Find <MongoMessageModel>(t => t.profileId == profileId && t.messageTimeStamp <= SBHelper.ConvertToUnixTimestamp(dayEnd) && t.messageTimeStamp >= SBHelper.ConvertToUnixTimestamp(dayStart) && (t.type == Domain.Socioboard.Enum.MessageType.InstagramFollower || t.type == Domain.Socioboard.Enum.MessageType.InstagramFollowing));
            var task      = Task.Run(async() => {
                return(await ret);
            });
            var lstInstagramFollowerFollowing = task.Result.ToList();

            return(lstInstagramFollowerFollowing);
        }
Example #5
0
        // for article and blogs;
        public static List <ArticlesAndBlogs> GetArticlesAndBlogsReports(string HostName, int dayCount, Helper.Cache _redisCache, Helper.AppSettings settings)
        {
            MongoRepository ArticlesAndBlogsRepo = new MongoRepository("ArticlesAndBlogs", settings);
            DateTime        dayStart             = new DateTime(DateTime.UtcNow.AddDays(-90).Year, DateTime.UtcNow.AddDays(-90).Month, DateTime.UtcNow.AddDays(-90).Day, 0, 0, 0, DateTimeKind.Utc);
            DateTime        dayEnd = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 59, DateTimeKind.Utc);
            var             result = ArticlesAndBlogsRepo.Find <ArticlesAndBlogs>(t => t.HostName.Equals(HostName) && (t.Created_Time > SBHelper.ConvertToUnixTimestamp(dayStart)) && (t.Created_Time < SBHelper.ConvertToUnixTimestamp(dayEnd)));
            var             task   = Task.Run(async() =>
            {
                return(await result);
            });
            IList <ArticlesAndBlogs> lstArticlesAndBlogs = task.Result;

            return(lstArticlesAndBlogs.ToList());
        }
        public static void CreateReport(string ProfileId, bool is90daysupdated)
        {
            int day = 1;

            if (!is90daysupdated)
            {
                day = 90;
            }
            for (int i = 0; i < day; i++)
            {
                DateTime date = DateTime.UtcNow.AddDays(-1 * i);
                Domain.Socioboard.Models.Mongo.Fbpublicpagedailyreports _Fbpublicpagedailyreports = new Domain.Socioboard.Models.Mongo.Fbpublicpagedailyreports();
                DateTime        dayStart       = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0, DateTimeKind.Utc);
                DateTime        dayEnd         = new DateTime(date.Year, date.Month, date.Day, 23, 59, 59, DateTimeKind.Utc);
                MongoRepository mongoreppo     = new MongoRepository("FbPublicPagePost");
                MongoRepository mongoreppopage = new MongoRepository("Fbpublicpagedailyreports");
                var             ret            = mongoreppo.Find <Domain.Socioboard.Models.Mongo.FbPublicPagePost>(t => t.PageId == ProfileId && t.PostDate <= SBHelper.ConvertToUnixTimestamp(dayEnd) && t.PostDate >= SBHelper.ConvertToUnixTimestamp(dayStart));
                var             task           = Task.Run(async() =>
                {
                    return(await ret);
                });
                IList <Domain.Socioboard.Models.Mongo.FbPublicPagePost> lstFbPublicPagePost = task.Result.ToList();
                _Fbpublicpagedailyreports.id            = ObjectId.GenerateNewId();
                _Fbpublicpagedailyreports.date          = SBHelper.ConvertToUnixTimestamp(date);
                _Fbpublicpagedailyreports.likescount    = lstFbPublicPagePost.ToList().Sum(t => t.Likes);
                _Fbpublicpagedailyreports.pageid        = ProfileId;
                _Fbpublicpagedailyreports.pommentscount = lstFbPublicPagePost.ToList().Sum(t => t.Comments);
                _Fbpublicpagedailyreports.postscount    = lstFbPublicPagePost.ToList().Count();
                _Fbpublicpagedailyreports.sharescount   = lstFbPublicPagePost.ToList().Sum(t => t.Shares);

                var retfb  = mongoreppopage.Find <Domain.Socioboard.Models.Mongo.Fbpublicpagedailyreports>(t => t.date >= _Fbpublicpagedailyreports.date && t.pageid == _Fbpublicpagedailyreports.pageid);
                var taskfb = Task.Run(async() => {
                    return(await retfb);
                });
                IList <Domain.Socioboard.Models.Mongo.Fbpublicpagedailyreports> lstfbpublicreport = taskfb.Result.ToList();
                if (lstfbpublicreport.ToList().Count < 1)
                {
                    mongoreppopage.Add <Domain.Socioboard.Models.Mongo.Fbpublicpagedailyreports>(_Fbpublicpagedailyreports);
                }
            }
        }
        public static List <InstagramComment> GetInstagramPostComments(string profileId, int daysCount)
        {
            //MongoRepository instagarmCommentRepo = new MongoRepository("InstagramComment");
            //DateTime dayStart = new DateTime(DateTime.UtcNow.AddDays(-(daysCount)).Year, DateTime.UtcNow.AddDays(-(daysCount)).Month, DateTime.UtcNow.AddDays(-(daysCount)).Day, 0, 0, 0, DateTimeKind.Utc);
            //DateTime dayEnd = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 59, DateTimeKind.Utc);
            //var ret = instagarmCommentRepo.Find<Domain.Socioboard.Models.Mongo.InstagramComment>(t => t.InstagramId == profileId && t.CommentDate <= SBHelper.ConvertToUnixTimestamp(dayEnd) && t.CommentDate >= SBHelper.ConvertToUnixTimestamp(dayStart));
            //var task = Task.Run(async () =>
            //{
            //    return await ret;
            //});
            //IList<Domain.Socioboard.Models.Mongo.InstagramComment> lstInstagramPostComments = task.Result.ToList();


            var lstInstagramPostComments = new List <InstagramComment>();
            var instagramFeedRepo        = new MongoRepository("InstagramFeed");
            var dayStart = new DateTime(DateTime.UtcNow.AddDays(-(daysCount)).Year, DateTime.UtcNow.AddDays(-(daysCount)).Month, DateTime.UtcNow.AddDays(-(daysCount)).Day, 0, 0, 0, DateTimeKind.Utc);
            var dayEnd   = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 59, DateTimeKind.Utc);
            var ret      = instagramFeedRepo.Find <InstagramFeed>(t => t.InstagramId == profileId && t.FeedDate <= SBHelper.ConvertToUnixTimestamp(dayEnd) && t.FeedDate >= SBHelper.ConvertToUnixTimestamp(dayStart) && t.Type == "image");
            var task     = Task.Run(async() =>
            {
                return(await ret);
            });
            var lstInstagramFeed = task.Result.GroupBy(x => x.FeedId).Select(g => g.First()).ToList();

            foreach (var instagramFeedItem in lstInstagramFeed.ToList())
            {
                lstInstagramPostComments.AddRange(instagramFeedItem._InstagramComment);
            }
            return(lstInstagramPostComments.ToList());
        }
Example #8
0
 public static List <MongoMessageModel> GetTwitterMessages(string profileId, DateTime date)
 {
     try
     {
         MongoRepository mongorepo = new MongoRepository("MongoMessageModel");
         DateTime        dayStart  = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0, DateTimeKind.Utc);
         DateTime        dayEnd    = new DateTime(date.Year, date.Month, date.Day, 23, 59, 59, DateTimeKind.Utc);
         var             result    = mongorepo.Find <MongoMessageModel>(t => (t.profileId.Equals(profileId) && t.messageTimeStamp > SBHelper.ConvertToUnixTimestamp(dayStart)) && (t.messageTimeStamp < SBHelper.ConvertToUnixTimestamp(dayEnd)));
         var             task      = Task.Run(async() =>
         {
             return(await result);
         });
         IList <Domain.Socioboard.Models.Mongo.MongoMessageModel> lstTwtMessages = task.Result;
         return(lstTwtMessages.ToList());
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
        public static List <MongoTwitterDirectMessages> GetTwitterDirectMessages(string profileId, DateTime date)
        {
            MongoRepository mongorepo = new MongoRepository("MongoTwitterDirectMessages");
            DateTime        dayStart  = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0, DateTimeKind.Utc);
            DateTime        dayEnd    = new DateTime(date.Year, date.Month, date.Day, 23, 59, 59, DateTimeKind.Utc);
            var             result    = mongorepo.Find <MongoTwitterDirectMessages>(t => (t.recipientId.Equals(profileId) || t.senderId.Equals(profileId)) && (t.timeStamp > SBHelper.ConvertToUnixTimestamp(dayStart)) && (t.timeStamp < SBHelper.ConvertToUnixTimestamp(dayEnd)));
            var             task      = Task.Run(async() =>
            {
                return(await result);
            });
            IList <Domain.Socioboard.Models.Mongo.MongoTwitterDirectMessages> lstTwtMessages = task.Result;

            return(lstTwtMessages.ToList());
        }
        private static string GetInstagramPostComments(string profile_id, string access_token)
        {
            var InstagramPostCommentsRepo = new MongoRepository("InstagramPostComments");
            var code_status = "false";
            var insert      = new InstagramPostComments();
            var post_data   = new JObject();
            var url         = "https://api.instagram.com/v1/users/" + profile_id + "/media/recent?access_token=" + access_token + "&count=100";

            try
            {
                post_data = JObject.Parse(ApiInstagramHttp(url));

                var items = post_data.SelectToken("data");

                if (items != null)
                {
                    apiHitsCount++;
                    foreach (var item in items)
                    {
                        Guid     Id                = Guid.NewGuid();
                        string   feed_id           = item.SelectToken("id")?.ToString();
                        string   feed_type         = item.SelectToken("type")?.ToString();
                        string   created_time_feed = item.SelectToken("created_time")?.ToString() ?? "0";
                        DateTime create_time_feed  = ToDateTime(DateTime.Now, long.Parse(created_time_feed));
                        if (create_time_feed.Date >= DateTime.Now.AddDays(-90).Date)
                        {
                            var comments = item.SelectToken("comments.data");

                            foreach (var comment in comments)
                            {
                                var      created_time      = comment.SelectToken("created_time")?.ToString() ?? "0";
                                DateTime create_time       = ToDateTime(DateTime.Now, long.Parse(created_time));
                                var      text              = comment.SelectToken("text")?.ToString();
                                var      commented_by_id   = comment.SelectToken("from.id")?.ToString();
                                var      commented_by_name = comment.SelectToken("from.username")?.ToString();
                                var      comment_id        = comment.SelectToken("id")?.ToString();

                                insert.Profile_Id        = profile_id;
                                insert.Feed_Id           = feed_id;
                                insert.Commented_By_Id   = commented_by_id;
                                insert.Commented_By_Name = commented_by_name;
                                insert.Created_Time      = SBHelper.ConvertToUnixTimestamp(Convert.ToDateTime(created_time));
                                insert.Comment_Id        = comment_id;
                                insert.Comment           = text;
                                insert.Feed_Type         = feed_type;
                                var ret  = InstagramPostCommentsRepo.Find <InstagramPostComments>(t => t.Feed_Id.Equals(insert.Feed_Id));
                                var task = Task.Run(async() =>
                                {
                                    return(await ret);
                                });
                                var count = task.Result.Count;

                                if (count < 1)
                                {
                                    InstagramPostCommentsRepo.Add(insert);
                                }
                                code_status = "true";
                            }
                        }
                    }
                }
                else
                {
                    apiHitsCount = MaxapiHitsCount;
                }
            }
            catch (Exception ex)
            {
            }



            return(code_status);
        }
        private static void GetInstagramFollower(string profile_id, string access_token)
        {
            var objMessageModel = new MongoMessageModel();
            var post_data       = new JObject();
            var next_post_data  = new JObject();
            var url             = "https://api.instagram.com/v1/users/" + profile_id + "/followed-by?access_token=" + access_token + "&cout=500";

            try
            {
                post_data = JObject.Parse(ApiInstagramHttp(url));

                var items    = post_data.SelectToken("data");
                var link     = post_data.SelectToken("pagination");
                var nextpage = link.SelectToken("next_url")?.ToString();
                foreach (var item in items)
                {
                    try
                    {
                        //Guid Id = Guid.NewGuid();
                        var user_name   = item.SelectToken("username")?.ToString();
                        var id          = item.SelectToken("id")?.ToString();
                        var full_name   = item.SelectToken("full_name")?.ToString();
                        var image_url   = item.SelectToken("profile_picture")?.ToString();
                        var CreatedTime = DateTime.UtcNow;
                        objMessageModel.id               = ObjectId.GenerateNewId();
                        objMessageModel.profileId        = profile_id;
                        objMessageModel.fromId           = id;
                        objMessageModel.fromName         = user_name;
                        objMessageModel.messageId        = Generatetxnid();
                        objMessageModel.RecipientId      = profile_id;
                        objMessageModel.RecipientName    = "";
                        objMessageModel.fromProfileUrl   = image_url;
                        objMessageModel.type             = Domain.Socioboard.Enum.MessageType.InstagramFollower;
                        objMessageModel.FollowerCount    = 0;
                        objMessageModel.FollowingCount   = 0;
                        objMessageModel.readStatus       = 1;
                        objMessageModel.messageTimeStamp = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                        var mongorepo = new MongoRepository("MongoMessageModel");
                        var ret       = mongorepo.Find <MongoMessageModel>(t => t.RecipientId == objMessageModel.RecipientId && t.fromId == objMessageModel.fromId && t.type == Domain.Socioboard.Enum.MessageType.InstagramFollower);
                        var task      = Task.Run(async() =>
                        {
                            return(await ret);
                        });
                        if (task.Result != null)
                        {
                            var count = task.Result.Count;
                            if (count < 1)
                            {
                                mongorepo.Add(objMessageModel);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                do
                {
                    if (nextpage != null)
                    {
                        try
                        {
                            next_post_data = JObject.Parse(ApiInstagramHttp(nextpage));
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    var items1 = next_post_data.SelectToken("data");

                    foreach (var item in items1)
                    {
                        try
                        {
                            //Guid Id = Guid.NewGuid();
                            var user_name   = item.SelectToken("username")?.ToString();
                            var id          = item.SelectToken("id")?.ToString();
                            var full_name   = item.SelectToken("full_name")?.ToString();
                            var image_url   = item.SelectToken("profile_picture")?.ToString();
                            var CreatedTime = DateTime.UtcNow;
                            objMessageModel.id               = ObjectId.GenerateNewId();
                            objMessageModel.profileId        = profile_id;
                            objMessageModel.fromId           = id;
                            objMessageModel.fromName         = user_name;
                            objMessageModel.messageId        = Generatetxnid();
                            objMessageModel.RecipientId      = profile_id;
                            objMessageModel.RecipientName    = "";
                            objMessageModel.fromProfileUrl   = image_url;
                            objMessageModel.type             = Domain.Socioboard.Enum.MessageType.InstagramFollower;
                            objMessageModel.FollowerCount    = 0;
                            objMessageModel.FollowingCount   = 0;
                            objMessageModel.readStatus       = 1;
                            objMessageModel.messageTimeStamp = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                            var mongorepo = new MongoRepository("MongoMessageModel");
                            var ret       = mongorepo.Find <MongoMessageModel>(t => t.RecipientId == objMessageModel.RecipientId && t.fromId == objMessageModel.fromId && t.type == Domain.Socioboard.Enum.MessageType.InstagramFollower);
                            var task      = Task.Run(async() =>
                            {
                                return(await ret);
                            });
                            if (task.Result != null)
                            {
                                var count = task.Result.Count;
                                if (count < 1)
                                {
                                    mongorepo.Add(objMessageModel);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    link     = next_post_data.SelectToken("pagination");
                    nextpage = link.SelectToken("next_url")?.ToString();
                }while (next_post_data != null);
            }
            catch (Exception ex)
            {
            }
        }
        private static string GetParseInstagramPostLikes(string profile_id, string access_token)
        {
            var     InstagramPostLikesRepo = new MongoRepository("InstagramPostLikes");
            var     InstagramSelfFeedRepo  = new MongoRepository("InstagramSelfFeed");
            string  code_status            = "false";
            var     insert    = new InstagramPostLikes();
            JObject post_data = new JObject();
            string  url       = "https://api.instagram.com/v1/users/" + profile_id + "/media/recent?access_token=" + access_token + "&count=30";

            try
            {
                post_data = JObject.Parse(ApiInstagramHttp(url));
            }
            catch (Exception ex)
            {
            }
            try
            {
                var items = post_data["data"];
                if (items != null)
                {
                    apiHitsCount++;
                    foreach (var item in items)
                    {
                        string post_url  = string.Empty;
                        string feed_url  = string.Empty;
                        string user_name = string.Empty;

                        string   feed_id           = item.SelectToken("id")?.ToString();
                        string   feed_type         = item.SelectToken("type")?.ToString();
                        string   created_time_feed = item.SelectToken("created_time")?.ToString();
                        DateTime create_time_feed  = ToDateTime(DateTime.Now, long.Parse(created_time_feed ?? "0"));

                        var send_data = new InstagramSelfFeed();

                        try
                        {
                            post_url  = feed_type == "video" ? item.SelectToken("videos.standard_resolution.url")?.ToString() : item.SelectToken("images.standard_resolution.url")?.ToString();
                            feed_url  = item.SelectToken("link")?.ToString();
                            user_name = item.SelectToken("user.username")?.ToString();


                            send_data.User_name    = user_name;
                            send_data.ProfileId    = profile_id;
                            send_data.FeedId       = feed_id;
                            send_data.Accesstoken  = access_token;
                            send_data.Post_url     = post_url;
                            send_data.Link         = feed_url;
                            send_data.Type         = feed_type;
                            send_data.Created_Time = created_time_feed;
                            var ret  = InstagramSelfFeedRepo.Find <InstagramSelfFeed>(t => t.FeedId.Equals(send_data.FeedId));
                            var task = Task.Run(async() =>
                            {
                                return(await ret);
                            });
                            int count = task.Result.Count;

                            if (count < 1)
                            {
                                InstagramSelfFeedRepo.Add(send_data);
                            }
                        }
                        catch (Exception ex)
                        {
                        }


                        try
                        {
                            //https://api.instagram.com/v1/media/{media-id}/likes?access_token=ACCESS-TOKEN

                            string like_url = "https://api.instagram.com/v1/media/" + feed_id + "/likes?access_token=" + access_token + "&count=30";
                            post_data = JObject.Parse(ApiInstagramHttp(like_url));

                            var likes_items = post_data["data"];
                            if (likes_items != null)
                            {
                                apiHitsCount++;
                                foreach (var itemLike in likes_items)
                                {
                                    var likes = itemLike.SelectToken("data");
                                    //dynamic likes = item1["likes"]["data"];
                                    if (itemLike != null)
                                    {
                                        apiHitsCount++;
                                        //foreach (var like in likes)
                                        //{
                                        try
                                        {
                                            string liked_by_id   = itemLike.SelectToken("id")?.ToString();
                                            string liked_by_name = itemLike.SelectToken("username")?.ToString();
                                            insert.Profile_Id    = profile_id;
                                            insert.Feed_Id       = feed_id;
                                            insert.Liked_By_Id   = liked_by_id;
                                            insert.Liked_By_Name = liked_by_name;
                                            insert.Feed_Type     = feed_type;
                                            insert.Created_Date  = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                                            insert.Status        = 1;
                                            var ret = InstagramPostLikesRepo.Find <InstagramPostLikes>(t => t.Liked_By_Id.Equals(insert.Liked_By_Id));

                                            var task = Task.Run(async() =>
                                            {
                                                return(await ret);
                                            });
                                            int count = task.Result.Count;

                                            if (count < 1)
                                            {
                                                InstagramPostLikesRepo.Add(insert);
                                            }
                                            code_status = "true";
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                    }
                                }
                            }
                            //dynamic likes = item["likes"]["data"];

                            else
                            {
                                apiHitsCount = MaxapiHitsCount;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
                else
                {
                    apiHitsCount = MaxapiHitsCount;
                }
            }

            catch (Exception ex)
            {
                apiHitsCount = MaxapiHitsCount;
                Console.WriteLine(ex.Message);
            }

            return(code_status);
        }
Example #13
0
        public static List <MongoMessageModel> GetTwitterMessages(string profileId, DateTime start, DateTime end)
        {
            MongoRepository mongorepo = new MongoRepository("MongoTwitterMessage");
            DateTime        dayStart  = new DateTime(start.Year, start.Month, start.Day, 0, 0, 0, DateTimeKind.Utc);
            DateTime        dayEnd    = new DateTime(end.Year, end.Month, end.Day, 23, 59, 59, DateTimeKind.Utc);
            var             result    = mongorepo.Find <MongoMessageModel>(t => (t.profileId.Equals(profileId) && t.messageTimeStamp > SBHelper.ConvertToUnixTimestamp(dayEnd)) && (t.messageTimeStamp < SBHelper.ConvertToUnixTimestamp(dayStart)));
            var             task      = Task.Run(async() =>
            {
                return(await result);
            });
            IList <Domain.Socioboard.Models.Mongo.MongoMessageModel> lstTwtMessages = task.Result;

            return(lstTwtMessages.ToList());
        }
Example #14
0
        public static string gettwittersexdivision(long groupId, DateTime start, DateTime end)
        {
            string             gettwittersexdivision = string.Empty;
            long               malecount             = 0;
            long               femalecount           = 0;
            string             firstname             = string.Empty;
            DateTime           dayStart  = new DateTime(start.Year, start.Month, start.Day, 0, 0, 0, DateTimeKind.Utc);
            DateTime           dayEnd    = new DateTime(end.Year, end.Month, end.Day, 23, 59, 59, DateTimeKind.Utc);
            MongoRepository    mongorepo = new MongoRepository("MongoTwitterMessage");
            DatabaseRepository dbr       = new DatabaseRepository();
            List <Domain.Socioboard.Models.Groupprofiles> lstgrpProfiles = dbr.Find <Domain.Socioboard.Models.Groupprofiles>(t => t.groupId == groupId && t.profileType == Domain.Socioboard.Enum.SocialProfileType.Twitter).ToList();

            string[] lstStr = lstgrpProfiles.Select(t => t.profileId).ToArray();
            var      ret    = mongorepo.Find <Domain.Socioboard.Models.Mongo.MongoMessageModel>(t => lstStr.Contains(t.profileId) && t.type == Domain.Socioboard.Enum.MessageType.TwitterFollower && t.messageTimeStamp <= SBHelper.ConvertToUnixTimestamp(dayEnd) && t.messageTimeStamp >= SBHelper.ConvertToUnixTimestamp(dayStart) && t.readStatus == 0);
            var      task   = Task.Run(async() =>
            {
                return(await ret);
            });
            long totalcount = task.Result.Count;

            if (totalcount > 0)
            {
                foreach (Domain.Socioboard.Models.Mongo.MongoMessageModel twtfollowername in task.Result.ToList())
                {
                    if (twtfollowername.fromName.Contains(" "))
                    {
                        firstname = twtfollowername.fromName.Split(' ')[0];
                    }
                    else
                    {
                        firstname = twtfollowername.fromName;
                    }

                    Domain.Socioboard.Models.TwitterNameTable _TwitterNameTable = dbr.Single <Domain.Socioboard.Models.TwitterNameTable>(t => t.Name == firstname);
                    if (_TwitterNameTable != null)
                    {
                        if (_TwitterNameTable.Gender == 1)
                        {
                            malecount++;
                        }
                    }
                    else
                    {
                        int    length   = (firstname.Length) / 2;
                        string sub_name = firstname.Substring(0, length);
                        List <Domain.Socioboard.Models.TwitterNameTable> root_names = dbr.Find <Domain.Socioboard.Models.TwitterNameTable>(x => x.Name.Contains(sub_name)).ToList();
                        int returndata = cosine_similarity(root_names, firstname);
                        if (returndata == 1)
                        {
                            malecount++;
                        }
                    }
                }
            }
            femalecount = 100 - malecount;
            return(malecount.ToString() + "," + femalecount.ToString());;
        }
Example #15
0
        public static void GetYoutubeSearchData(string Url)
        {
            MongoRepository ArticlesAndBlogsRepo = new MongoRepository("ArticlesAndBlogs");

            try
            {
                string youtubesearchurl = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=15&order=relevance&q=" + Url + "&key=AIzaSyBmQ1X1UBnKi3V78EkLuh7UHk5odrGfp5M";
                string response         = WebRequst(youtubesearchurl);
                var    Jdata            = Newtonsoft.Json.Linq.JObject.Parse(response);

                foreach (var item in Jdata["items"])
                {
                    Domain.Socioboard.Models.Mongo.ArticlesAndBlogs _ArticlesAndBlogs = new Domain.Socioboard.Models.Mongo.ArticlesAndBlogs();
                    _ArticlesAndBlogs.Id       = ObjectId.GenerateNewId();
                    _ArticlesAndBlogs.Type     = Domain.Socioboard.Enum.ArticlesAndBlogsTypes.youtube;
                    _ArticlesAndBlogs.HostName = Url;

                    try
                    {
                        _ArticlesAndBlogs.VideoId = item["id"]["videoId"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _ArticlesAndBlogs.VideoId = "";
                    }

                    if (!string.IsNullOrEmpty(_ArticlesAndBlogs.VideoId))
                    {
                        try
                        {
                            _ArticlesAndBlogs.VideoUrl = "https://www.youtube.com/watch?v=" + _ArticlesAndBlogs.VideoId;
                        }
                        catch (Exception ex)
                        {
                            _ArticlesAndBlogs.VideoUrl = "";
                        }
                        _ArticlesAndBlogs.Url = Url;
                        try
                        {
                            _ArticlesAndBlogs.Title = item["snippet"]["title"].ToString();
                        }
                        catch (Exception ex)
                        {
                            _ArticlesAndBlogs.Title = "";
                        }
                        try
                        {
                            _ArticlesAndBlogs.Description = item["snippet"]["description"].ToString();
                        }
                        catch (Exception ex)
                        {
                            _ArticlesAndBlogs.Description = "";
                        }
                        try
                        {
                            _ArticlesAndBlogs.Created_Time = SBHelper.ConvertToUnixTimestamp((DateTime.Parse(item["snippet"]["publishedAt"].ToString())));
                        }
                        catch (Exception ex)
                        {
                            _ArticlesAndBlogs.Created_Time = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                        }

                        var ret  = ArticlesAndBlogsRepo.Find <Domain.Socioboard.Models.Mongo.ArticlesAndBlogs>(t => t.VideoId.Equals(_ArticlesAndBlogs.VideoId) && t.Type.Equals(_ArticlesAndBlogs.Type));
                        var task = Task.Run(async() =>
                        {
                            return(await ret);
                        });
                        int count = task.Result.Count;
                        if (count < 1)
                        {
                            ArticlesAndBlogsRepo.Add(_ArticlesAndBlogs);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        public static void CreateReports(string profileId, DateTime date)
        {
            List <MongoTwitterMessage>        lstTwitterMessages         = TwitterReports.GetTwitterMessages(profileId, date);
            List <MongoTwitterMessage>        lstreceived                = lstTwitterMessages.Where(x => x.fromId.Contains(profileId)).ToList();
            List <MongoTwitterDirectMessages> lstTwitterDirectMessages   = TwitterReports.GetTwitterDirectMessages(profileId, date);
            List <Domain.Socioboard.Models.ScheduledMessage> lstschedule = GetScheduledMessage(profileId, date);
            MongoRepository mongorepo = new MongoRepository("MongoTwitterDailyReports");

            MongoTwitterDailyReports todayReports = new MongoTwitterDailyReports();

            todayReports.mentions     = lstTwitterMessages.Count(t => t.type == Domain.Socioboard.Enum.TwitterMessageType.TwitterMention);
            todayReports.newFollowers = lstTwitterMessages.Count(t => t.type == Domain.Socioboard.Enum.TwitterMessageType.TwitterFollower);
            todayReports.timeStamp    = SBHelper.ConvertToUnixTimestamp(date);
            todayReports.retweets     = lstTwitterMessages.Count(t => t.type == Domain.Socioboard.Enum.TwitterMessageType.TwitterRetweet);
            //todayReports.newFollowing = lstTwitterMessages.Count(t=>t.type == Domain.Socioboard.Enum.TwitterMessageType.)
            todayReports.directMessagesReceived = lstTwitterDirectMessages.Count(t => t.type == Domain.Socioboard.Enum.TwitterMessageType.TwitterDirectMessageReceived);
            todayReports.directMessagesSent     = lstTwitterDirectMessages.Count(t => t.type == Domain.Socioboard.Enum.TwitterMessageType.TwitterDirectMessageSent);
            todayReports.profileId        = profileId;
            todayReports.id               = ObjectId.GenerateNewId();
            todayReports.messagesReceived = lstreceived.Count() + lstTwitterDirectMessages.Count(t => t.type == Domain.Socioboard.Enum.TwitterMessageType.TwitterDirectMessageReceived);
            todayReports.messagesSent     = lstschedule.Count();
            DateTime dayStart = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0, DateTimeKind.Utc);
            DateTime dayEnd   = new DateTime(date.Year, date.Month, date.Day, 23, 59, 59, DateTimeKind.Utc);
            var      result   = mongorepo.Find <MongoTwitterDailyReports>(t => t.profileId.Equals(profileId) && (t.timeStamp > SBHelper.ConvertToUnixTimestamp(dayStart)) && (t.timeStamp < SBHelper.ConvertToUnixTimestamp(dayEnd)));
            var      task     = Task.Run(async() =>
            {
                return(await result);
            });
            IList <MongoTwitterDailyReports> lstDailyReports = task.Result;

            if (lstDailyReports != null && lstDailyReports.Count() > 0)
            {
                lstDailyReports.First().mentions               = todayReports.mentions;
                lstDailyReports.First().newFollowers           = todayReports.newFollowers;
                lstDailyReports.First().newFollowing           = todayReports.newFollowing;
                lstDailyReports.First().profileId              = profileId;
                lstDailyReports.First().timeStamp              = SBHelper.ConvertToUnixTimestamp(date);
                lstDailyReports.First().directMessagesSent     = todayReports.directMessagesSent;
                lstDailyReports.First().directMessagesReceived = todayReports.directMessagesReceived;
                lstDailyReports.First().messagesReceived       = todayReports.messagesReceived;
                lstDailyReports.First().messagesSent           = todayReports.messagesSent;
                mongorepo.UpdateReplace(lstDailyReports.First(), t => t.id == lstDailyReports.First().id);
            }
            else
            {
                mongorepo.Add <MongoTwitterDailyReports>(todayReports);
            }
        }
Example #17
0
        public static void GoogleAnalyticsreportData(string ProfileId, string AccessToken, string HostName, bool is90daysupdated)
        {
            Helper.Cache    cache                     = new Helper.Cache(Helper.AppSettings.RedisConfiguration);
            MongoRepository TwtsearchRepo             = new MongoRepository("TwitterUrlMentions");
            MongoRepository ArticlesAndBlogsRepo      = new MongoRepository("ArticlesAndBlogs");
            MongoRepository GoogleAnalyticsReportRepo = new Model.MongoRepository("GoogleAnalyticsReport");
            string          finalToken                = string.Empty;
            int             day = 1;

            if (!is90daysupdated)
            {
                day = 90;
            }
            oAuthTokenGa objToken   = new oAuthTokenGa(Helper.AppSettings.googleClientId, Helper.AppSettings.googleClientSecret, Helper.AppSettings.googleRedirectionUrl);
            string       finaltoken = objToken.GetAccessToken(AccessToken);

            try
            {
                JObject objArray = JObject.Parse(finaltoken);
                finalToken = objArray["access_token"].ToString();
            }
            catch (Exception ex)
            {
                finalToken = AccessToken;
                Console.WriteLine(ex.StackTrace);
            }
            Analytics _Analytics = new Analytics("246221405801-5sg3n6bfpj329ie7tiqfdnb404pc78ea.apps.googleusercontent.com", "S5B4EtNKIe-1yHq4xEtXHCHK", "https://www.socioboard.com/GoogleManager/Google");
            DateTime  startDate  = DateTime.UtcNow.Date.AddDays(-day);

            while (startDate.Date < DateTime.UtcNow.Date)
            {
                string visits    = string.Empty;
                string pageviews = string.Empty;
                try
                {
                    string  analytics = _Analytics.getAnalyticsData(ProfileId, "ga:visits,ga:pageviews", startDate.ToString("yyyy-MM-dd"), startDate.ToString("yyyy-MM-dd"), finalToken);
                    JObject JData     = JObject.Parse(analytics);
                    visits    = JData["totalsForAllResults"]["ga:visits"].ToString();
                    pageviews = JData["totalsForAllResults"]["ga:pageviews"].ToString();
                }
                catch (Exception ex)
                {
                    visits    = "0";
                    pageviews = "0";
                }
                double startUnixTime = SBHelper.ConvertToUnixTimestamp(startDate.Date);
                double endUnixTime   = SBHelper.ConvertToUnixTimestamp(startDate.AddDays(1).Date);
                var    ret           = TwtsearchRepo.Find <Domain.Socioboard.Models.Mongo.TwitterUrlMentions>(t => t.HostName.Equals(HostName));
                var    task          = Task.Run(async() =>
                {
                    return(await ret);
                });
                IList <Domain.Socioboard.Models.Mongo.TwitterUrlMentions> lstTwitterUrlMentions = task.Result.ToList();
                int twtCount = lstTwitterUrlMentions.Count(t => t.Feeddate > startUnixTime && t.Feeddate <= endUnixTime);
                var ret1     = ArticlesAndBlogsRepo.Find <Domain.Socioboard.Models.Mongo.ArticlesAndBlogs>(t => t.HostName.Equals(HostName));
                var task1    = Task.Run(async() =>
                {
                    return(await ret1);
                });
                IList <Domain.Socioboard.Models.Mongo.ArticlesAndBlogs> lstArticlesAndBlogs = task1.Result.ToList();
                int artucleCount = lstArticlesAndBlogs.Count(t => t.Created_Time > startUnixTime && t.Created_Time <= endUnixTime);

                Domain.Socioboard.Models.Mongo.GoogleAnalyticsReport _GoogleAnalyticsReport = new Domain.Socioboard.Models.Mongo.GoogleAnalyticsReport();
                _GoogleAnalyticsReport.Id             = ObjectId.GenerateNewId();
                _GoogleAnalyticsReport.strId          = ObjectId.GenerateNewId().ToString();
                _GoogleAnalyticsReport.GaProfileId    = ProfileId;
                _GoogleAnalyticsReport.Article_Blogs  = artucleCount.ToString();
                _GoogleAnalyticsReport.TwitterMention = twtCount.ToString();
                _GoogleAnalyticsReport.Views          = pageviews;
                _GoogleAnalyticsReport.Visits         = visits;
                _GoogleAnalyticsReport.date           = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                GoogleAnalyticsReportRepo.Add <Domain.Socioboard.Models.Mongo.GoogleAnalyticsReport>(_GoogleAnalyticsReport);
                startDate = startDate.AddDays(1);
            }
        }
        public static string saveContentDataIdReposi(List <Domain.Socioboard.Models.Mongo.ContentFeedsShareathon> shareathon, long userId, string fbPageId, int timeInterval, Helper.Cache _redisCache, Helper.AppSettings settings, Model.DatabaseRepository dbr)
        {
            string[] lstProfileIds = null;
            if (fbPageId != null)
            {
                lstProfileIds = fbPageId.Split(',');
                fbPageId      = lstProfileIds[0];
            }

            MongoRepository mongorepo        = new MongoRepository("ContentFeedsShareathon", settings);
            MongoRepository mongoreposhareId = new MongoRepository("ContentStudioShareathonIdData", settings);



            int totalval = 0;

            // DateTime timeval = DateTime.Now;
            foreach (var fbid in lstProfileIds)
            {
                Domain.Socioboard.Models.Facebookaccounts listfb = dbr.FindSingle <Domain.Socioboard.Models.Facebookaccounts>(t => t.FbUserId == fbid);
                int    countval     = 0;
                int    countitem    = 0;
                string timevalue    = null;
                string sectimevalue = null;
                foreach (var item in shareathon)
                {
                    var retval  = mongoreposhareId.Find <Domain.Socioboard.Models.Mongo.ContentStudioShareathonIdData>(t => t.FbPageId.Contains(fbid) && t.postId == item.postId);
                    var taskval = Task.Run(async() =>
                    {
                        return(await retval);
                    });
                    int countvalue = taskval.Result.Count;
                    if (countvalue < 1)
                    {
                        Domain.Socioboard.Models.Mongo.ContentStudioShareathonIdData lstIdforPost = new Domain.Socioboard.Models.Mongo.ContentStudioShareathonIdData();
                        lstIdforPost.Id                  = ObjectId.GenerateNewId();
                        lstIdforPost.strId               = ObjectId.GenerateNewId().ToString();
                        lstIdforPost.FbPageId            = fbid;
                        lstIdforPost.Status              = false;
                        lstIdforPost.UserId              = listfb.UserId;
                        lstIdforPost.Timeintervalminutes = timeInterval;
                        lstIdforPost.postId              = item.postId;
                        lstIdforPost.lastsharestamp      = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                        if (countitem == 0)
                        {
                            lstIdforPost.latsSharetime = DateTime.UtcNow;
                        }
                        else
                        {
                            // a.AddMinutes
                            DateTime secval = Convert.ToDateTime(timevalue);
                            lstIdforPost.latsSharetime = secval.AddMinutes(timeInterval);//timevalue.latsSharetime.AddMinutes(timeInterval);
                            // var result = TimeSpan.FromMinutes(timeInterval);
                            //  lstIdforPost.lastsharestamp = lstIdforPost.lastsharestamp + datetotimestamp;
                        }


                        try
                        {
                            mongoreposhareId.Add(lstIdforPost);
                        }
                        catch (Exception ex)
                        {
                            //return "not added";
                        }
                        DateTime timeval = lstIdforPost.latsSharetime;
                        timevalue = timeval.ToString();
                    }
                    int count = 0;
                    try
                    {
                        var ret  = mongorepo.Find <Domain.Socioboard.Models.Mongo.ContentFeedsShareathon>(t => t.postId.Contains(item.postId) && t.FbPageId.Contains(fbid));
                        var task = Task.Run(async() =>
                        {
                            return(await ret);
                        });
                        count = task.Result.Count;
                    }
                    catch
                    {
                        var ret  = mongorepo.Find <Domain.Socioboard.Models.Mongo.ContentFeedsShareathon>(t => t.strId.Contains(item.strId) && t.FbPageId.Contains(fbid));
                        var task = Task.Run(async() =>
                        {
                            return(await ret);
                        });
                        count = task.Result.Count;
                    }


                    if (count < 1)
                    {
                        Domain.Socioboard.Models.Mongo.ContentFeedsShareathon lstforShareathon = new Domain.Socioboard.Models.Mongo.ContentFeedsShareathon();

                        lstforShareathon.Id                  = ObjectId.GenerateNewId();
                        lstforShareathon.strId               = ObjectId.GenerateNewId().ToString();
                        lstforShareathon.FbPageId            = fbid;
                        lstforShareathon.postId              = item.postId;
                        lstforShareathon.networkType         = item.networkType;
                        lstforShareathon.title               = item.title;
                        lstforShareathon.facebookAccount     = listfb.FbUserName;
                        lstforShareathon.ImageUrl            = item.ImageUrl;
                        lstforShareathon.postUrl             = item.postUrl;
                        lstforShareathon.videourl            = item.videourl;
                        lstforShareathon.UserId              = userId;
                        lstforShareathon.Timeintervalminutes = timeInterval;
                        lstforShareathon.lastsharestamp      = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);

                        lstforShareathon.Status = false;
                        if (countitem == 0)
                        {
                            lstforShareathon.latsSharetime = DateTime.UtcNow;
                        }
                        else
                        {
                            // a.AddMinutes
                            DateTime sectableaddtime = Convert.ToDateTime(sectimevalue);
                            lstforShareathon.latsSharetime = sectableaddtime.AddMinutes(timeInterval);
                        }
                        try
                        {
                            mongorepo.Add(lstforShareathon);
                            countval++;
                        }
                        catch (Exception ex)
                        {
                            //return "not added";
                        }

                        DateTime timevalsec = lstforShareathon.latsSharetime;
                        sectimevalue = timevalsec.ToString();
                    }
                    else
                    {
                        // return "some problem while adding";
                    }
                    countitem++;
                    totalval = countval;
                }
            }


            if (totalval > 0)
            {
                return("added successfully");
            }
            else
            {
                return("feed has already added");
            }
        }
        public static List <InstagramFeed> GetImagePosts(string profileId, int daysCount)
        {
            var instagramFeedRepo = new MongoRepository("InstagramFeed");
            var dayStart          = new DateTime(DateTime.UtcNow.AddDays(-(daysCount)).Year, DateTime.UtcNow.AddDays(-(daysCount)).Month, DateTime.UtcNow.AddDays(-(daysCount)).Day, 0, 0, 0, DateTimeKind.Utc);
            var dayEnd            = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 59, DateTimeKind.Utc);
            var ret  = instagramFeedRepo.Find <InstagramFeed>(t => t.InstagramId == profileId && t.FeedDate <= SBHelper.ConvertToUnixTimestamp(dayEnd) && t.FeedDate >= SBHelper.ConvertToUnixTimestamp(dayStart) && t.Type == "image");
            var task = Task.Run(async() =>
            {
                return(await ret);
            });
            var lstInstagramFeed = task.Result.GroupBy(x => x.FeedId).Select(g => g.First()).ToList();

            return(lstInstagramFeed);
        }
Example #20
0
        public void ShareFeedonGroup(string fbAccesstoken, string FeedId, string pageId, string message,
                                     string fbgroupId, int time, string faceaccountId, double lastupdatetime, string Facebooknameid)
        {
            var lstPost = new List <string>();
            var lstCout = 0;
            var feedid  = FeedId.TrimEnd(',').Split(',');
            var grpid   = Facebooknameid.TrimEnd(',').Split(',');
            var r       = new Random();
            var length  = feedid.Length;
            var objSharethonGroupPost = new SharethonGroupPost();
            var mongoRepository       = new MongoRepository("SharethonGroupPost");

            while (length >= lstCout)
            {
                var i = r.Next(0, length - 1);
                if (!lstPost.Contains(feedid[i]))
                {
                    var postId = feedid[i];
                    lstPost.Add(feedid[i]);
                    lstCout++;
                    foreach (var item in grpid)
                    {
                        var groupData = Regex.Split(item, "<:>");

                        var postData = mongoRepository.Find <SharethonGroupPost>(t =>
                                                                                 t.Facebookgroupid.Equals(groupData[1]) && t.PostId.Equals(postId));

                        var task = Task.Run(async() => await postData);

                        var count = task.Result.Count;

                        var link = "https://www.facebook.com/" + pageId + "/posts/" + feedid[i];

                        try
                        {
                            if (count < 1)
                            {
                                //  dynamic output = fb.Post("v2.7/" + grpdata[1] + "/feed", args);
                                try
                                {
                                    var response = FacebookApiHelper.PublishPostOnPage(fbAccesstoken, groupData[1], string.Empty,
                                                                                       string.Empty, link);
                                    if (response.Contains("id"))
                                    {
                                        GroupapiHitsCount++;
                                    }
                                }
                                catch (Exception)
                                {
                                    GroupapiHitsCount = GroupMaxapiHitsCount;
                                }

                                objSharethonGroupPost.Id = ObjectId.GenerateNewId();
                                objSharethonGroupPost.Facebookaccountid = faceaccountId;
                                objSharethonGroupPost.Facebookgroupid   = groupData[1];
                                objSharethonGroupPost.Facebookgroupname = groupData[0];
                                objSharethonGroupPost.PostId            = feedid[i];
                                objSharethonGroupPost.PostedTime        = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                                mongoRepository.Add(objSharethonGroupPost);
                            }
                        }
                        catch (Exception ex)
                        {
                            GroupapiHitsCount = GroupMaxapiHitsCount;
                            Console.WriteLine(ex.Message);
                        }
                    }
                    Thread.Sleep(1000 * 50);
                }

                Thread.Sleep(1000 * 60 * time);
            }
        }
        public static List <InstagramPostLikes> GetInstagramPostLikes(string profileId, int daysCount)
        {
            var InstagramPostLikesRepo = new MongoRepository("InstagramPostLikes");
            var dayStart = new DateTime(DateTime.UtcNow.AddDays(-(daysCount)).Year, DateTime.UtcNow.AddDays(-(daysCount)).Month, DateTime.UtcNow.AddDays(-(daysCount)).Day, 0, 0, 0, DateTimeKind.Utc);
            var dayEnd   = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 59, DateTimeKind.Utc);
            var ret      = InstagramPostLikesRepo.Find <InstagramPostLikes>(t => t.Profile_Id == profileId && t.Created_Date <= SBHelper.ConvertToUnixTimestamp(dayEnd) && t.Created_Date >= SBHelper.ConvertToUnixTimestamp(dayStart));
            var task     = Task.Run(async() =>
            {
                return(await ret);
            });
            var lstInstagramPostLikes = task.Result.ToList();

            return(lstInstagramPostLikes);
        }
Example #22
0
        public void PageShreathon(object o)
        {
            try
            {
                var arr        = o as object[];
                var shareathon = (PageShareathon)arr[0];
                var dbr        = (DatabaseRepository)arr[1];

                var shareathonRepository = (MongoRepository)arr[2];

                var ids = shareathon.Facebookpageid.Split(',');
                GlobalVariable.pageShareathonIdsRunning.Add(shareathon.strId);

                foreach (var id in ids)
                {
                    try
                    {
                        PageapiHitsCount = 0;
                        var fbAcc = dbr.Single <Facebookaccounts>(t => t.FbUserId == shareathon.Facebookaccountid);
                        Facebookaccounts facebookPage = null;

                        var lstFbAcc = dbr.Single <Facebookaccounts>(t => t.FbUserId == id);

                        if (lstFbAcc != null)
                        {
                            facebookPage = lstFbAcc;
                        }
                        if (facebookPage != null)
                        {
                            if (PageapiHitsCount < PageMaxapiHitsCount)
                            {
                                var feeds = string.Empty;

                                if (facebookPage.PageShareathonUpdate.AddHours(1) <= DateTime.UtcNow)
                                {
                                    feeds = Fbpages.getFacebookRecentPost(fbAcc.AccessToken, facebookPage.FbUserId);
                                    var feedId = string.Empty;

                                    if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]"))
                                    {
                                        PageapiHitsCount++;
                                        var fbpageNotes = JObject.Parse(feeds);

                                        foreach (var obj in JArray.Parse(fbpageNotes["data"].ToString()))
                                        {
                                            try
                                            {
                                                feedId = obj["id"].ToString();
                                                feedId = feedId.Split('_')[1];
                                                var dt = SBHelper.ConvertFromUnixTimestamp(
                                                    shareathon.Lastsharetimestamp);
                                                dt = dt.AddMinutes(shareathon.Timeintervalminutes);

                                                if (!shareathon.Lastpostid.Equals(feedId) &&
                                                    SBHelper.ConvertToUnixTimestamp(dt) <=
                                                    SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow))
                                                {
                                                    var ret = ShareFeed(fbAcc.AccessToken, feedId,
                                                                        facebookPage.FbUserId, "", fbAcc.FbUserId,
                                                                        facebookPage.FbUserName);
                                                    if (!string.IsNullOrEmpty(ret))
                                                    {
                                                        Thread.Sleep(1000 * 60 * shareathon.Timeintervalminutes);
                                                    }
                                                }
                                            }
                                            catch
                                            {
                                                PageapiHitsCount = PageMaxapiHitsCount;
                                            }
                                        }

                                        fbAcc.PageShareathonUpdate        = DateTime.UtcNow;
                                        facebookPage.PageShareathonUpdate = DateTime.UtcNow;
                                        dbr.Update(fbAcc);
                                        dbr.Update(facebookPage);
                                    }
                                    else
                                    {
                                        FilterDefinition <BsonDocument> filter =
                                            new BsonDocument("strId", shareathon.strId);
                                        var update = Builders <BsonDocument> .Update.Set("FacebookStatus", 0);

                                        shareathonRepository.Update <PageShareathon>(update, filter);
                                    }
                                }
                                else
                                {
                                    PageapiHitsCount = 0;
                                }
                            }
                        }
                    }
                    catch
                    {
                        PageapiHitsCount = PageMaxapiHitsCount;
                    }
                }

                try
                {
                    if (!string.IsNullOrEmpty(shareathon.FacebookPageUrlId))
                    {
                        var urlsIds = shareathon.FacebookPageUrlId.Split(',');
                        foreach (var idUrl in urlsIds)
                        {
                            try
                            {
                                PageapiHitsCount = 0;
                                var fbAcc = dbr.Single <Facebookaccounts>(
                                    t => t.FbUserId == shareathon.Facebookaccountid);
                                var pagename = Fbpages.GetFbPageName(fbAcc.AccessToken, idUrl);
                                if (PageapiHitsCount < PageMaxapiHitsCount)
                                {
                                    var feeds = string.Empty;
                                    feeds = Fbpages.getFacebookRecentPost(fbAcc.AccessToken, idUrl);
                                    var feedId = string.Empty;
                                    if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]"))
                                    {
                                        PageapiHitsCount++;
                                        var fbpageNotes = JObject.Parse(feeds);
                                        foreach (var obj in JArray.Parse(fbpageNotes["data"].ToString()))
                                        {
                                            try
                                            {
                                                feedId = obj["id"].ToString();
                                                feedId = feedId.Split('_')[1];
                                                var dt = SBHelper.ConvertFromUnixTimestamp(
                                                    shareathon.Lastsharetimestamp);
                                                dt = dt.AddMinutes(shareathon.Timeintervalminutes);
                                                if (!shareathon.Lastpostid.Equals(feedId) &&
                                                    SBHelper.ConvertToUnixTimestamp(dt) <=
                                                    SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow))
                                                {
                                                    var ret = ShareFeed(fbAcc.AccessToken, feedId, idUrl, "",
                                                                        fbAcc.FbUserId, pagename);
                                                    if (!string.IsNullOrEmpty(ret))
                                                    {
                                                        Thread.Sleep(1000 * 60 * shareathon.Timeintervalminutes);
                                                    }
                                                }
                                            }
                                            catch
                                            {
                                                PageapiHitsCount = PageMaxapiHitsCount;
                                            }
                                        }

                                        fbAcc.PageShareathonUpdate = DateTime.UtcNow;
                                        dbr.Update(fbAcc);
                                    }
                                    else
                                    {
                                        FilterDefinition <BsonDocument> filter =
                                            new BsonDocument("strId", shareathon.strId);
                                        var update = Builders <BsonDocument> .Update.Set("FacebookStatus", 1);

                                        shareathonRepository.Update <PageShareathon>(update, filter);
                                    }
                                }
                            }
                            catch
                            {
                                PageapiHitsCount = PageMaxapiHitsCount;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }

                GlobalVariable.pageShareathonIdsRunning.Remove(shareathon.strId);
            }
            catch (Exception e)
            {
                PageapiHitsCount = PageMaxapiHitsCount;
                Console.WriteLine(e.Message);
            }
            finally
            {
                NoOfthreadPageshreathonRunning--;
            }
        }
Example #23
0
        //for twiter
        public static List <TwitterUrlMentions> GetTwitterMentionReports(string HostName, int dayCount, Helper.Cache _redisCache, Helper.AppSettings settings)
        {
            MongoRepository TwtsearchRepo = new MongoRepository("TwitterUrlMentions", settings);
            DateTime        dayStart      = new DateTime(DateTime.UtcNow.AddDays(-90).Year, DateTime.UtcNow.AddDays(-90).Month, DateTime.UtcNow.AddDays(-90).Day, 0, 0, 0, DateTimeKind.Utc);
            DateTime        dayEnd        = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 59, DateTimeKind.Utc);
            var             result        = TwtsearchRepo.Find <TwitterUrlMentions>(t => t.HostName.Equals(HostName) && (t.Feeddate > SBHelper.ConvertToUnixTimestamp(dayStart)) && (t.Feeddate < SBHelper.ConvertToUnixTimestamp(dayEnd)));
            var             task          = Task.Run(async() =>
            {
                return(await result);
            });
            IList <TwitterUrlMentions> lstDailyReports = task.Result;

            return(lstDailyReports.ToList());
        }
Example #24
0
        public void Groupshreathon(object o)
        {
            try
            {
                var arr                  = o as object[];
                var shareathon           = (GroupShareathon)arr[0];
                var dbr                  = (DatabaseRepository)arr[1];
                var shareathonRepository = (MongoRepository)arr[2];
                var ids                  = shareathon.Facebookpageid.Split(',');

                foreach (var id in ids)
                {
                    try
                    {
                        var groupApiHitsCountNew = 0;
                        var fbAcc = dbr.Single <Facebookaccounts>(t => t.FbUserId == shareathon.Facebookaccountid);
                        //var lstFbAcc = dbr.Single<Domain.Socioboard.Models.Facebookaccounts>(t => t.FbUserId == id);

                        if (fbAcc != null)
                        {
                            if (groupApiHitsCountNew < GroupMaxapiHitsCount)
                            {
                                var feeds = string.Empty;
                                if (fbAcc.GroupShareathonUpdate.AddHours(1) <= DateTime.UtcNow)
                                {
                                    feeds = Fbpages.getFacebookRecentPost(fbAcc.AccessToken, id);

                                    var feedId = string.Empty;
                                    if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]"))
                                    {
                                        var fbpageNotes = JObject.Parse(feeds);
                                        foreach (var obj in JArray.Parse(fbpageNotes["data"].ToString()))
                                        {
                                            try
                                            {
                                                var feedid = obj["id"].ToString();
                                                feedid = feedid.Split('_')[1];
                                                feedId = feedid + "," + feedId;
                                            }
                                            catch (Exception ex)
                                            {
                                                Console.WriteLine(ex.Message);
                                            }
                                        }

                                        try
                                        {
                                            var dt = SBHelper.ConvertFromUnixTimestamp(shareathon.Lastsharetimestamp);
                                            dt = dt.AddMinutes(shareathon.Timeintervalminutes);
                                            if (shareathon.Lastpostid == null ||
                                                !shareathon.Lastpostid.Equals(feedId) &&
                                                SBHelper.ConvertToUnixTimestamp(dt) <=
                                                SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow))
                                            {
                                                ShareFeedonGroup(fbAcc.AccessToken, feedId, id, "",
                                                                 shareathon.Facebookgroupid, shareathon.Timeintervalminutes,
                                                                 shareathon.Facebookaccountid, shareathon.Lastsharetimestamp,
                                                                 shareathon.Facebooknameid);
                                            }
                                            fbAcc.GroupShareathonUpdate = DateTime.UtcNow;
                                            dbr.Update(fbAcc);
                                        }
                                        catch (Exception ex)
                                        {
                                            Console.WriteLine(ex.Message);
                                        }
                                    }
                                    else
                                    {
                                        FilterDefinition <BsonDocument> filter =
                                            new BsonDocument("strId", shareathon.strId);
                                        var update = Builders <BsonDocument> .Update.Set("FacebookStatus", 0);

                                        shareathonRepository.Update <GroupShareathon>(update, filter);
                                        GroupapiHitsCount = GroupMaxapiHitsCount;
                                    }
                                }
                                else
                                {
                                    GroupapiHitsCount = 0;
                                }
                            }
                        }
                    }
                    catch
                    {
                        GroupapiHitsCount = GroupMaxapiHitsCount;
                    }
                }
            }
            catch (Exception e)
            {
                GroupapiHitsCount = GroupMaxapiHitsCount;
                Console.WriteLine(e.Message);
            }
            finally
            {
                NoOfthreadGroupshreathonRunning--;
            }
        }
Example #25
0
 public static void flickrSearch()
 {
     try
     {
         string  Imagedata = getHtmlfromUrl();
         JObject shareData = JObject.Parse(Imagedata);
         foreach (var item in shareData["photos"]["photo"])
         {
             MongoRepository mongoreppo = new MongoRepository("AdvanceSerachData");
             Domain.Socioboard.Models.Mongo.AdvanceSerachData _AdvanceSerachData = new Domain.Socioboard.Models.Mongo.AdvanceSerachData();
             _AdvanceSerachData.Id          = ObjectId.GenerateNewId();
             _AdvanceSerachData.strId       = ObjectId.GenerateNewId().ToString();
             _AdvanceSerachData.domainType  = "https://www.flickr.com/";
             _AdvanceSerachData.postType    = Domain.Socioboard.Enum.AdvanceSearchpostType.trending;
             _AdvanceSerachData.networkType = Domain.Socioboard.Enum.NetworkType.flickr;
             try
             {
                 _AdvanceSerachData.ImageUrl = item["url_n"].ToString();
                 _AdvanceSerachData.postUrl  = item["url_n"].ToString();
             }
             catch { }
             try
             {
                 _AdvanceSerachData.title = item["title"].ToString();
             }
             catch { }
             try
             {
                 _AdvanceSerachData.postdescription = item["tags"].ToString();
             }
             catch { }
             try
             {
                 _AdvanceSerachData.postId = item["id"].ToString();
             }
             catch { }
             try
             {
                 _AdvanceSerachData.userName = item["ownername"].ToString();
             }
             catch { }
             try
             {
                 _AdvanceSerachData.postedTime = Domain.Socioboard.Helpers.SBHelper.ConvertToUnixTimestamp(Convert.ToDateTime(item["datetaken"].ToString()));
             }
             catch {
                 _AdvanceSerachData.postedTime = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
             }
             int count = mongoreppo.Counts <Domain.Socioboard.Models.Mongo.AdvanceSerachData>(t => t.postUrl == _AdvanceSerachData.postUrl);
             if (count == 0)
             {
                 mongoreppo.Add <Domain.Socioboard.Models.Mongo.AdvanceSerachData>(_AdvanceSerachData);
             }
             else
             {
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
Example #26
0
        public static void GetTwitterWebMentions(string HostName)
        {
            MongoRepository TwtsearchRepo = new MongoRepository("TwitterUrlMentions");

            try
            {
                HostName = HostName.Replace("www.", "");
                JArray output = new JArray();
                SortedDictionary <string, string> requestParameters = new SortedDictionary <string, string>();
                try
                {
                    var oauth_url    = " https://api.twitter.com/1.1/search/tweets.json?q=" + HostName.Trim() + "&result_type=recent&count=30";
                    var headerFormat = "Bearer {0}";
                    var authHeader   = string.Format(headerFormat, "AAAAAAAAAAAAAAAAAAAAAOZyVwAAAAAAgI0VcykgJ600le2YdR4uhKgjaMs%3D0MYOt4LpwCTAIi46HYWa85ZcJ81qi0D9sh8avr1Zwf7BDzgdHT");

                    var postBody = requestParameters.ToWebString();
                    ServicePointManager.Expect100Continue = false;

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(oauth_url + "?"
                                                                               + requestParameters.ToWebString());

                    request.Headers.Add("Authorization", authHeader);
                    request.Method = "GET";
                    request.Headers.Add("Accept-Encoding", "gzip");
                    HttpWebResponse response       = request.GetResponse() as HttpWebResponse;
                    Stream          responseStream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress);
                    using (var reader = new StreamReader(responseStream))
                    {
                        var objText = reader.ReadToEnd();
                        output = JArray.Parse(JObject.Parse(objText)["statuses"].ToString());
                    }
                }
                catch (Exception ex)
                {
                }
                Domain.Socioboard.Models.Mongo.TwitterUrlMentions _TwitterUrlMentions;
                try
                {
                    foreach (var chile in output)
                    {
                        try
                        {
                            _TwitterUrlMentions              = new Domain.Socioboard.Models.Mongo.TwitterUrlMentions();
                            _TwitterUrlMentions.Id           = ObjectId.GenerateNewId();
                            _TwitterUrlMentions.Feed         = chile["text"].ToString();
                            _TwitterUrlMentions.Feeddate     = SBHelper.ConvertToUnixTimestamp(ParseTwitterTime(chile["created_at"].ToString()));
                            _TwitterUrlMentions.FeedId       = chile["id_str"].ToString();
                            _TwitterUrlMentions.FromId       = chile["user"]["id_str"].ToString();
                            _TwitterUrlMentions.FromImageUrl = chile["user"]["profile_image_url"].ToString();
                            _TwitterUrlMentions.FromName     = chile["user"]["screen_name"].ToString();
                            _TwitterUrlMentions.HostName     = HostName;

                            var ret  = TwtsearchRepo.Find <Domain.Socioboard.Models.Mongo.TwitterUrlMentions>(t => t.FeedId.Equals(_TwitterUrlMentions.FeedId) && t.HostName.Equals(_TwitterUrlMentions.HostName));
                            var task = Task.Run(async() =>
                            {
                                return(await ret);
                            });
                            int count = task.Result.Count;

                            if (count < 1)
                            {
                                TwtsearchRepo.Add(_TwitterUrlMentions);
                            }
                        }
                        catch { }
                    }
                }
                catch { }
            }
            catch { }
        }
        public static List <TwitterFan> GetTopFiveFans(string profileId, int daysCount, Helper.Cache _redisCache, Helper.AppSettings settings)
        {
            MongoRepository mongorepo = new MongoRepository("MongoMessageModel", settings);
            DateTime        dayStart  = new DateTime(DateTime.UtcNow.AddDays(-1 * daysCount).Year, DateTime.UtcNow.AddDays(-1 * daysCount).Month, DateTime.UtcNow.AddDays(-1 * daysCount).Day, 0, 0, 0, DateTimeKind.Utc);
            DateTime        dayEnd    = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 59, DateTimeKind.Utc);
            var             result    = mongorepo.Find <MongoMessageModel>(t => (t.messageTimeStamp > SBHelper.ConvertToUnixTimestamp(dayStart)) && (t.messageTimeStamp < SBHelper.ConvertToUnixTimestamp(dayEnd)) && t.profileId == profileId && (t.type == Domain.Socioboard.Enum.MessageType.TwitterMention || t.type == Domain.Socioboard.Enum.MessageType.TwitterRetweet));
            var             task      = Task.Run(async() =>
            {
                return(await result);
            });
            IList <Domain.Socioboard.Models.Mongo.MongoMessageModel> lstTwtMessages = task.Result;
            List <TwitterFan> lstTwtTopFans = lstTwtMessages.GroupBy(t => t.fromId).Select(g => new TwitterFan(g.ToList())).OrderBy(x => x.totalCount).Take(5).ToList();

            return(lstTwtTopFans);
        }
Example #28
0
        public static void DailyMotionPost(string Url)
        {
            MongoRepository ArticlesAndBlogsRepo = new MongoRepository("ArticlesAndBlogs");

            try
            {
                string _dailymotionpostRestUrl = "https://api.dailymotion.com/videos/?search=" + Url + "&fields=id,title,created_time,url,description";

                string response = WebRequst(_dailymotionpostRestUrl);

                var jdata = Newtonsoft.Json.Linq.JObject.Parse(response);

                foreach (var item in jdata["list"])
                {
                    Domain.Socioboard.Models.Mongo.ArticlesAndBlogs _ArticlesAndBlogs = new Domain.Socioboard.Models.Mongo.ArticlesAndBlogs();
                    _ArticlesAndBlogs.Id       = ObjectId.GenerateNewId();
                    _ArticlesAndBlogs.Type     = Domain.Socioboard.Enum.ArticlesAndBlogsTypes.dailymotion;
                    _ArticlesAndBlogs.HostName = Url;

                    try
                    {
                        _ArticlesAndBlogs.VideoId = item["id"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _ArticlesAndBlogs.VideoId = "";
                    }
                    try
                    {
                        _ArticlesAndBlogs.Title = item["title"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _ArticlesAndBlogs.Title = "";
                    }
                    try
                    {
                        _ArticlesAndBlogs.VideoUrl = item["url"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _ArticlesAndBlogs.VideoUrl = "";
                    }
                    try
                    {
                        _ArticlesAndBlogs.Description = item["description"].ToString();
                    }
                    catch (Exception ex)
                    {
                        _ArticlesAndBlogs.Description = "";
                    }
                    try
                    {
                        _ArticlesAndBlogs.Created_Time = double.Parse(item["created_time"].ToString());
                    }
                    catch (Exception ex)
                    {
                        _ArticlesAndBlogs.Created_Time = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                    }
                    _ArticlesAndBlogs.Url = Url;
                    var ret  = ArticlesAndBlogsRepo.Find <Domain.Socioboard.Models.Mongo.ArticlesAndBlogs>(t => t.VideoId.Equals(_ArticlesAndBlogs.VideoId) && t.Type.Equals(_ArticlesAndBlogs.Type));
                    var task = Task.Run(async() =>
                    {
                        return(await ret);
                    });
                    int count = task.Result.Count;
                    if (count < 1)
                    {
                        ArticlesAndBlogsRepo.Add(_ArticlesAndBlogs);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        private static List <MongoDirectMessages> GetTodayDirectMessages(string profileId, long userId, Helper.Cache _redisCache, Helper.AppSettings settings)
        {
            MongoRepository mongorepo = new MongoRepository("MongoDirectMessages", settings);
            DateTime        dayStart  = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 0, 0, 0, DateTimeKind.Utc);
            DateTime        dayEnd    = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 59, DateTimeKind.Utc);
            var             result    = mongorepo.Find <MongoDirectMessages>(t => (t.timeStamp > SBHelper.ConvertToUnixTimestamp(dayStart)) && (t.timeStamp < SBHelper.ConvertToUnixTimestamp(dayEnd)));
            var             task      = Task.Run(async() =>
            {
                return(await result);
            });
            IList <Domain.Socioboard.Models.Mongo.MongoDirectMessages> lstTwtMessages = task.Result;

            return(lstTwtMessages.ToList());
        }
 public IEnumerable <MongoFacebookFeed> FetchAccountsFeedDetails(Facebookaccounts facebookAccount,
                                                                 JObject feedDetails)
 {
     return((from feed in feedDetails.SelectTokens("data")?.SelectMany(feed => feed)
             select JObject.Parse(feed.ToString())
             into feedDetail
             let fromName = feedDetail.SelectToken("from.name")?.ToString()
                            let fromId = feedDetail.SelectToken("from.id")?.ToString()
                                         let feedId = feedDetail.SelectToken("id")?.ToString()
                                                      let createdDateTime = DateTime.Parse(feedDetail.SelectToken("created_time")?.ToString() ?? DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"))
                                                                            .ToString("yyyy/MM/dd HH:mm:ss")
                                                                            let likeCount = feedDetail.SelectToken("likes.summary.total_count")?.ToString()
                                                                                            let commentCount = feedDetail.SelectToken("comments.summary.total_count")?.ToString()
                                                                                                               let postType = feedDetail.SelectToken("type")?.ToString() ?? "status"
                                                                                                                              let postingFrom = feedDetail.SelectToken("application.name")?.ToString() ?? "Facebook"
                                                                                                                                                let picture = feedDetail.SelectToken("picture")?.ToString()
                                                                                                                                                              let message = feedDetail.SelectToken("message")?.ToString() ?? feedDetail.SelectToken("description")?.ToString() ?? feedDetail.SelectToken("story")?.ToString() ?? string.Empty
                                                                                                                                                                            let postDate = SBHelper.ConvertToUnixTimestamp(Convert.ToDateTime(createdDateTime))
                                                                                                                                                                                           select new MongoFacebookFeed
     {
         Type = "fb_feed",
         ProfileId = facebookAccount.FbUserId,
         Id = ObjectId.GenerateNewId(),
         FromProfileUrl = $"http://graph.facebook.com/{facebookAccount.FbUserId}/picture?type=small",
         FromName = fromName,
         FromId = fromId,
         FeedId = feedId,
         FeedDate = postDate.ToString(CultureInfo.InvariantCulture),
         FeedDateToshow = SBHelper.ConvertFromUnixTimestamp(Convert.ToDouble(postDate)).ToString("yyyy/MM/dd HH:mm:ss"),
         FbComment = $"http://graph.facebook.com/{feedId}/comments",
         FbLike = $"http://graph.facebook.com/{feedId}/likes",
         Likecount = likeCount,
         Commentcount = commentCount,
         postType = postType,
         postingFrom = postingFrom,
         Picture = picture,
         FeedDescription = message,
         EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss")
     }).ToList());
 }