Example #1
0
        private Word PickWord(TwitterProfile profile, Word previousWord)
        {
            var  algorithm = _options.WordAlgorithms.PickAlgorithm(_random);
            Word word      = null;

            switch (algorithm)
            {
            case AlgorithmType.Random:
                word = PickWordRandom(profile);
                break;

            case AlgorithmType.ByProbability:
                word = PickWordByProbability(profile);
                break;

            case AlgorithmType.ByProbabilityWithPrediction:
                word = previousWord == null?
                       PickWordByProbability(profile) :
                           PickWordByProbabilityWithPrediction(profile, previousWord);

                break;
            }

            return(word);
        }
Example #2
0
        public bool ProfileTimeLineHasTweets(TwitterProfile profile)
        {
            if (profile == null)
            {
                return(false);
            }

            if (profile.Name == null)
            {
                return(false);
            }

            var user = User.GetUserFromScreenName(profile.Name);

            if (user == null)
            {
                return(false);
            }

            var timelineParameter = Timeline.CreateHomeTimelineParameter();

            timelineParameter.ExcludeReplies  = true;
            timelineParameter.TrimUser        = true;
            timelineParameter.IncludeEntities = false;

            var timeLine = Timeline.GetUserTimeline(user);

            return(timeLine != null);
        }
Example #3
0
        private Word PickWordByProbability(TwitterProfile profile)
        {
            var weights = profile.Words.Select(w => w.Occurrence).ToList();

            var index = AlgorithmSelector.PickIndexWeighted(weights, _random);

            return(profile.Words[index].Word);
        }
Example #4
0
        public async Task <IEnumerable <Tweet> > GetAllTweetsFromProfile(TwitterProfile profile)
        {
            var tweets = await(from tweet in _context.Status
                               where tweet.Type == StatusType.User &&
                               tweet.ScreenName == profile.Name
                               select tweet).ToListAsync();

            return(tweets.Select(tweet => new Tweet(tweet.Text)));
        }
Example #5
0
        public void AddProfile(TwitterProfile profile, int occurrence)
        {
            if (Profiles.Any(p => p.Name == profile.Name))
            {
                return;
            }

            ProfileOccurances.Add(new ProfileOccurrance(profile, this, occurrence));
        }
Example #6
0
        public ProfileOccurrance(TwitterProfile profile, BotOptions options)
        {
            Profile   = profile;
            ProfileId = profile.Id.Value;

            BotOptions   = options;
            BotOptionsId = options.Id.Value;

            Occurrence = 1;
        }
Example #7
0
 public Tweet(long twitterId, string text, DateTime createdAt, int userId, TwitterProfile user, int quoteCount, int replyCount, int retweetCount, int favoriteCount)
 {
     TwitterId     = twitterId;
     Text          = text;
     CreatedAt     = createdAt;
     UserId        = userId;
     User          = user;
     QuoteCount    = quoteCount;
     ReplyCount    = replyCount;
     RetweetCount  = retweetCount;
     FavoriteCount = favoriteCount;
 }
Example #8
0
        public byte[] SaveProfileImageToServer(TwitterProfile profile)
        {
            var profileImage = "https://twitter.com/" + profile.Name + "/profile_image?size=original";

            using (WebClient client = new WebClient())
            {
                client.DownloadFile(new Uri(profileImage), @"profile.jpg");
            }

            string path = @"profile.jpg";

            return(File.ReadAllBytes(path));
        }
Example #9
0
        public WordOccurrence(Word word, TwitterProfile profile)
        {
            // TODO: Null-checks

            Word   = word;
            WordId = word.Id.Value;

            TwitterProfile   = profile;
            TwitterProfileId = profile.Id.Value;

            NextWordOccurrences = new List <NextWordOccurrence>();
            Occurrence          = 1;
        }
Example #10
0
        private Word PickWordByProbabilityWithPrediction(TwitterProfile profile, Word previousWord)
        {
            var word = profile.Words.SingleOrDefault(w => w.Word.Equals(previousWord));

            if (word?.NextWordOccurrences == null || word.NextWordOccurrences.Count == 0)
            {
                return(PickWordByProbability(profile));
            }

            var weights = word.NextWordOccurrences.Select(n => n.Occurrence).ToList();
            var index   = AlgorithmSelector.PickIndexWeighted(weights, _random);

            return(word.NextWordOccurrences[index].Word);
        }
Example #11
0
        private Word PickWordRandom(TwitterProfile profile)
        {
            var index = _random.Next(profile.Words.Count);

            return(profile.Words[index].Word);
        }
Example #12
0
        public async Task <bool> DoesTwitterUserExist(TwitterProfile profile)
        {
            var user = (await GetTwitterProfile(profile.Name));

            return(user != null);
        }
Example #13
0
 public async Task <string> GetTwitterUserName(TwitterProfile profile)
 {
     return((await GetTwitterProfile(profile.Name)).Name);
 }