public static void GetGooglePlusComments(string feedId, string AccessToken, string profileId, Helper.AppSettings settings, ILogger _logger) { MongoRepository gplusCommentRepo = new MongoRepository("GoogleplusComments", settings); oAuthTokenGPlus ObjoAuthTokenGPlus = new oAuthTokenGPlus(settings.GoogleConsumerKey, settings.GoogleConsumerSecret, settings.GoogleRedirectUri); MongoGoogleplusComments _GoogleplusComments = new MongoGoogleplusComments(); try { string _Comments = ObjoAuthTokenGPlus.APIWebRequestToGetUserInfo(Globals.strGetCommentListByActivityId.Replace("[ActivityId]", feedId) + "?key=" + settings.GoogleApiKey, AccessToken); JObject J_Comments = JObject.Parse(_Comments); List <MongoGoogleplusComments> lstGoogleplusComments = new List <MongoGoogleplusComments>(); foreach (var item in J_Comments["items"]) { try { _GoogleplusComments.Id = ObjectId.GenerateNewId(); _GoogleplusComments.Comment = item["object"]["content"].ToString(); _GoogleplusComments.CommentId = item["id"].ToString(); _GoogleplusComments.CreatedDate = Convert.ToDateTime(item["published"]).ToString("yyyy/MM/dd HH:mm:ss"); _GoogleplusComments.FeedId = feedId; _GoogleplusComments.FromId = item["actor"]["id"].ToString(); _GoogleplusComments.FromImageUrl = item["actor"]["image"]["url"].ToString(); _GoogleplusComments.FromName = item["actor"]["url"].ToString(); _GoogleplusComments.FromUrl = item["actor"]["url"].ToString(); _GoogleplusComments.GplusUserId = profileId; lstGoogleplusComments.Add(_GoogleplusComments); //if (!objGoogleplusCommentsRepository.IsExist(_GoogleplusComments.CommentId)) //{ // objGoogleplusCommentsRepository.Add(_GoogleplusComments); //} } catch (Exception ex) { _logger.LogError(ex.Message); } } gplusCommentRepo.AddList(lstGoogleplusComments); } catch (Exception ex) { } }
public void GetGooglePlusComments(string feedId, string AccessToken, string profileId) { oAuthTokenGPlus ObjoAuthTokenGPlus = new oAuthTokenGPlus(); Domain.Socioboard.MongoDomain.GoogleplusComments _GoogleplusComments = new Domain.Socioboard.MongoDomain.GoogleplusComments(); try { string _Comments = ObjoAuthTokenGPlus.APIWebRequestToGetUserInfo(Globals.strGetCommentListByActivityId.Replace("[ActivityId]", feedId) + "?key=" + ConfigurationManager.AppSettings["Api_Key"].ToString(), AccessToken); JObject J_Comments = JObject.Parse(_Comments); List <Domain.Socioboard.MongoDomain.GoogleplusComments> lstGoogleplusComments = new List <Domain.Socioboard.MongoDomain.GoogleplusComments>(); foreach (var item in J_Comments["items"]) { try { _GoogleplusComments.Id = ObjectId.GenerateNewId(); _GoogleplusComments.Comment = item["object"]["content"].ToString(); _GoogleplusComments.CommentId = item["id"].ToString(); _GoogleplusComments.CreatedDate = Convert.ToDateTime(item["published"]).ToString("yyyy/MM/dd HH:mm:ss"); _GoogleplusComments.FeedId = feedId; _GoogleplusComments.FromId = item["actor"]["id"].ToString(); _GoogleplusComments.FromImageUrl = item["actor"]["image"]["url"].ToString(); _GoogleplusComments.FromName = item["actor"]["url"].ToString(); _GoogleplusComments.FromUrl = item["actor"]["url"].ToString(); _GoogleplusComments.GplusUserId = profileId; lstGoogleplusComments.Add(_GoogleplusComments); //if (!objGoogleplusCommentsRepository.IsExist(_GoogleplusComments.CommentId)) //{ // objGoogleplusCommentsRepository.Add(_GoogleplusComments); //} } catch (Exception ex) { logger.Error(ex.Message); } } gplusCommentRepo.AddList(lstGoogleplusComments); } catch (Exception ex) { } }
public static void GetInstagramSelfFeeds(string instagramId, string accessToken, Helper.AppSettings _appSettings) { MongoRepository instagarmCommentRepo = new MongoRepository("InstagramComment", _appSettings); MongoRepository instagramFeedRepo = new MongoRepository("InstagramFeed", _appSettings); try { Users userInstagram = new Users(); Media _Media = new Media(); InstagramResponse <Comment[]> usercmts = new InstagramResponse <Comment[]>(); CommentController objComment = new CommentController(); LikesController objLikes = new LikesController(); string feeds = _Media.UserResentFeeds(instagramId, accessToken); if (feeds != null) { JObject feed_data = JObject.Parse(feeds); foreach (var item in feed_data["data"]) { try { Domain.Socioboard.Models.Mongo.InstagramFeed objInstagramFeed = new Domain.Socioboard.Models.Mongo.InstagramFeed(); try { objInstagramFeed.FeedDate = Convert.ToDouble(item["created_time"].ToString()); } catch { } try { objInstagramFeed.FeedId = item["id"].ToString(); } catch { } try { objInstagramFeed.Type = item["type"].ToString(); if (objInstagramFeed.Type == "video") { objInstagramFeed.VideoUrl = item["videos"]["standard_resolution"]["url"].ToString(); } } catch { } try { objInstagramFeed.FeedImageUrl = item["images"]["standard_resolution"]["url"].ToString(); } catch { } try { objInstagramFeed.InstagramId = instagramId; } catch { } try { objInstagramFeed.LikeCount = Int32.Parse(item["likes"]["count"].ToString()); } catch { } try { objInstagramFeed.CommentCount = Int32.Parse(item["comments"]["count"].ToString()); } catch { } try { string str = item["user_has_liked"].ToString(); if (str.ToLower() == "false") { objInstagramFeed.IsLike = 0; } else { objInstagramFeed.IsLike = 1; } } catch { } try { objInstagramFeed.AdminUser = item["user"]["username"].ToString(); } catch { } try { objInstagramFeed.Feed = item["caption"]["text"].ToString(); } catch { } try { objInstagramFeed.ImageUrl = item["user"]["profile_picture"].ToString(); } catch { } try { objInstagramFeed.FromId = item["user"]["id"].ToString(); } catch { } try { objInstagramFeed.FeedUrl = item["link"].ToString(); } catch { } var ret = instagramFeedRepo.Find <Domain.Socioboard.Models.Mongo.InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId)); var task = Task.Run(async() => { return(await ret); }); int count = task.Result.Count; if (count < 1) { instagramFeedRepo.Add(objInstagramFeed); } else { FilterDefinition <BsonDocument> filter = new BsonDocument("FeedId", objInstagramFeed.FeedId); var update = Builders <BsonDocument> .Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl); instagramFeedRepo.Update <Domain.Socioboard.Models.Mongo.InstagramFeed>(update, filter); } List <Domain.Socioboard.Models.Mongo.InstagramComment> lstInstagramComment = new List <Domain.Socioboard.Models.Mongo.InstagramComment>(); usercmts = objComment.GetComment(objInstagramFeed.FeedId, accessToken); for (int cmt = 0; cmt < usercmts.data.Count(); cmt++) { try { Domain.Socioboard.Models.Mongo.InstagramComment objInstagramComment = new Domain.Socioboard.Models.Mongo.InstagramComment(); try { objInstagramComment.Comment = usercmts.data[cmt].text; } catch { } try { objInstagramComment.CommentDate = Convert.ToDouble(usercmts.data[cmt].created_time.ToString()); } catch { } try { objInstagramComment.CommentId = usercmts.data[cmt].id; } catch { } try { objInstagramComment.FeedId = objInstagramFeed.FeedId; } catch { } try { objInstagramComment.InstagramId = instagramId; } catch { } try { objInstagramComment.FromName = usercmts.data[cmt].from.username; } catch { } try { objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture; } catch { } lstInstagramComment.Add(objInstagramComment); } catch (Exception ex) { } } instagarmCommentRepo.AddList(lstInstagramComment); } catch (Exception ex) { } } } } catch (Exception ex) { } }
public void GetInstagramFeeds(Domain.Socioboard.Domain.InstagramAccount objInsAccount) { MongoRepository instagarmCommentRepo = new MongoRepository("InstagramComment"); MongoRepository instagramFeedRepo = new MongoRepository("InstagramFeed"); try { GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users(); InstagramResponse<InstagramMedia[]> userinf2 = userInstagram.CurrentUserFeed("", "", "30", objInsAccount.AccessToken); InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>(); CommentController objComment = new CommentController(); LikesController objLikes = new LikesController(); if (userinf2 != null) { for (int j = 0; j < userinf2.data.Count(); j++) { try { objInstagramFeed = new Domain.Socioboard.MongoDomain.InstagramFeed(); //objInstagramFeed.EntryDate = DateTime.Now; try { // objInstagramFeed.Id = ObjectId.GenerateNewId(); objInstagramFeed.strId = ObjectId.GenerateNewId().ToString(); } catch { } try { objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString(); } catch { } try { objInstagramFeed.FeedId = userinf2.data[j].id; } catch { } try { objInstagramFeed.Type = userinf2.data[j].type.ToString(); if (objInstagramFeed.Type == "video") { objInstagramFeed.VideoUrl = userinf2.data[j].videos.standard_resolution.url.ToString(); } } catch { } try { objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString(); } catch { } try { objInstagramFeed.InstagramId = objInsAccount.InstagramId; } catch { } try { objInstagramFeed.LikeCount = userinf2.data[j].likes.count; } catch { } try { objInstagramFeed.CommentCount = userinf2.data[j].comments.count; } catch { } try { string str = userinf2.data[j].user_has_liked.ToString(); if (str == "False") { objInstagramFeed.IsLike = 0; } else { objInstagramFeed.IsLike = 1; } } catch { } try { objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username; } catch { } try { objInstagramFeed.Feed = userinf2.data[j].caption.text; } catch { } try { objInstagramFeed.ImageUrl = userinf2.data[j].caption.from.profile_picture; } catch { } try { objInstagramFeed.FromId = userinf2.data[j].caption.from.id; } catch { } try { objInstagramFeed.FeedUrl = userinf2.data[j].link; } catch { } //try //{ // objInstagramFeed.UserId = objInsAccount.UserId.; //} //catch { } var ret = instagramFeedRepo.Find<Domain.Socioboard.MongoDomain.InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId)); var task = Task.Run(async () => { return await ret; }); int count = task.Result.Count; if (count < 1) { instagramFeedRepo.Add(objInstagramFeed); } else { FilterDefinition<BsonDocument> filter = new BsonDocument("FeedId", objInstagramFeed.FeedId); var update = Builders<BsonDocument>.Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl); instagramFeedRepo.Update<Domain.Socioboard.MongoDomain.InstagramFeed>(update, filter); } //if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId)) //{ // objInstagramFeedRepository.addInstagramFeed(objInstagramFeed); //} List<Domain.Socioboard.MongoDomain.InstagramComment> lstInstagramComment = new List<Domain.Socioboard.MongoDomain.InstagramComment>(); usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken); for (int cmt = 0; cmt < usercmts.data.Count(); cmt++) { try { Domain.Socioboard.MongoDomain.InstagramComment objInstagramComment = new Domain.Socioboard.MongoDomain.InstagramComment(); try { objInstagramComment.Comment = usercmts.data[cmt].text; } catch { } try { objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString(); } catch { } try { objInstagramComment.CommentId = usercmts.data[cmt].id; } catch { } //try //{ // objInstagramComment.EntryDate = DateTime.UtcNow.ToString(); //} //catch { } try { objInstagramComment.FeedId = userinf2.data[j].id; } catch { } try { objInstagramComment.Id = ObjectId.GenerateNewId(); objInstagramComment.strId = ObjectId.GenerateNewId().ToString(); } catch { } try { objInstagramComment.InstagramId = objInsAccount.InstagramId; } catch { } try { // objInstagramComment.UserId = objInsAccount.UserId; } catch { } try { objInstagramComment.FromName = usercmts.data[cmt].from.username; } catch { } try { objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture; } catch { } lstInstagramComment.Add(objInstagramComment); } catch (Exception ex) { logger.Error(ex.StackTrace); } } instagarmCommentRepo.AddList(lstInstagramComment); } catch (Exception ex) { logger.Error(ex.Message); } } } } catch (Exception ex) { logger.Error(ex.Message); } }
public void GetInstagramSelfFeeds(string instagramId, string accessToken) { MongoRepository instagarmCommentRepo = new MongoRepository("InstagramComment"); MongoRepository instagramFeedRepo = new MongoRepository("InstagramFeed"); try { GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users(); GlobusInstagramLib.Instagram.Core.MediaMethods.Media _Media = new GlobusInstagramLib.Instagram.Core.MediaMethods.Media(); InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>(); CommentController objComment = new CommentController(); LikesController objLikes = new LikesController(); string feeds = _Media.UserResentFeeds(instagramId, accessToken); if (feeds != null) { JObject feed_data = JObject.Parse(feeds); foreach (var item in feed_data["data"]) { try { Domain.Socioboard.MongoDomain.InstagramFeed objInstagramFeed = new Domain.Socioboard.MongoDomain.InstagramFeed(); try { objInstagramFeed.FeedDate = item["created_time"].ToString(); } catch { } try { objInstagramFeed.FeedId = item["id"].ToString(); } catch { } try { objInstagramFeed.Type = item["type"].ToString(); if (objInstagramFeed.Type == "video") { objInstagramFeed.VideoUrl = item["videos"]["standard_resolution"]["url"].ToString(); } } catch { } try { objInstagramFeed.FeedImageUrl = item["images"]["standard_resolution"]["url"].ToString(); } catch { } try { objInstagramFeed.InstagramId = instagramId; } catch { } try { objInstagramFeed.LikeCount = Int32.Parse(item["likes"]["count"].ToString()); } catch { } try { objInstagramFeed.CommentCount = Int32.Parse(item["comments"]["count"].ToString()); } catch { } try { string str = item["user_has_liked"].ToString(); if (str.ToLower() == "false") { objInstagramFeed.IsLike = 0; } else { objInstagramFeed.IsLike = 1; } } catch { } try { objInstagramFeed.AdminUser = item["user"]["username"].ToString(); } catch { } try { objInstagramFeed.Feed = item["caption"]["text"].ToString(); } catch { } try { objInstagramFeed.ImageUrl = item["user"]["profile_picture"].ToString(); } catch { } try { objInstagramFeed.FromId = item["user"]["id"].ToString(); } catch { } try { objInstagramFeed.FeedUrl = item["link"].ToString(); } catch { } var ret = instagramFeedRepo.Find<Domain.Socioboard.MongoDomain.InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId)); var task = Task.Run(async () => { return await ret; }); int count = task.Result.Count; if (count < 1) { instagramFeedRepo.Add(objInstagramFeed); } else { FilterDefinition<BsonDocument> filter = new BsonDocument("FeedId", objInstagramFeed.FeedId); var update = Builders<BsonDocument>.Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl); instagramFeedRepo.Update<Domain.Socioboard.MongoDomain.InstagramFeed>(update, filter); } List<Domain.Socioboard.MongoDomain.InstagramComment> lstInstagramComment = new List<Domain.Socioboard.MongoDomain.InstagramComment>(); usercmts = objComment.GetComment(objInstagramFeed.FeedId, accessToken); for (int cmt = 0; cmt < usercmts.data.Count(); cmt++) { try { Domain.Socioboard.MongoDomain.InstagramComment objInstagramComment = new Domain.Socioboard.MongoDomain.InstagramComment(); try { objInstagramComment.Comment = usercmts.data[cmt].text; } catch { } try { objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString(); } catch { } try { objInstagramComment.CommentId = usercmts.data[cmt].id; } catch { } try { objInstagramComment.FeedId = objInstagramFeed.FeedId; } catch { } try { objInstagramComment.InstagramId = instagramId; } catch { } try { objInstagramComment.FromName = usercmts.data[cmt].from.username; } catch { } try { objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture; } catch { } lstInstagramComment.Add(objInstagramComment); } catch (Exception ex) { } } instagarmCommentRepo.AddList(lstInstagramComment); } catch (Exception ex) { } } } } catch (Exception ex) { } }
/// <summary> /// /// </summary> /// <param name="GplusTagId"></param> /// <param name="BoardId"></param> /// <param name="_redisCache"></param> /// <param name="settings"></param> /// <param name="_logger"></param> /// <returns></returns> public static List <MongoBoardGplusFeeds> AddBoardGplusTagFeeds(string GplusTagId, string BoardId, Helper.AppSettings settings, ILogger _logger) { MongoRepository boardrepo = new MongoRepository("MongoBoardGplusFeeds", settings); List <MongoBoardGplusFeeds> GplusFeeds = new List <MongoBoardGplusFeeds>(); try { JObject RecentActivities = JObject.Parse(GplusTagSearch.GooglePlusgetUserRecentActivitiesByHashtag(GplusTagId, settings.GoogleApiKey)); foreach (JObject obj in RecentActivities["items"]) { MongoBoardGplusFeeds bgpfeed = new MongoBoardGplusFeeds(); bgpfeed.Id = ObjectId.GenerateNewId(); bgpfeed.Gplusboardaccprofileid = BoardId; try { bgpfeed.Feedlink = obj["url"].ToString(); } catch { } try { foreach (JObject att in JArray.Parse(obj["object"]["attachments"].ToString())) { if (att["objectType"].ToString().Equals("photo")) { bgpfeed.Imageurl = att["fullImage"]["url"].ToString() + ","; } } } catch { } try { bgpfeed.Publishedtime = Domain.Socioboard.Helpers.SBHelper.ConvertToUnixTimestamp(DateTime.Parse(obj["published"].ToString())); } catch { } try { bgpfeed.Title = obj["title"].ToString(); } catch { } try { bgpfeed.Feedid = obj["id"].ToString(); } catch { } try { bgpfeed.FromId = obj["actor"]["id"].ToString(); } catch { } try { bgpfeed.FromName = obj["actor"]["displayName"].ToString(); } catch { } try { bgpfeed.FromPicUrl = obj["actor"]["image"]["url"].ToString(); } catch { } GplusFeeds.Add(bgpfeed); } try { boardrepo.AddList <MongoBoardGplusFeeds>(GplusFeeds); } catch { } } catch { } return(GplusFeeds); }
/// <summary> ///Will fetch hasttag feeds from twitter and add to mongo db... /// </summary> /// <param name="HashTag">Twitter Keyword</param> /// <param name="BoardTagid">BoardId</param> /// <param name="LastTweetId"></param> /// <param name="settings"></param> /// <param name="_logger"></param> /// <returns></returns> public static List <MongoBoardTwtFeeds> AddBoardTwitterHashTagFeeds(string HashTag, string BoardTagid, string LastTweetId, Helper.AppSettings settings, ILogger _logger) { MongoRepository mongorepo = new MongoRepository("MongoBoardTwtFeeds", settings); List <MongoBoardTwtFeeds> twtFeedsList = new List <MongoBoardTwtFeeds>(); string timeline = TwitterHashTag.TwitterBoardHashTagSearch(HashTag, LastTweetId); int i = 0; if (!string.IsNullOrEmpty(timeline) && !timeline.Equals("[]")) { foreach (JObject obj in JArray.Parse(timeline)) { MongoBoardTwtFeeds twitterfeed = new MongoBoardTwtFeeds(); twitterfeed.Id = ObjectId.GenerateNewId(); i++; try { twitterfeed.Feedurl = JArray.Parse(obj["extended_entities"]["media"].ToString())[0]["url"].ToString(); } catch { try { twitterfeed.Feedurl = JArray.Parse(obj["entities"]["urls"].ToString())[0]["expanded_url"].ToString(); } catch (Exception e) { _logger.LogError(e.Message); _logger.LogError(e.StackTrace); } } try { twitterfeed.Imageurl = JArray.Parse(obj["extended_entities"]["media"].ToString())[0]["media_url"].ToString(); } catch { try { twitterfeed.Imageurl = JArray.Parse(obj["entities"]["media"].ToString())[0]["media_url"].ToString(); } catch (Exception e) { _logger.LogError(e.Message); _logger.LogError(e.StackTrace); } } try { foreach (JObject tag in JArray.Parse(obj["entities"]["hashtags"].ToString())) { try { twitterfeed.Hashtags = tag["text"].ToString() + ","; } catch (Exception e) { _logger.LogError(e.Message); _logger.LogError(e.StackTrace); } } } catch { } try { twitterfeed.Text = obj["text"].ToString(); } catch (Exception e) { _logger.LogError(e.Message); _logger.LogError(e.StackTrace); } try { twitterfeed.Retweetcount = Convert.ToInt32(obj["retweet_count"].ToString()); } catch (Exception e) { _logger.LogError(e.Message); _logger.LogError(e.StackTrace); } try { twitterfeed.Favoritedcount = Convert.ToInt32(obj["favorite_count"].ToString()); } catch (Exception e) { _logger.LogError(e.Message); _logger.LogError(e.StackTrace); } try { string Const_TwitterDateTemplate = "ddd MMM dd HH:mm:ss +ffff yyyy"; twitterfeed.Publishedtime = Domain.Socioboard.Helpers.SBHelper.ConvertToUnixTimestamp(DateTime.ParseExact((string)obj["created_at"], Const_TwitterDateTemplate, new System.Globalization.CultureInfo("en-US"))); } catch (Exception e) { _logger.LogError(e.Message); _logger.LogError(e.StackTrace); } try { twitterfeed.Feedid = obj["id_str"].ToString(); } catch (Exception ex) { try { twitterfeed.Feedid = obj["id"].ToString(); } catch (Exception e) { _logger.LogError(e.Message); _logger.LogError(e.StackTrace); } } try { twitterfeed.FromId = obj["user"]["id_str"].ToString(); } catch (Exception ex) { try { twitterfeed.FromId = obj["user"]["id"].ToString(); } catch (Exception e) { _logger.LogError(e.Message); _logger.LogError(e.StackTrace); } } try { twitterfeed.FromName = obj["user"]["screen_name"].ToString(); } catch (Exception e) { _logger.LogError(e.Message); _logger.LogError(e.StackTrace); } try { twitterfeed.FromPicUrl = obj["user"]["profile_image_url"].ToString(); } catch (Exception e) { _logger.LogError(e.Message); _logger.LogError(e.StackTrace); } twitterfeed.Isvisible = true; twitterfeed.Twitterprofileid = BoardTagid; twtFeedsList.Add(twitterfeed); } try { mongorepo.AddList <MongoBoardTwtFeeds>(twtFeedsList); } catch (Exception ex) { _logger.LogError(ex.StackTrace); } } return(twtFeedsList); }
/// <summary> /// news api implementation /// </summary> /// <param name="keywords"></param> /// <param name="userId"></param> /// <param name="logger"></param> /// <param name="env"></param> /// <param name="appSettings"></param> /// <returns></returns> public static async Task <IEnumerable <RssNewsContentsFeeds> > FindUrl(string keywords, string userId, ILogger logger, IHostingEnvironment env, Helper.AppSettings appSettings) { IList <RssNewsContentsFeeds> finalLinkList = new List <RssNewsContentsFeeds>(); try { var rssFeedRepository = new MongoRepository("RssNewsContentsFeeds", appSettings); List <string> keywordCollections = null; if (keywords != null) { keywordCollections = keywords.Split(',').ToList(); } var day = 30; if (DateTime.UtcNow.Day > 1) { day = DateTime.UtcNow.Day - 1; } var newsApiClient = new NewsApiClient(appSettings.NewsApiKey); if (keywordCollections != null) { foreach (var keyword in keywordCollections) { var articlesResponse = newsApiClient.GetEverything(new EverythingRequest { Q = keyword, SortBy = SortBys.PublishedAt, Language = Languages.EN, From = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, day) }); if (articlesResponse.Articles.Count == 0) { logger.LogError(articlesResponse.Error?.ToString()); var temp = await rssFeedRepository.Find <RssNewsContentsFeeds>(x => x.keywords.Contains(keyword)); finalLinkList = temp.Skip(temp.Count - 20).Take(20 / keywordCollections.Count).ToList(); } else { foreach (var item in articlesResponse.Articles) { var rssFeed = new RssNewsContentsFeeds { keywords = keyword, Link = item.Url, Title = item.Title, Image = item.UrlToImage, PublishingDate = item.PublishedAt?.ToString(System.Globalization.CultureInfo.CurrentCulture) }; finalLinkList.Add(rssFeed); } try { await rssFeedRepository.AddList(finalLinkList); } catch (Exception ex) { logger.LogError(ex.StackTrace); } } finalLinkList = finalLinkList.Take(20 / keywordCollections.Count).ToList(); } } } catch (Exception ex) { logger.LogError(ex.StackTrace); } return(finalLinkList.Take(20)); }