66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using Ratermania.Automation.Interfaces;
|
|
using Ratermania.Shopify;
|
|
using Ratermania.Shopify.Resources;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PartSource.Automation.Jobs.POC
|
|
{
|
|
public class FixMultipleSeoTables : IAutomationJob
|
|
{
|
|
private readonly ShopifyClient _shopifyClient;
|
|
|
|
public FixMultipleSeoTables(ShopifyClient shopifyClient)
|
|
{
|
|
_shopifyClient = shopifyClient;
|
|
}
|
|
|
|
public async Task Run()
|
|
{
|
|
IEnumerable<Product> products = await _shopifyClient.Products.Get(new Dictionary<string, object> { { "limit", 250 }, { "product_type", "CA112-SC137-FL13750_Intake Manifolds" } });
|
|
|
|
while (products != null && products.Any())
|
|
{
|
|
foreach (Product product in products)
|
|
{
|
|
try
|
|
{
|
|
string[] parts = product.BodyHtml.Split("<div id=\"seoData\">");
|
|
|
|
if (parts.Length > 2)
|
|
{
|
|
string ul = product.BodyHtml.Substring(0, product.BodyHtml.IndexOf("</ul>") + "</ul>".Length);
|
|
string seoData = "<div id=\"seoData\">" + parts[1].Substring(0, parts[1].IndexOf("</table>") + "</table>".Length) + "</div>";
|
|
string vehicleIds = new Regex("<div id=\"vehicleIDs\".*</div>").Match(product.BodyHtml).Value;
|
|
|
|
product.BodyHtml = ul + seoData + vehicleIds;
|
|
|
|
await _shopifyClient.Products.Update(product);
|
|
}
|
|
}
|
|
|
|
catch
|
|
{
|
|
Console.WriteLine($"Failed to update {product.Id}");
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
Console.WriteLine("Did 250");
|
|
products = await _shopifyClient.Products.GetNext();
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
products = await _shopifyClient.Products.GetPrevious();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|