public bool AddTwittertrendingHashTagFeedsFBPlugin(string HashTag, string trendingTagid, string LastTweetId, Helper.AppSettings _appSettings) { //Helper.AppSettings _appSettings; MongoRepository mongorepo = new MongoRepository("MongoBoardTwtFeeds", _appSettings); bool output = false; 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) { } } 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) { } } try { foreach (JObject tag in JArray.Parse(obj["entities"]["hashtags"].ToString())) { try { twitterfeed.Hashtags = tag["text"].ToString() + ","; } catch (Exception e) { } } } catch { } try { twitterfeed.Text = obj["text"].ToString(); } catch (Exception e) { } try { twitterfeed.Retweetcount = Convert.ToInt32(obj["retweet_count"].ToString()); } catch (Exception e) { } try { twitterfeed.Favoritedcount = Convert.ToInt32(obj["favorite_count"].ToString()); } catch (Exception e) { } 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) { } try { twitterfeed.Feedid = obj["id_str"].ToString(); } catch (Exception ex) { try { twitterfeed.Feedid = obj["id"].ToString(); } catch (Exception e) { } } try { twitterfeed.FromId = obj["user"]["id_str"].ToString(); } catch (Exception ex) { try { twitterfeed.FromId = obj["user"]["id"].ToString(); } catch (Exception e) { } } try { twitterfeed.FromName = obj["user"]["screen_name"].ToString(); } catch (Exception e) { } try { twitterfeed.FromPicUrl = obj["user"]["profile_image_url"].ToString(); } catch (Exception e) { } twitterfeed.Isvisible = true; twitterfeed.Twitterprofileid = trendingTagid; var ret = mongorepo.Find <MongoBoardTwtFeeds>(t => t.Feedid == twitterfeed.Feedid); var task = Task.Run(async() => { return(await ret); }); int count = task.Result.Count; if (count < 1) { try { mongorepo.Add <MongoBoardTwtFeeds>(twitterfeed); } catch (Exception e) { } } else { FilterDefinition <BsonDocument> filter = new BsonDocument("Feedid", twitterfeed.Feedid); var update = Builders <BsonDocument> .Update .Set("Favoritedcount", twitterfeed.Favoritedcount) .Set("FromPicUrl", twitterfeed.FromPicUrl) .Set("Retweetcount", twitterfeed.Retweetcount); mongorepo.Update <Domain.Socioboard.Models.Mongo.MongoBoardTwtFeeds>(update, filter); } output = true; } } return(output); }
public bool AddBoardTwitterHashTagFeeds(string HashTag, string BoardTagid, string LastTweetId, Helper.AppSettings settings, ILogger _logger) { MongoRepository mongorepo = new MongoRepository("MongoBoardTwtFeeds", settings); bool output = false; 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; try { mongorepo.Add <MongoBoardTwtFeeds>(twitterfeed); } catch (Exception e) { } output = true; } } return(output); }
public static void addContentfeedsdata(string keyword) { MongoRepository mongorepo = new MongoRepository("RssNewsContentsFeeds"); string timeline = TwitterHashTag.TwitterBoardHashTagSearch(keyword, null); int i = 0; if (!string.IsNullOrEmpty(timeline) && !timeline.Equals("[]")) { foreach (JObject obj in JArray.Parse(timeline)) { RssNewsContentsFeeds contentFeedsDet = new RssNewsContentsFeeds(); contentFeedsDet.Id = ObjectId.GenerateNewId(); i++; try { contentFeedsDet.Link = JArray.Parse(obj["entities"]["expanded_url"].ToString())[0]["url"].ToString(); } catch { try { contentFeedsDet.Link = JArray.Parse(obj["entities"]["urls"].ToString())[0]["expanded_url"].ToString(); } catch (Exception e) { } } try { contentFeedsDet.Image = JArray.Parse(obj["extended_entities"]["media"].ToString())[0]["media_url"].ToString(); } catch { try { contentFeedsDet.Image = JArray.Parse(obj["entities"]["media"].ToString())[0]["media_url"].ToString(); } catch (Exception e) { } } try { contentFeedsDet.Title = obj["text"].ToString(); } catch (Exception e) { } try { string Const_TwitterDateTemplate = "ddd MMM dd HH:mm:ss +ffff yyyy"; contentFeedsDet.PublishingDate = Domain.Socioboard.Helpers.SBHelper.ConvertToUnixTimestamp(DateTime.ParseExact((string)obj["created_at"], Const_TwitterDateTemplate, new System.Globalization.CultureInfo("en-US"))).ToString(); } catch (Exception e) { } contentFeedsDet.keywords = keyword; var ret = mongorepo.Find <RssNewsContentsFeeds>(t => t.Image == contentFeedsDet.Image); var task = Task.Run(async() => { return(await ret); }); int count = task.Result.Count; if (count < 1) { try { mongorepo.Add <RssNewsContentsFeeds>(contentFeedsDet); } catch (Exception e) { } } else { } } } }