Добавление автомобилей

This commit is contained in:
2024-10-08 09:53:24 +03:00
parent 493f3ddbf4
commit d86dd4e39a
17 changed files with 1369 additions and 185 deletions

View File

@@ -11,16 +11,6 @@ using OpenQA.Selenium.Support.UI;
namespace GtaVUsersInfo.Helpers
{
public class Car
{
public string Name { get; set; }
public int Price { get; set; }
public string Photo { get; set; }
public string Manufacturer { get; set; }
public string Class { get; set; }
public string Model { get; set; }
}
public class CarParser : IDisposable
{
private IWebDriver driver;
@@ -115,6 +105,11 @@ namespace GtaVUsersInfo.Helpers
public void SaveToJson(List<Car> cars, string filePath)
{
if (!Directory.Exists(Path.GetDirectoryName(filePath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
}
var json = JsonConvert.SerializeObject(cars, Formatting.Indented);
File.WriteAllText(filePath, json);
}
@@ -129,17 +124,4 @@ namespace GtaVUsersInfo.Helpers
}
}
}
class Program
{
static async Task Main(string[] args)
{
using (var parser = new CarParser())
{
var cars = await parser.ParseCarsFromPages(25);
parser.SaveToJson(cars, "cars.json");
Console.WriteLine("Data saved to cars.json");
}
}
}
}

24
Helpers/ErrorsShow.cs Normal file
View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GtaVUsersInfo.Helpers
{
public static class ErrorsShow
{
public static void ShowErrorMessage(string message)
{
MessageBox.Show(message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine(message);
}
public static void ShowInfoMessage(string message)
{
MessageBox.Show(message, "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
Console.WriteLine(message);
}
}
}

View File

@@ -6,8 +6,9 @@ using System.Threading.Tasks;
namespace GtaVUsersInfo.Helpers
{
public class Strings
public static class ReadonlyStrings
{
public readonly static string carUrl = "https://gtacars.net/";
public readonly static string carJsonPath = "data/cars.json";
}
}