Frase.io Update Code
Frase.io Update Code
Utilites;
using Crawler.Extensions.SeleniumExtensions;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
namespace JobsTrackerCrawler
{
class Program
{
string documentsFolder =
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string baseFolder = Path.Combine(documentsFolder, "Frase.io",
"GeneratedContent");
UIConstants.SiteUrl = "https://app.frase.io/app/documents";
SeleniumBrowserMethods.InitializeAndSetupBrowser("ProfileOne");
SeleniumObjectsMethods.PutWaitInThread(2);
CreateNewDocumentPopUp();
ChangeCountryAndLanguage(country, language);
SeleniumObjectsMethods.PutWaitInThread(5);
SeleniumSetMethods.EnterText(PropertyType.CssSelector,
"input[placeholder=\"Enter search query\"]", topic, 250);
SeleniumSetMethods.Click(PropertyType.XPath,
"//button[span[text()='Start']]", 250);
SeleniumObjectsMethods.PutWaitInThread(5);
SeleniumBrowserMethods.RefreshPage();
SeleniumObjectsMethods.PutWaitInThread(2);
SeleniumSetMethods.Click(PropertyType.CssSelector,
"button[aria-controls*=\"-content-outline\"]", 250);
SeleniumSetMethods.Click(PropertyType.CssSelector,
"button[class*=\"backdrop-blur-lg bg-emerald-200/30 dark:bg-emerald-800/30\"]",
250);
SeleniumSetMethods.Click(PropertyType.CssSelector,
"button[id=\"optimize-tab\"]", 250);
SeleniumSetMethods.Click(PropertyType.CssSelector,
"div[data-orientation=\"horizontal\"][data-state=\"active\"] button[aria-
haspopup=\"menu\"][aria-expanded=\"false\"][data-state=\"closed\"]", 250);
SeleniumSetMethods.Click(PropertyType.CssSelector,
"a[download=\"topics.csv\"]", 250);
if (!Directory.Exists(topicFolder))
{
Directory.CreateDirectory(topicFolder);
}
if (!string.IsNullOrEmpty(latestCsvFile))
{
string newCsvFilePath = Path.Combine(topicFolder, topic
+ ".csv");
if (File.Exists(newCsvFilePath))
{
File.Delete(newCsvFilePath);
Console.WriteLine($"Existing CSV file deleted:
{newCsvFilePath}");
}
SeleniumObjectsMethods.PutWaitInThread(4);
File.Move(latestCsvFile, newCsvFilePath);
}
else
{
Console.WriteLine("No CSV file found in Downloads.");
}
RemoveTopicFromFile(topic);
}
if (File.Exists(topicListPath))
{
var topics = File.ReadAllLines(topicListPath)
.Where(line => !
string.IsNullOrWhiteSpace(line) && line.Trim() != completedTopic)
.ToList();
File.WriteAllLines(topicListPath, topics);
try
{
// Check if the file exists
if (File.Exists(filePath))
{
// Read all lines from the file
string[] lines = File.ReadAllLines(filePath);
break;
}
}
SeleniumObjectsMethods.PutWaitInThread(2);
SeleniumSetMethods.Click(PropertyType.CssSelector,
"div[role=\"dialog\"] form > div[class^=\"space-y-2\"]:nth-child(3) button[aria-
haspopup=\"dialog\"]:nth-child(2)", 60);
var languageNames =
SeleniumGetMethods.GetWebElements(PropertyType.CssSelector, "div[role='group'] >
div");
foreach (var name in languageNames)
{
if
(SeleniumGetMethods.GetInnerTextFromHTML(name).ToLower().Contains(language.ToLower(
)))
{
SeleniumSetMethods.Click(name);
Actions actions = new Actions(PropertiesCollection.Driver);
actions.SendKeys(Keys.Escape).Perform();
break;
}
}
SeleniumSetMethods.Click(PropertyType.CssSelector,
"div[role=\"dialog\"] form > div:nth-child(4) > button:nth-child(2)");
}
return topics;
}
else
{
Console.WriteLine("TopicList.txt file does not exist.");
return Array.Empty<string>(); // Return an empty array if file
does not exist
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
return Array.Empty<string>(); // Return an empty array in case of
an error
}
}
static string GetLatestFile(string folderPath, string searchPattern)
{
try
{
var directory = new DirectoryInfo(folderPath);
var file = directory.GetFiles(searchPattern)
.OrderByDescending(f => f.LastWriteTime)
.FirstOrDefault();
return file?.FullName;
}
catch (Exception ex)
{
Console.WriteLine($"Error getting latest file: {ex.Message}");
return null;
}
}
Thread.Sleep(1000);
}
LogError($"Files did not download for topic = '{topicName}'");
}
}
}