Skip to content

Commit

Permalink
Update the csv accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
outerwinnie committed Sep 5, 2024
1 parent 82d8f7e commit ff6dd14
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,29 +268,44 @@ private static async Task ProcessRewards()

try
{
var records = new List<RewardRecordClass>();

// Read the existing rewards data
using (var reader = new StreamReader(_rewardsCsvPath))
using (var csv = new CsvReader(reader, new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture)))
{
var records = csv.GetRecords<RewardRecordClass>().ToList();
records = csv.GetRecords<RewardRecordClass>().ToList();
}

foreach (var record in records)
foreach (var record in records)
{
if (record.RewardName == "recuerdate")
{
if (record.RewardName == "recuerdate")
if (int.TryParse(record.Quantity, out int quantity))
{
if (int.TryParse(record.Quantity, out int quantity))
var imagesSent = 0;
for (int i = 0; i < quantity; i++)
{
for (int i = 0; i < quantity; i++)
{
await PostRandomImageUrl();
}
}
else
{
Console.WriteLine($"Invalid Quantity value for record with RewardName '{record.RewardName}'.");
await PostRandomImageUrl();
imagesSent++;
}

// Update the Quantity field
record.Quantity = (quantity - imagesSent).ToString();
}
else
{
Console.WriteLine($"Invalid Quantity value for record with RewardName '{record.RewardName}'.");
}
}
}

// Write the updated rewards data back to the CSV file
using (var writer = new StreamWriter(_rewardsCsvPath))
using (var csv = new CsvWriter(writer, new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture)))
{
csv.WriteRecords(records);
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit ff6dd14

Please sign in to comment.