static void Main()
        {
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            string tConsumerKey = "";
            string tConsumerSecret = "";
            string tAccessToken = "";
            string tAccessSecret = "";

            try
            {
                tConsumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"];
                tConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"];
                tAccessToken = ConfigurationManager.AppSettings["TwitterAccessToken"];
                tAccessSecret = ConfigurationManager.AppSettings["TwitterAccessSecret"];
            }
            catch (Exception)
            {
                throw new System.ArgumentException("Error with Twitter keys", "twitter");
            }

            //build twitter connection
            var twitService = new TweetSharp.TwitterService(tConsumerKey, tConsumerSecret, tAccessToken, tAccessSecret);

            //build options to check for mentions
            var mentionsOptions = new TweetSharp.ListTweetsMentioningMeOptions();
            mentionsOptions.Count = 20;
            mentionsOptions.SinceId = 300328033800306680;

            //get the mentions
            IEnumerable<TwitterStatus> mentions = twitService.ListTweetsMentioningMe(mentionsOptions);

            List<TwitterStatus> listOfStuff = mentions.ToList();
            listOfStuff.ForEach(
                x =>
                {
                    Console.WriteLine("Now gathering info about tweet #{0}.", x.Id);
                    Console.WriteLine("It is in response to tweet #{0}.", x.InReplyToStatusId);

                    var thatTweet = twitService.GetTweet(new GetTweetOptions { Id = (long)x.InReplyToStatusId });

                    Console.WriteLine("That tweet's text was {0}", thatTweet.Text);
                    Console.WriteLine("More importantly, heres the url it was referencing {0}", thatTweet.Entities.Urls[0].ExpandedValue);

                    string moveString = "not found";

                    if (x.Text.Contains("*"))
                    {
                        int startIndex = x.Text.IndexOf("*");
                        int endIndex = x.Text.LastIndexOf("*");
                        moveString = x.Text.Substring(startIndex, endIndex - startIndex + 1);
                    }
                    Console.WriteLine("The move attached to this tweet was {0}.", moveString);
                }
            );
            Console.WriteLine("End of new API stuff");
        }
Exemple #2
0
        private static void DoMining()
        {
            using (var db = new TwitterDataContext(_connStr))
            {
                var devTwitters = (from d in db.DevTwitterAccounts
                                   select d).ToList();
                foreach (var devAccount in devTwitters)
                {
                    ListTweetsOnListOptions listTweetOptions = new ListTweetsOnListOptions();

                    var service = new TwitterService(CONSUMER_KEY, CONSUMER_SECRET);
                    service.AuthenticateWith(ACCESS_TOKEN, ACCESS_SECRET);
                    var currentTweets = service.ListTweetsOnUserTimeline(
                        new ListTweetsOnUserTimelineOptions()
                        {
                            Count = 20,
                            ExcludeReplies = false,
                            IncludeRts = false,
                            ScreenName = "@" + devAccount.DevTwitterName,
                            SinceId = null,
                            MaxId = null
                        });

                    foreach (var tweet in currentTweets)
                    {
                        List<TwitterStatus> tweetsToInsert = new List<TwitterStatus>();
                        int? convIdToAddTo = null;

                        //We are basically going to keep on getting the reply-to tweets.
                        var currentTweet = tweet;
                        while (true)
                        {
                            if (currentTweet == null)
                                break;

                            List<Tweet> tweetExists;

                            tweetExists = (from t in db.Tweets
                                           where t.TweetTwitterId == currentTweet.Id
                                           select t).ToList();

                            if (tweetExists.Count > 0)
                            {
                                convIdToAddTo = tweetExists[0].TwitterConversationId;
                                break;
                            }
                            else
                            {
                                tweetsToInsert.Add(currentTweet);
                            }

                            if (currentTweet.InReplyToStatusId != null)
                            {
                                currentTweet = service.GetTweet(
                                    new GetTweetOptions()
                                    {
                                        Id = currentTweet.InReplyToStatusId.Value
                                    });
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (tweetsToInsert.Count > 0)
                        {
                            tweetsToInsert = tweetsToInsert.OrderBy(x => x.CreatedDate).ToList();

                            if (convIdToAddTo == null)
                            {
                                string title = String.Empty;

                                if (tweetsToInsert[0].Text.Length > 60)
                                {
                                    for (int i = 0; i < 60; i++)
                                    {
                                        title += tweetsToInsert[0].Text[i];
                                    }
                                    title += " (...)";
                                }
                                else
                                {
                                    title = tweetsToInsert[0].Text;
                                }

                                TwitterConversation conversation = new TwitterConversation();
                                conversation.TwitterConvTitle = title;
                                conversation.LastBlueResponder = tweet.Author.ScreenName;
                                conversation.LastDevResponseDate = tweet.CreatedDate;
                                conversation.TwitterConvAuthor = tweetsToInsert[0].Author.ScreenName;

                                conversation.BlizzAreaId = (from t in tweetsToInsert
                                                            from d in db.DevTwitterAccounts
                                                            where d.DevTwitterName.ToLower() == t.Author.ScreenName.ToLower()
                                                            select d.BlizzAreaId).ToList()[0];

                                foreach (var twitterTweet in tweetsToInsert)
                                {
                                    Tweet bpTweet = new Tweet();

                                    try
                                    {
                                        var devTwitter = (from d in db.DevTwitterAccounts
                                                          where d.DevTwitterName == twitterTweet.Author.ScreenName.Replace("@", "")
                                                          select d).Single();
                                        bpTweet.DevId = devTwitter.DevId;
                                    }
                                    catch (InvalidOperationException) { /*Then we simply leave DevId as null.*/ }

                                    bpTweet.TweetContent = twitterTweet.TextAsHtml;
                                    bpTweet.TweetDate = twitterTweet.CreatedDate;
                                    bpTweet.TweetTwitterId = twitterTweet.Id;
                                    bpTweet.TwitterUserName = twitterTweet.Author.ScreenName;
                                    bpTweet.TweetContentNonHtml = twitterTweet.Text;
                                    bpTweet.UserAvatarUrl = twitterTweet.Author.ProfileImageUrl;
                                    conversation.LastDevResponseDate = twitterTweet.CreatedDate;
                                    bpTweet.TwitterInResponseToId = twitterTweet.InReplyToStatusId;

                                    conversation.Tweets.Add(bpTweet);
                                }

                                db.TwitterConversations.InsertOnSubmit(conversation);
                                db.SubmitChanges();

                            }
                            else
                            {
                                foreach (var twitterTweet in tweetsToInsert)
                                {
                                    Tweet bpTweet = new Tweet();

                                    try
                                    {
                                        var devTwitter = (from d in db.DevTwitterAccounts
                                                          where d.DevTwitterName == twitterTweet.Author.ScreenName.Replace("@", "")
                                                          select d).Single();
                                        bpTweet.DevId = devTwitter.DevId;
                                    }
                                    catch (InvalidOperationException) { /*Then we simply leave DevId as null.*/ }

                                    bpTweet.TweetContent = twitterTweet.TextAsHtml;
                                    bpTweet.TweetDate = twitterTweet.CreatedDate;
                                    bpTweet.TweetTwitterId = twitterTweet.Id;
                                    bpTweet.TwitterUserName = twitterTweet.Author.ScreenName;
                                    bpTweet.TwitterConversationId = convIdToAddTo.Value;
                                    bpTweet.TweetContentNonHtml = twitterTweet.Text;
                                    bpTweet.UserAvatarUrl = twitterTweet.Author.ProfileImageUrl;
                                    bpTweet.TwitterInResponseToId = twitterTweet.InReplyToStatusId;

                                    var conversation = db.TwitterConversations.Where(x => x.Id == convIdToAddTo).Single();
                                    conversation.LastDevResponseDate = twitterTweet.CreatedDate;

                                    db.Tweets.InsertOnSubmit(bpTweet);
                                    db.SubmitChanges();
                                }
                            }
                        }

                    }

                }
            }
        }
Exemple #3
0
        private static void FixTweets()
        {
            var service = new TwitterService(CONSUMER_KEY, CONSUMER_SECRET);
            service.AuthenticateWith(ACCESS_TOKEN, ACCESS_SECRET);

            using (var db = new TwitterDataContext(_connStr))
            {
                var allTweets = (from t in db.Tweets
                                 where t.TwitterInResponseToId == null
                                 select t).ToList();
                allTweets.Reverse();
                Console.WriteLine(allTweets.Count);
                foreach (var tweet in allTweets)
                {
                    Console.WriteLine("{0}\n\n", tweet.TweetContent);
                    try
                    {
                        var desiredTweet = service.GetTweet(
                                    new GetTweetOptions()
                                    {
                                        Id = tweet.TweetTwitterId
                                    });
                        var desiredId = desiredTweet.InReplyToStatusId;
                        tweet.TwitterInResponseToId = desiredId;
                        db.SubmitChanges();
                        Console.WriteLine("Inserted. \n\n");
                    }
                    catch
                    {

                    }
                }
            }
        }