public static string GetClearDescription(MyListingsSalesItem item) { if (item == null) { return(string.Empty); } var descriptionBuilder = new StringBuilder(); descriptionBuilder.Append($"Name: {item.HashName}{Environment.NewLine}"); descriptionBuilder.Append($"Game: {item.Game}{Environment.NewLine}"); descriptionBuilder.Append($"App id: {item.AppId}{Environment.NewLine}"); descriptionBuilder.Append($"Sale id: {item.SaleId}{Environment.NewLine}"); descriptionBuilder.Append($"Url: {item.Url}{Environment.NewLine}"); return(descriptionBuilder.ToString()); }
private MyListingsSalesItem ProcessSellListings(HtmlNode item, string currency) { var node = item.SelectSingleNode(".//span[@class='market_listing_price']"); var date = Regex.Match(item.InnerText, @"Listed: (.+)?\s").Groups[1].Value.Trim(); var priceString = node.InnerText.Replace("\r", string.Empty).Replace("\n", string.Empty) .Replace("\t", string.Empty).Replace(" ", string.Empty); if (priceString.Contains("Sold!")) { return(null); } var game = item.SelectSingleNode("//span[@class='market_listing_game_name']").InnerText; double price; try { var priceParse = priceString.Split('(')[0]; var currencySymbol = SteamCurrencies.Currencies[currency]; priceParse = priceParse.Replace(currencySymbol, string.Empty); var parseDouble = NumberUtils.TryParseDouble(priceParse, out price); if (parseDouble == false) { throw new SteamException($"Cannot parse order listing price - {priceString}"); } } catch (SteamException) { throw; } catch (Exception e) { throw new SteamException($"Cannot parse order listing price - {priceString} - {e.Message}"); } var saleIdMatch = Regex.Match(item.InnerHtml, "(?<=mylisting_)([0-9]*)(?=_name)"); if (!saleIdMatch.Success) { throw new SteamException("Cannot find sale listing ID"); } var saleIdParse = long.TryParse(saleIdMatch.Value, out var saleId); if (!saleIdParse) { throw new SteamException($"Cannot parse sale listing ID - {saleIdMatch.Value}"); } var imageUrl = item.SelectSingleNode($"//img[contains(@id, 'mylisting_{saleId}_image')]").Attributes["src"] .Value; imageUrl = Regex.Match(imageUrl, "image/(.*)/").Groups[1].Value; var urlNode = item.SelectSingleNode(".//a[@class='market_listing_item_name_link']"); if (urlNode == null) { throw new SteamException("Cannot find sale listing url"); } var url = urlNode.Attributes["href"].Value; var hashName = MarketUtils.HashNameFromUrl(url); var appId = MarketUtils.AppIdFromUrl(url); var nameNode = urlNode.InnerText; var result = new MyListingsSalesItem { AppId = appId, HashName = hashName, Name = nameNode, Date = date, SaleId = saleId, Price = price, Url = url, ImageUrl = imageUrl, Game = game }; return(result); }
private void GetPendingTransactionData( HtmlNode item, int tempIndex, MyListings myListings, ETransactionType type, string currency) { if (item == null) { return; } var node = item.SelectSingleNode(".//span[@class='market_listing_price']"); if (node == null) { throw new SteamException( $"Cannot parse order listing price and quantity node. Item index [{tempIndex}]"); } var date = Regex.Match(item.InnerText, @"Listed: (.+)?\s").Groups[1].Value.Trim(); var game = item.SelectSingleNode("//span[@class='market_listing_game_name']")?.InnerText; if (type == ETransactionType.Order) { var priceAndQuantityString = node.InnerText.Replace("\r", string.Empty).Replace("\n", string.Empty) .Replace("\t", string.Empty).Replace(" ", string.Empty); var priceAndQuantitySplit = priceAndQuantityString.Split('@'); double price; try { var priceParse = priceAndQuantitySplit[1].Replace(".", string.Empty); var currencySymbol = SteamCurrencies.Currencies[currency]; double.TryParse(priceParse.Replace(currencySymbol, string.Empty), out price); } catch (Exception) { throw new SteamException($"Cannot parse order listing price. Item index [{tempIndex}]"); } var quantityParse = int.TryParse(priceAndQuantitySplit[0], out var quantity); if (!quantityParse) { throw new SteamException($"Cannot parse order listing quantity. Item index [{tempIndex}]"); } var orderIdMatch = Regex.Match(item.InnerHtml, "(?<=mbuyorder_)([0-9]*)(?=_name)"); if (!orderIdMatch.Success) { throw new SteamException($"Cannot find order listing ID. Item index [{tempIndex}]"); } var orderIdParse = long.TryParse(orderIdMatch.Value, out var orderId); if (!orderIdParse) { throw new SteamException($"Cannot parse order listing ID. Item index [{tempIndex}]"); } var imageUrl = item.SelectSingleNode($"//img[contains(@id, 'mylisting_{orderId}_image')]") .Attributes["src"].Value; imageUrl = Regex.Match(imageUrl, "image/(.*)/").Groups[1].Value; var urlNode = item.SelectSingleNode(".//a[@class='market_listing_item_name_link']"); if (urlNode == null) { throw new SteamException($"Cannot find order listing url. Item index [{tempIndex}]"); } var url = urlNode.Attributes["href"].Value; var hashName = MarketUtils.HashNameFromUrl(url); var appId = MarketUtils.AppIdFromUrl(url); var nameNode = urlNode.InnerText; myListings.Orders.Add( new MyListingsOrdersItem { AppId = appId, HashName = hashName, Name = nameNode, Date = date, OrderId = orderId, Price = price, Quantity = quantity, Url = url, ImageUrl = imageUrl, Game = game }); } else { var priceString = node.InnerText.Replace("\r", string.Empty).Replace("\n", string.Empty) .Replace("\t", string.Empty).Replace(" ", string.Empty); double price; try { var priceParse = priceString.Split('(')[0]; var currencySymbol = SteamCurrencies.Currencies[currency]; double.TryParse(priceParse.Replace(currencySymbol, string.Empty), out price); } catch (Exception) { throw new SteamException($"Cannot parse order listing price. Item index [{tempIndex}]"); } var saleIdMatch = Regex.Match(item.InnerHtml, "(?<=mylisting_)([0-9]*)(?=_name)"); if (!saleIdMatch.Success) { throw new SteamException($"Cannot find sale listing ID. Item index [{tempIndex}]"); } var saleIdParse = long.TryParse(saleIdMatch.Value, out var saleId); if (!saleIdParse) { throw new SteamException($"Cannot parse sale listing ID. Item index [{tempIndex}]"); } var imageUrl = item.SelectSingleNode($"//img[contains(@id, 'mylisting_{saleId}_image')]") .Attributes["src"].Value.Replace("38fx38f", string.Empty).Replace( "https://steamcommunity-a.akamaihd.net/economy/image/", string.Empty); var urlNode = item.SelectSingleNode(".//a[@class='market_listing_item_name_link']"); if (urlNode == null) { throw new SteamException($"Cannot find sale listing url. Item index [{tempIndex}]"); } var url = urlNode.Attributes["href"].Value; var hashName = MarketUtils.HashNameFromUrl(url); var appId = MarketUtils.AppIdFromUrl(url); var nameNode = urlNode.InnerText; var result = new MyListingsSalesItem { AppId = appId, HashName = hashName, Name = nameNode, Date = date, SaleId = saleId, Price = price, Url = url, ImageUrl = imageUrl, Game = game }; var isConfirmation = item.InnerHtml.Contains("CancelMarketListingConfirmation"); if (isConfirmation == false) { myListings.Sales.Add(result); } else { myListings.ConfirmationSales.Add(result); } } }