示例#1
0
 public void SaveBotState()
 {
     if (!String.IsNullOrEmpty(_botStateBackupDir))
     {
         var savePath = Path.Combine(_botStateBackupDir, _botStateFileName);
         SerDeUtils.SerializeToJsonFile(_botState, savePath);
         _logger.Info($"BotState successfully saved: {savePath}");
     }
     else
     {
         _logger.Warn($"Can't save BotState, bad path: {_botStateBackupDir}");
     }
 }
        private void GetProfilePosts(string path)
        {
            _userProfilePage.ScrollDownUntil(() => _userProfilePage.GetPostsCount(), _postsCount);
            var allPosts = _userProfilePage.GetPostsByCount(_postsCount);

            allPosts.ForEach(post =>
            {
                post.Add("Item_ID", Guid.NewGuid().ToString());
                post.Add("Profile_Url", _userProfilePage.GetPageUrl());
                post.Add("Data_Type", "Post");
            });
            SerDeUtils.SerializeToJsonFile(allPosts, path);
        }
 public override void Process(BotStateBuilder botState)
 {
     botState.ComponentsDataHandler.Add(this.GetType().Name, _searchResults);
     foreach (var link in _searchLinks)
     {
         _searchResultsPage.SetPageUrl(link.Value);
         _searchResultsPage.GoToPageUrl();
         _searchResultsPage.GoToPageUrl();
         _searchResultsPage.ScrollDownToPageEnd();
         _searchResults.Add(link.Key, _searchResultsPage.GetAllProfilesUrls());
         Configs.Logger.Info($"Resuls for link: {link.Key} was added to list");
     }
     SerDeUtils.SerializeToJsonFile(_searchResults, ResultsOutputPath);
 }
        private void GetProfileInfo(string path)
        {
            var fields = new Dictionary <string, object>
            {
                { "Item_ID", Guid.NewGuid().ToString() },
                { "Profile_Url", _userProfilePage.GetPageUrl() },
                { "Data_Type", "ProfileInfo" },
                { "Full_Name", _userProfilePage.GetFullName() }
            };

            fields.AddRange(_userProfilePage.GetProfileInfoFields());

            SerDeUtils.SerializeToJsonFile(fields, path);
        }
        public override void Process(BotStateBuilder botState)
        {
            if (!_loadResultsFromFile)
            {
                //Gets values from another components
                _searchResults =
                    (Dictionary <string, List <string> >)
                    botState.ComponentsDataHandler[typeof(SearchResultsScannerComponent).Name];
            }
            else
            {
                _searchResults = SerDeUtils.DeserializeJsonFile <Dictionary <string, List <string> > >(Path.Combine(_baseDir, _searchResultsFileName));
            }
            Wait wait = new Wait(botState.Driver);

            foreach (var searchResult in _searchResults)
            {
                foreach (var userProfile in searchResult.Value)
                {
                    _userProfilePage.SetPageUrl(userProfile);
                    Thread.Sleep(400);
                    _userProfilePage.GoToPageUrl();

                    var currentProfileDataPath = Path.Combine(_baseDir, "AllProfiles", searchResult.Key, Path.GetFileName(userProfile));
                    Directory.CreateDirectory(currentProfileDataPath);

                    //Get Profile info
                    GetProfileInfo(Path.Combine(currentProfileDataPath, "ProfileInfo.json"));
                    Configs.Logger.Debug($"Profile info was gathered | Profile: {userProfile}");

                    if (_postsCount != 0)
                    {
                        //Get Profile posts
                        GetProfilePosts(Path.Combine(currentProfileDataPath, "Posts.json"));
                        Configs.Logger.Debug($"Posts was gathered | Profile: {userProfile}");
                    }

                    if (_profilePhotosCount != 0 || _galleryPhotosCount != 0)
                    {
                        //Get All kind of photos
                        OpenAlbumViewForGettingPhotos(currentProfileDataPath);
                    }

                    Configs.Logger.Info($"Profile inteligence succed! Profile: {userProfile} | Search marker: {searchResult.Key}");
                }
            }
        }
示例#6
0
 public BotLoader(List <BotComponent> components, Type driverType = null, string botStateBackupDir = null,
                  bool loadFromBackup = false)
 {
     _components        = components;
     _loadFromBackup    = loadFromBackup;
     _botStateBackupDir = botStateBackupDir;
     _botStateFileName  = "BotStateBuilder.state";
     _botState          = new BotStateBuilder(driverType);
     if (!loadFromBackup == false)
     {
         if (!String.IsNullOrEmpty(_botStateBackupDir))
         {
             _botState =
                 SerDeUtils.DeserializeJsonFile <BotStateBuilder>(Path.Combine(_botStateBackupDir, _botStateFileName));
             _logger.Info($"BotState loaded from {_botStateFileName}");
         }
         else
         {
             _logger.Warn($"Can't find state file on path:{_botStateBackupDir}");
         }
     }
 }
 public override void Prepare(BotStateBuilder botState)
 {
     _searchLinks       = SerDeUtils.DeserializeJsonFile <Dictionary <string, string> >(LinksInputPath);
     _searchResults     = new Dictionary <string, List <string> >();
     _searchResultsPage = new SearchResultsPage(botState.Driver);
 }