-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstockbackup.txt
54 lines (44 loc) · 1.69 KB
/
stockbackup.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using ProductSynchronizer.Entities;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Newtonsoft.Json.Linq;
using ProductSynchronizer.Helpers;
namespace ProductSynchronizer.Parsers
{
public class StockXWorker : WorkerBase
{
private const string STOCKX_API_URL = "https://stockx.com/api/products/";
public StockXWorker() :base(Resource.StockX, HttpClientVpnType.OnlyProxy)
{
}
protected override List<ISizeMapNode> ParseHtml(string response)
{
var shoesSizeMap = new List<ISizeMapNode>();
var sizesContainer = JArray.Parse(response)["Product"]?["children"]?
.Select(x => x.Children().FirstOrDefault()).ToList();
if (sizesContainer == null || !sizesContainer.Any())
{
return shoesSizeMap;
}
foreach (var sizeNode in sizesContainer)
{
var size = sizeNode["shoeSize"]?.ToObject<string>()?.Trim();
var price = sizeNode["market"]?["lowestAsk"]?.ToObject<string>();
var shoeContext = new ShoeContext()
{
ExternalSize = size,
ExternalPrice = double.Parse(price, CultureInfo.InvariantCulture),
Quantity = 999
};
shoesSizeMap.Add(shoeContext);
}
return shoesSizeMap;
}
protected override void UpdateProductLocation(Product product)
{
var sneakersName = product.Location.Split('/').Last();
product.Location = STOCKX_API_URL + sneakersName;
}
}
}