コード例 #1
0
ファイル: Twitter.cs プロジェクト: sawyerit/drone
        /// <summary>
        /// Get all mentions and replies @GoDaddy
        /// Not used
        /// </summary>
        internal List <Mention> GetMentionsReplies()
        {
            int countPerPage; int pageCount;

            XMLUtility.GetPageResultCounts(Xml, "mentionsreplies", out countPerPage, out pageCount, 200, 1);
            TweetManager tm = new TweetManager();

            return(tm.GetMentionsAndReplies(countPerPage, pageCount, Utility.GetOAuthToken(Xml)));
        }
コード例 #2
0
ファイル: XMLUtilityTests.cs プロジェクト: sawyerit/drone
        public void TwitterUtility_GetPageResultCounts_DefaultsCorrectly()
        {
            Drone.Twitter.Components.Twitter t = new Twitter.Components.Twitter(new TwitterTestDataSource());
            int countPerPage; int pageCount;

            XMLUtility.GetPageResultCounts(new XmlDocument(), "twitter", out countPerPage, out pageCount, 100, 3);

            Assert.AreEqual(countPerPage, 100);
            Assert.AreEqual(pageCount, 3);
        }
コード例 #3
0
ファイル: XMLUtilityTests.cs プロジェクト: sawyerit/drone
        public void TwitterUtility_GetPageResultCounts()
        {
            Drone.Twitter.Components.Twitter t = new Twitter.Components.Twitter(new TwitterTestDataSource());
            int countPerPage; int pageCount;

            XMLUtility.GetPageResultCounts(t.Xml, "twitter", out countPerPage, out pageCount, 100, 3);

            Assert.AreEqual(countPerPage, 100);
            Assert.AreEqual(pageCount, 5);
        }
コード例 #4
0
ファイル: Twitter.cs プロジェクト: sawyerit/drone
        /// <summary>
        /// Get all tweets with "GoDaddy" in them.
        /// 100 per page, up to 15 pages if we loop and make seperate calls for each page
        /// </summary>
        internal Dictionary <int, List <Status> > GetAllMentionsByQuery(TwitterContext cont)
        {
            Dictionary <int, List <Status> > allTwitterMentions = new Dictionary <int, List <Status> >();

            if (XMLUtility.IsComponentEnabled(Xml, ProcessorName))
            {
                int countPerPage; int pageCount;
                TwitterDataSource data = new TwitterDataSource();
                TweetManager      tm   = new TweetManager();

                XMLUtility.GetPageResultCounts(Xml, ProcessorName, out countPerPage, out pageCount, 100, 3);
                List <Keyword> queries    = data.GetTweetQueries();
                bool           useSinceId = XMLUtility.UseSinceId(Xml, ProcessorName);

                //create backup of current keys in case of failure at db level
                lock (cont) cont.prevRunLatestTweetIDs = cont.LatestTweetIDs.ToDictionary(entry => entry.Key, entry => entry.Value);

                foreach (Keyword item in queries)
                {
                    try
                    {
                        long sinceId = 0;
                        if (useSinceId)
                        {
                            //get the last recorded id for this query and use it
                            if (!Object.Equals(cont, null))
                            {
                                lock (cont)
                                {
                                    if (cont.LatestTweetIDs.ContainsKey(item.KeywordId))
                                    {
                                        cont.LatestTweetIDs.TryGetValue(item.KeywordId, out sinceId);
                                    }
                                }
                            }
                        }

                        //call the mention object in the API wrapper
                        TwitterDataComponent _dataComponent = DroneDataComponent as TwitterDataComponent;
                        KeywordStatus        ks             = new KeywordStatus();
                        ks.KeywordId = item.KeywordId;

                        ks.StatusList = tm.GetTweetsByQuery(countPerPage, item.KeywordValue + (sinceId > 0 ? "&since_id=" + sinceId : string.Empty), Utility.GetOAuthToken(Xml));
                        allTwitterMentions.Add(ks.KeywordId, ks.StatusList);

                        _dataComponent.KeywordStatus = ks;
                        DroneDataSource.Process(_dataComponent);

                        //if there was a failure saving to the db, reset the since id to gather and try again
                        if (_dataComponent.SaveFailure)
                        {
                            lock (cont) cont.LatestTweetIDs = cont.prevRunLatestTweetIDs.ToDictionary(entry => entry.Key, entry => entry.Value);
                        }

                        //get the last id for this query and store it
                        if (!Object.Equals(cont, null) && allTwitterMentions.ContainsKey(item.KeywordId) && allTwitterMentions[item.KeywordId].Count > 0)
                        {
                            long latestID;
                            long.TryParse(allTwitterMentions[item.KeywordId][0].id.ToString(), out latestID);

                            lock (cont)
                            {
                                if (cont.LatestTweetIDs.ContainsKey(item.KeywordId))
                                {
                                    cont.LatestTweetIDs[item.KeywordId] = latestID;
                                }
                                else
                                {
                                    cont.LatestTweetIDs.Add(item.KeywordId, latestID);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionExtensions.LogError(e, "Twitter.GetAllMentionsByQuery()", "Keyword name: " + item.KeywordName);
                    }
                }
            }
            return(allTwitterMentions);
        }