Esempio n. 1
0
        public static async Task <List <InstaUserShort> > GetFilteredUsersAsync(List <InstaUserShort> users, List <SearchModel> searches, IInstaApi api, int count)
        {
            var FilteredUsers = new List <InstaUserShort>();

            // Search for our results
            // In strings
            foreach (var search in searches)
            {
                if (search.InUsers)
                {
                    var _tempList = new List <InstaUserShort>();

                    search.GetInStrings().ForEach(inString =>
                    {
                        _tempList.AddRange(users.Where(u => (u.UserName + u.FullName).Contains(inString)));
                    });

                    search.GetExStrings().ForEach(exString =>
                    {
                        _tempList.RemoveAll(m => (m.UserName + m.FullName).Contains(exString));
                    });

                    FilteredUsers.AddRange(_tempList);
                }

                if (search.InHashtags)
                {
                    // No way to implement
                }

                if (search.InFollowingMe)
                {
                    var _tempList = new List <InstaUserShort>();

                    foreach (var u in users)
                    {
                        var isFollowingMe = await api.GetFriendshipStatusAsync(u.Pk);

                        if (isFollowingMe.Succeeded)
                        {
                            if (isFollowingMe.Value.FollowedBy)
                            {
                                _tempList.Add(u);
                            }
                        }
                    }

                    FilteredUsers = _tempList;
                }

                if (search.InPosts)
                {
                    // No way to implement
                }
            }
            ;


            return(FilteredUsers.Take(count).ToList());
        }
Esempio n. 2
0
        private static async void RunFollowTaskAsync(TaskModel t, IInstaApi api)
        {
            List <InstaUserShort> users = new List <InstaUserShort>();

            t = t.Refreshed;

            foreach (var search in t.Searches)
            {
                foreach (var inString in search.GetInStrings())
                {
                    var _temp = await api.SearchUsersAsync(inString);

                    if (_temp.Succeeded)
                    {
                        users.AddRange(_temp.Value.ToList());


                        var _tempList = new List <InstaUserShort>();

                        foreach (var user in users)
                        {
                            var _fs = await api.GetFriendshipStatusAsync(user.Pk);

                            if (_fs.Succeeded)
                            {
                                if (!_fs.Value.Following)
                                {
                                    _tempList.Add(user);
                                }
                            }
                        }

                        users = _tempList;
                    }
                }

                var FilteredUsers = await Helper.GetFilteredUsersAsync(users, t.Searches, api, 5);

                // Execute
                if (FilteredUsers.Count > 0)
                {
                    foreach (var user in FilteredUsers)
                    {
                        if (user != null)
                        {
                            var result = await api.FollowUserAsync(user.Pk);

                            if (result.Succeeded)
                            {
                                if (result.Value.Following)
                                {
                                    t.TaskExecuted();
                                    Helper.Log($"Task Executed: {t.Name} - {t.TaskType.ToString()} {Environment.NewLine} {JsonConvert.SerializeObject(result.Value)}");
                                }
                                else
                                {
                                    Helper.Log(JsonConvert.SerializeObject(result.Value));
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public static async Task <List <InstaMedia> > GetFilteredMediaAsync(List <InstaMedia> medias, List <SearchModel> searches, IInstaApi api, int count)
        {
            var FilteredMedia = new List <InstaMedia>();

            // Search for our results
            // In strings
            foreach (var search in searches)
            {
                if (search.InUsers)
                {
                    var _tempList = new List <InstaMedia>();

                    search.GetInStrings().ForEach(inString =>
                    {
                        _tempList.AddRange(medias.Where(m => (m.User.UserName + m.User.FullName).Contains(inString)));
                    });

                    search.GetExStrings().ForEach(exString =>
                    {
                        _tempList.RemoveAll(m => (m.User.UserName + m.User.FullName).Contains(exString));
                    });

                    search.GetInLocations().ForEach(inLocation =>
                    {
                        _tempList.AddRange(medias.Where(m =>
                        {
                            if (m.Location != null && inLocation.FbLocation != null)
                            {
                                return(m.Location.FacebookPlacesId == inLocation.FbLocation.Pk);
                            }
                            else
                            {
                                return(false);
                            }
                        }));
                    });

                    search.GetExLocations().ForEach(exLocation =>
                    {
                        _tempList.RemoveAll(m =>
                        {
                            if (m.Location != null && exLocation.FbLocation != null)
                            {
                                return(m.Location.FacebookPlacesId == exLocation.FbLocation.Pk);
                            }
                            else
                            {
                                return(false);
                            }
                        });
                    });

                    FilteredMedia.AddRange(_tempList);
                }

                if (search.InHashtags)
                {
                    var _tempList = new List <InstaMedia>();


                    search.GetInStrings().ForEach(inString =>
                    {
                        if (inString.StartsWith("#"))
                        {
                            _tempList.AddRange(medias.Where(m =>
                            {
                                if (m.Caption != null)
                                {
                                    return(m.Caption.Text.Contains(inString));
                                }
                                else
                                {
                                    return(false);
                                }
                            }));
                        }
                    });

                    search.GetExStrings().ForEach(exString =>
                    {
                        if (exString.StartsWith("#"))
                        {
                            _tempList.RemoveAll(m =>
                            {
                                if (m.Caption != null)
                                {
                                    return(m.Caption.Text.Contains(exString));
                                }
                                else
                                {
                                    return(false);
                                }
                            });
                        }
                    });

                    FilteredMedia.AddRange(_tempList);
                }

                if (search.InFollowingMe)
                {
                    var _tempMedia = new List <InstaMedia>();

                    foreach (var m in medias)
                    {
                        var isFollowingMe = await api.GetFriendshipStatusAsync(m.User.Pk);

                        if (isFollowingMe.Succeeded)
                        {
                            if (isFollowingMe.Value.FollowedBy)
                            {
                                _tempMedia.Add(m);
                            }
                        }
                    }

                    FilteredMedia.AddRange(_tempMedia);
                }

                if (search.InPosts)
                {
                    // It a Must in Posts
                }
            }
            ;


            return(FilteredMedia.Take(count).ToList());
        }