コード例 #1
0
ファイル: FetchSeller.cs プロジェクト: weidnerk/ebayUtility
        private static async Task SearchEngineMatch(UserSettingsView settings, int rptNumber, int minSold, int daysBack, int?minPrice, int?maxPrice, bool?activeStatusOnly, bool?isSellerVariation, string itemID, double pctProfit, decimal wmShipping, decimal wmFreeShippingMin, double eBayPct, int imgLimit, string supplierTag)
        {
            string loopItemID = null;
            bool   found      = false;

            try
            {
                var mv = new ModelViewTimesSold();
                mv.TimesSoldRpt = FilterMatch(settings, rptNumber, minSold, daysBack, minPrice, maxPrice, activeStatusOnly, isSellerVariation, itemID);

                // Only search where MatchCount is null or does not equal 1
                mv.TimesSoldRpt = mv.TimesSoldRpt.Where(p => !p.MatchCount.HasValue || (p.MatchCount.HasValue && p.MatchCount.Value != 1)).ToList();

                foreach (var row in mv.TimesSoldRpt)
                {
                    loopItemID = row.ItemID;
                    if (loopItemID == "392388202275")
                    {
                        var stop = 999;
                    }
                    ISupplierItem walitem;
                    string        descr = row.Description;
                    found = false;

                    // Search sections of description since most search engines only use first part of query anyway
                    for (int i = 0; i < 5; i++)
                    {
                        string section = GetDescrSection(descr, i);
                        if (!string.IsNullOrEmpty(section))
                        {
                            section = supplierTag + " " + section;

                            //var links = dsutil.DSUtil.BingSearch(section);
                            var links = dsutil.DSUtil.GoogleSearchSelenium(section);

                            var validLinks = wallib.wmUtility.ValidURLs(links); // just get supplier links
                            if (validLinks.Count > 0)
                            {
                                // Collect valid supplier links from search engine result
                                foreach (string supplierURL in validLinks)
                                {
                                    walitem = await wallib.wmUtility.GetDetail(supplierURL, imgLimit, false);

                                    if (walitem != null)
                                    {
                                        // If can't get supplier pics, not much point in posting.
                                        // Can happen when not matching correctly on something like an eBook or giftcard where walmart
                                        // is not providing "standard" images. (error is logged in GetDetail()).
                                        if (!string.IsNullOrEmpty(walitem.SupplierPicURL))
                                        {
                                            if (!string.IsNullOrEmpty(walitem.ItemID) || !string.IsNullOrEmpty(walitem.UPC) || !string.IsNullOrEmpty(walitem.MPN))
                                            {
                                                found           = true;
                                                walitem.Updated = DateTime.Now;
                                                _repository.SupplierItemUpdateByID(walitem,
                                                                                   "Updated",
                                                                                   "ItemURL",
                                                                                   "SoldAndShippedBySupplier",
                                                                                   "SupplierBrand",
                                                                                   "SupplierPrice",
                                                                                   "IsVariation",
                                                                                   "SupplierPicURL",
                                                                                   "IsFreightShipping");

                                                var oh = new OrderHistory();
                                                oh.ItemID         = row.ItemID;
                                                oh.MatchCount     = 1;
                                                oh.MatchType      = 3;
                                                oh.SourceID       = walitem.SourceID;
                                                oh.SupplierItemID = walitem.ID;
                                                if (walitem.SupplierPrice.HasValue)
                                                {
                                                    var p = wallib.wmUtility.wmNewPrice(walitem.SupplierPrice.Value, pctProfit, wmShipping, wmFreeShippingMin, eBayPct);
                                                    oh.ProposePrice = p.ProposePrice;
                                                    _repository.OrderHistoryUpdate(oh, "ProposePrice", "MatchType", "MatchCount", "SourceID", "SupplierItemID");
                                                }
                                                else
                                                {
                                                    _repository.OrderHistoryUpdate(oh, "MatchType", "MatchCount", "SourceID", "SupplierItemID");
                                                }
                                            }
                                        }
                                        if (found)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (found)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                string msgItemID = (!string.IsNullOrEmpty(loopItemID)) ? "ItemID: " + loopItemID : "";
                string header    = "SearchEngineMatch RptNumber: " + rptNumber.ToString() + " " + msgItemID;
                string msg       = dsutil.DSUtil.ErrMsg(header, exc);
                dsutil.DSUtil.WriteFile(_logfile, msg, "");
            }
        }
コード例 #2
0
ファイル: FetchSeller.cs プロジェクト: weidnerk/ebayUtility
        /// <summary>
        /// Based on filtering a seller's sales, try to match a prodID with a prodID on walmart
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="rptNumber"></param>
        /// <param name="minSold"></param>
        /// <param name="daysBack"></param>
        /// <param name="minPrice"></param>
        /// <param name="maxPrice"></param>
        /// <param name="activeStatusOnly"></param>
        /// <param name="nonVariation"></param>
        /// <param name="itemID"></param>
        /// <param name="pctProfit"></param>
        /// <returns></returns>
        private static async Task UPCMatch(IUserSettingsView settings, int rptNumber, int minSold, int daysBack, int?minPrice, int?maxPrice, bool?activeStatusOnly, bool?isSellerVariation, string itemID, double pctProfit, decimal wmShipping, decimal wmFreeShippingMin, double eBayPct, int imgLimit)
        {
            string loopItemID = null;

            try
            {
                var mv = new ModelViewTimesSold();
                mv.TimesSoldRpt = FilterMatch(settings, rptNumber, minSold, daysBack, minPrice, maxPrice, activeStatusOnly, isSellerVariation, itemID);

                foreach (var row in mv.TimesSoldRpt)
                {
                    loopItemID = row.ItemID;
                    bool tryAgain = false;
                    WalmartSearchProdIDResponse response;
                    //var walitem = new SupplierItem();
                    ISupplierItem walitem;
                    if (row.SellerUPC != null)
                    {
                        response = wallib.wmUtility.SearchProdID(row.SellerUPC);
                        if (response.Count == 1)
                        {
                            walitem = await wallib.wmUtility.GetDetail(response.URL, imgLimit, false);

                            // If can't get supplier pics, not much point in posting.
                            // Can happen when not matching correctly on something like an eBook or giftcard where walmart
                            // is not providing "standard" images. (error is logged in GetDetail()).
                            if (!string.IsNullOrEmpty(walitem.SupplierPicURL))
                            {
                                walitem.UPC     = row.SellerUPC;
                                walitem.Updated = DateTime.Now;
                                _repository.SupplierItemUpdateByProdID(row.SellerUPC, "", walitem as SupplierItem,
                                                                       "Updated",
                                                                       "ItemURL",
                                                                       "SoldAndShippedBySupplier",
                                                                       "SupplierBrand",
                                                                       "SupplierPrice",
                                                                       "IsVariation",
                                                                       "SupplierPicURL",
                                                                       "IsFreightShipping");

                                var oh = new OrderHistory();
                                oh.ItemID         = row.ItemID;
                                oh.MatchCount     = response.Count;
                                oh.MatchType      = 1;
                                oh.SourceID       = walitem.SourceID;
                                oh.SupplierItemID = walitem.ID;
                                if (walitem.SupplierPrice.HasValue)
                                {
                                    var p = wallib.wmUtility.wmNewPrice(walitem.SupplierPrice.Value, pctProfit, wmShipping, wmFreeShippingMin, eBayPct);
                                    oh.ProposePrice = p.ProposePrice;
                                    _repository.OrderHistoryUpdate(oh, "ProposePrice", "MatchType", "MatchCount", "SourceID", "SupplierItemID");
                                }
                                else
                                {
                                    _repository.OrderHistoryUpdate(oh, "MatchType", "MatchCount", "SourceID", "SupplierItemID");
                                }
                            }
                        }
                        else
                        {
                            tryAgain = true;
                        }
                    }
                    else
                    {
                        tryAgain = true;
                    }
                    if (tryAgain)
                    {
                        if (row.SellerMPN != null)
                        {
                            response = wallib.wmUtility.SearchProdID(row.SellerMPN);
                            if (response.Count == 1)
                            {
                                walitem = await wallib.wmUtility.GetDetail(response.URL, imgLimit, false);

                                // If can't get supplier pics, not much point in posting.
                                // Can happen when not matching correctly on something like an eBook or giftcard where walmart
                                // is not providing "standard" images. (error is logged in GetDetail()).
                                if (!string.IsNullOrEmpty(walitem.SupplierPicURL))
                                {
                                    walitem.MPN     = row.SellerMPN;
                                    walitem.Updated = DateTime.Now;
                                    _repository.SupplierItemUpdateByProdID("", row.SellerMPN, walitem as SupplierItem,
                                                                           "Updated",
                                                                           "ItemURL",
                                                                           "SoldAndShippedBySupplier",
                                                                           "SupplierBrand",
                                                                           "SupplierPrice",
                                                                           "IsVariation",
                                                                           "SupplierPicURL");

                                    // now update the ebay seller item specific UPC
                                    // but walmart doesn't always give a UPC
                                    if (!string.IsNullOrEmpty(walitem.UPC))
                                    {
                                        var itemSpecific = new OrderHistoryItemSpecific();
                                        itemSpecific.SellerItemID = row.ItemID;
                                        itemSpecific.ItemName     = "UPC";
                                        itemSpecific.ItemValue    = walitem.UPC;
                                        itemSpecific.Flags        = true;
                                        _repository.OrderHistoryItemSpecificUpdate(itemSpecific);
                                    }

                                    if (walitem.SupplierPrice.HasValue)
                                    {
                                        var oh = new OrderHistory();
                                        oh.ItemID = row.ItemID;
                                        var p = wallib.wmUtility.wmNewPrice(walitem.SupplierPrice.Value, pctProfit, wmShipping, wmFreeShippingMin, eBayPct);
                                        oh.ProposePrice   = p.ProposePrice;
                                        oh.MatchCount     = response.Count;
                                        oh.MatchType      = 1;
                                        oh.SourceID       = walitem.SourceID;
                                        oh.SupplierItemID = walitem.ID;
                                        _repository.OrderHistoryUpdate(oh, "ProposePrice", "MatchType", "MatchCount", "SourceID", "SupplierItemID");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                string msgItemID = (!string.IsNullOrEmpty(loopItemID)) ? "ItemID: " + loopItemID : "";
                string header    = "UPCMatch RptNumber: " + rptNumber.ToString() + " " + msgItemID;
                string msg       = dsutil.DSUtil.ErrMsg(header, exc);
                dsutil.DSUtil.WriteFile(_logfile, msg, "");
            }
        }