private List <TwitterTweet> GetMentionedTweetsAndReplies(List <Status> mentionTweets, List <Status> filterTweets) { List <TwitterTweet> result = new List <TwitterTweet>(); foreach (Status mentionTweet in mentionTweets) { TwitterTweet entry = new TwitterTweet(); entry.AssessmentId = _assessment.Id; entry.Tweet = mentionTweet.Text; entry.TweetTimestamp = mentionTweet.CreatedAt; entry.TweetUrl = "https://twitter.com/" + mentionTweet.User.ScreenNameResponse + "/status/" + mentionTweet.StatusID.ToString(); entry.TwitterId = mentionTweet.User.ScreenNameResponse; var replyTweets = filterTweets.Where(x => x.InReplyToStatusID == mentionTweet.StatusID).ToList(); if (replyTweets.Count != 0) { Status firstReplyTweet = replyTweets.OrderBy(x => x.CreatedAt).ToList()[0]; entry.Response = firstReplyTweet.Text; entry.ResponseTimestamp = firstReplyTweet.CreatedAt; entry.ResponseUrl = "https://twitter.com/" + firstReplyTweet.User.ScreenNameResponse + "/status/" + firstReplyTweet.StatusID.ToString();; } result.Add(entry); } // Remove duplicate if there is List <TwitterTweet> distinctItems = result.GroupBy(x => x.TweetUrl).Select(y => y.First()).ToList(); return(distinctItems); }
public static void LoadNews(string filename) { using (TwitterDbContext db = new TwitterDbContext()) { long? minId = (from t in db.Tweets where t.ProfileId == -1 select (long?)t.Id).Min(); if (!minId.HasValue) minId = 0; using (StreamReader sr = new StreamReader(filename)) { while (!sr.EndOfStream) { string title = sr.ReadLine(); string[] tokens = title.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length != 3) continue; TwitterTweet tweet = new TwitterTweet { Id = (--minId).Value, ProfileId = -2, CreatedBy = tokens[0], CreatedAt = DateTime.Parse(tokens[1]), Text = tokens[2] }; db.Entry<TwitterTweet>(tweet).State = System.Data.Entity.EntityState.Added; } } db.SaveChanges(); } }
private void WriteTwitterPartial(int entryNextPosition, int rowPostion, List <TwitterTweet> entries, String fileName) { var existingFile = new FileInfo(fileName); using (var package = new ExcelPackage(existingFile)) { // Get the work book in the file var workBook = package.Workbook; if (workBook != null) { if (workBook.Worksheets.Count > 0) { var currentWorksheet = workBook.Worksheets["8 Twitter raw data"]; for (int i = 0; i < _rowPerTime; i++) { int index = i + entryNextPosition; if (index < entries.Count) { TwitterTweet entry = entries[index]; currentWorksheet.Cells[rowPostion, 1].Value = entry.Tweet; currentWorksheet.Cells[rowPostion, 2].Value = entry.TweetUrl; if (entry.TweetTimestamp != null) { currentWorksheet.Cells[rowPostion, 3].Value = ConvertToJson((DateTime)entry.TweetTimestamp); } if (entry.Response != null) { currentWorksheet.Cells[rowPostion, 4].Value = entry.Response; currentWorksheet.Cells[rowPostion, 5].Value = entry.ResponseUrl; if (entry.ResponseTimestamp != null) { currentWorksheet.Cells[rowPostion, 6].Value = ConvertToJson((DateTime)entry.ResponseTimestamp); } } } else { break; } rowPostion++; } package.Save(); } } } }