Beispiel #1
0
        public static List <PriceSourceItemOld> SearchLookup(string term, AmazonEndpoint?endpoint = null)
        {
            List <PriceSourceItemOld> results           = new List <PriceSourceItemOld>();
            List <Endpoint>           endpointsToSearch = new List <Endpoint>();

            if (endpoint != null)
            {
                endpointsToSearch.Add(Endpoints.Get(endpoint.Value));
            }
            else
            {
                endpointsToSearch.AddRange(Endpoints.EndpointsList);
            }

            foreach (var endpointItem in endpointsToSearch)
            {
                var authentication = new AmazonAuthentication();
                authentication.AccessKey = endpointItem.accessKey;
                authentication.SecretKey = endpointItem.secreteKey;

                endpoint = (AmazonEndpoint)Enum.Parse(typeof(AmazonEndpoint), endpointItem.endpointCode);
                var    wrapper    = new AmazonWrapper(authentication, endpoint.Value, endpointItem.merchantId);
                string searchTerm = "ASUS DUAL-RX580-O8G Radeon RX 580 8 GB GDDR5";
                //string searchTerm = //"B076GZ3JFC";
                AmazonItemResponse result = wrapper.Lookup(term);
                results.AddRange(result.ToPriceSourceItems());
            }
            return(results);
        }
Beispiel #2
0
        async Task SaveItemsAsync(
            ApplicationDbContext context,
            IDictionary <string, Models.Item> items,
            AmazonItemResponse response,
            CancellationToken cancellationToken)
        {
            foreach (var item in response.Items.Item)
            {
                if (items.TryGetValue(item.ASIN, out var targetItem))
                {
                    var isComic = IsComic(item);

                    targetItem.SetDetails(
                        isComic: isComic,
                        detailPageUrl: item.DetailPageURL,
                        imageUrl: item.MediumImage?.URL,
                        author: string.Join(",", item.ItemAttributes.Author ?? new string[0]),
                        publisher: item.ItemAttributes.Publisher,
                        description: string.Join(
                            Environment.NewLine,
                            item.EditorialReviews?.Select(e => e.Content) ?? new string[0])
                        );

                    if (isComic)
                    {
                        // タグを保存
                        var tags      = GetTags(item);
                        var savedTags = await FindOrCreateTagsAsync(context, tags, cancellationToken);

                        foreach (var tag in savedTags)
                        {
                            if (!targetItem.HasTag(tag))
                            {
                                targetItem.AddTag(tag);
                            }
                        }
                    }

                    context.Items.Update(targetItem);
                    await context.SaveChangesAsync(cancellationToken);

                    logger.LogInformation($"Is {targetItem.Title} comic?: {targetItem.IsComic}");
                }
            }
        }
Beispiel #3
0
        public static List <PriceSourceItemOld> ToPriceSourceItems(this AmazonItemResponse amazonItemResponse)
        {
            List <PriceSourceItemOld> result = new List <PriceSourceItemOld>();

            if (amazonItemResponse == null)
            {
                return(result);
            }
            foreach (var item in amazonItemResponse.Items.Item)
            {
                string asin     = item.ASIN;
                string url      = item.DetailPageURL;
                string imageUrl = item.LargeImage.URL;

                if (item.Offers.TotalOffers != "0")
                {
                    foreach (var offer in item.Offers.Offer)
                    {
                        string merchant = offer.Merchant?.Name;
                        foreach (var offerListing in offer.OfferListing)
                        {
                            PriceSourceItemOld priceSourceItem = new PriceSourceItemOld();

                            priceSourceItem.Merchant = merchant;
                            priceSourceItem.ASIN     = asin;
                            string itemName = item.ToString();
                            priceSourceItem.Name     = itemName;
                            priceSourceItem.URL      = url;
                            priceSourceItem.ImageUrl = imageUrl;
                            string priceStr = offerListing.Price.Amount;
                            priceSourceItem.PriceCurrency = offerListing.Price.CurrencyCode;
                            if (!string.IsNullOrWhiteSpace(offerListing.SalePrice?.Amount))
                            {
                                priceStr = offerListing.SalePrice.Amount;
                                priceSourceItem.PriceCurrency = offerListing.SalePrice.CurrencyCode;
                            }
                            if (priceStr.Length >= 2)
                            {
                                priceStr = priceStr.Insert(priceStr.Length - 2, ".");
                            }
                            priceSourceItem.Price = double.Parse(priceStr);
                            result.Add(priceSourceItem);
                        }
                    }
                }
                else if (item.ItemLinks.FirstOrDefault(l => l.Description == "All Offers") != null)
                {
                    url = item.ItemLinks.FirstOrDefault(l => l.Description == "All Offers").URL;
                    PriceSourceItemOld priceSourceItem = new PriceSourceItemOld();
                    string             itemName        = item.ToString();
                    priceSourceItem.Name     = itemName;
                    priceSourceItem.ASIN     = asin;
                    priceSourceItem.URL      = url;
                    priceSourceItem.ImageUrl = imageUrl;
                    string priceStr = item.OfferSummary.LowestNewPrice.Amount;
                    priceSourceItem.PriceCurrency = item.OfferSummary.LowestNewPrice.CurrencyCode;
                    if (priceStr.Length >= 2)
                    {
                        priceStr = priceStr.Insert(priceStr.Length - 2, ".");
                    }
                    priceSourceItem.Price = double.Parse(priceStr);
                    result.Add(priceSourceItem);
                }
            }
            return(result);
        }
Beispiel #4
0
 public static bool ProductHasISBN(AmazonItemResponse itemInfo)
 {
     return(itemInfo.Items.Item[0].ItemAttributes.ISBN != null);
 }