Ejemplo n.º 1
0
 public static Advertisement GetAdvertisementBasedOnOffer(FlatOffer offer)
 {
     return(new Advertisement
     {
         Address = offer.Address,
         FlatSize = offer.FlatSize,
         FlatType = offer.FlatType,
         NumberOfRooms = offer.NumberOfRooms,
         Price = offer.Price,
         UniqueId = offer.Links.First().UniqueId,
         Url = offer.Links.First().Url,
         ImagesUrl = new System.Collections.Generic.List <string> {
             "www.FakeUrl.com"
         }
     });
 }
        protected FlatOffer GenerateOfferFromAdvertisement(int id, Advertisement ad, decimal?priceOverride = null)
        {
            var offer = new FlatOffer
            {
                Id            = id,
                Address       = ad.Address,
                FlatSize      = ad.FlatSize,
                FlatType      = ad.FlatType,
                NumberOfRooms = ad.NumberOfRooms,
                Price         = priceOverride.HasValue ? priceOverride.Value : ad.Price
            };

            offer.AddLink(ad.Url, ad.UniqueId);

            return(offer);
        }
Ejemplo n.º 3
0
        public IQueryableExtensionTests()
        {
            var offer1 = new FlatOffer
            {
                DateAdded = new DateTime(2020, 1, 10)
            };

            var offer2 = new FlatOffer
            {
                DateAdded   = new DateTime(2019, 1, 10),
                DateRemoved = new DateTime(2020, 1, 10)
            };

            _query = new List <FlatOffer> {
                offer1, offer2
            }.AsQueryable();
        }
Ejemplo n.º 4
0
        public void UpdateSavedOffer(MongoCRUD db, FlatOffer flatOffer)
        {
            FlatOffer flatOfferSaved = db.LoadRecordsById <FlatOffer>(CollectionName, flatOffer.Link);

            if (flatOfferSaved == null)
            {
                db.InsertRecord <FlatOffer>(CollectionName, flatOffer);
            }
            else
            {
                if (flatOfferSaved.Link == flatOffer.Link && !flatOffer.Equals(flatOfferSaved))
                {
                    Console.WriteLine($"updated {flatOfferSaved.Link}");
                    flatOfferSaved.AddState(flatOffer.State);
                    db.UpsertRecord <FlatOffer>(CollectionName, flatOfferSaved.Link, flatOfferSaved);
                }
            }
        }
Ejemplo n.º 5
0
        public static FlatOffer GetFlatOfferType1()
        {
            var offer = new FlatOffer
            {
                Address       = "Ble",
                FlatSize      = 80,
                FlatType      = FlatType.Brick,
                NumberOfRooms = 3,
                Price         = 800000
            };

            offer.Links = new List <Link> {
                new Link("http://ble.com", 496846, offer)
            };
            offer.Notifications = new List <Notification> {
                new Notification(offer, NotificationType.OfferAdded)
            };
            offer.Images = new List <Image> {
                new Image(new byte[] { 0x25, 0x16 }, 1, offer)
            };
            return(offer);
        }
Ejemplo n.º 6
0
        public static void SelectSupplier(this MfgBom.Bom.Part part, int design_quantity)
        {
            // Initialize SelectedSupplier fields
            part.SelectedSupplierPartCostPerUnit = null;
            part.SelectedSupplierName            = null;
            part.SelectedSupplierSku             = null;

            if (part.SellerMapStructure == null ||
                part.SellerMapStructure.sellerMap == null)
            {
                using (StringWriter sw = new StringWriter())
                    using (JsonTextWriter jtw = new JsonTextWriter(sw))
                    {
                        Newtonsoft.Json.JsonSerializer.Create(
                            new Newtonsoft.Json.JsonSerializerSettings()
                        {
                            Formatting        = Newtonsoft.Json.Formatting.Indented,
                            NullValueHandling = NullValueHandling.Ignore
                        })
                        .Serialize(jtw, part);

                        Console.Error.WriteLine("No sellers identified for part: " + Environment.NewLine + "{0}",
                                                sw.ToString());
                        return;
                    }
            }

            int quantityNeeded = design_quantity * part.quantity;

            // Flatten the supplier structures for easier sorting
            List <FlatOffer> offers = new List <FlatOffer>();

            foreach (var sellerToSku in part.SellerMapStructure.sellerMap)
            {
                foreach (var skuToCurrency in sellerToSku.Value.skuMap)
                {
                    foreach (var currencyToPricePoint in skuToCurrency.Value.currencyMap)
                    {
                        foreach (var pricePoint in currencyToPricePoint.Value)
                        {
                            offers.Add(new FlatOffer()
                            {
                                supplier = sellerToSku.Key,
                                sku      = skuToCurrency.Key,
                                currency = currencyToPricePoint.Key,
                                quantity = pricePoint.quantity,
                                price    = pricePoint.price
                            });
                        }
                    }
                }
            }

            var offersUSD = offers.Where(o => o.currency == "USD");

            if (false == offersUSD.Any())
            {
                Console.WriteLine("Could not find any offers in USD for part with MPN {0}", part.octopart_mpn);
                return;
            }

            var offersByPrice = offersUSD.OrderBy(o => o.price);

            // Best offer is the cheapest one where we exceed its threshold.
            FlatOffer bestOffer = offersByPrice.FirstOrDefault(o => o.quantity <= quantityNeeded);

            if (bestOffer == null)
            {
                // Take lowest-quantity break.
                // If there's a tie in quantities, it will be the cheapest, since we're sorted by price.
                bestOffer = offersByPrice.OrderBy(o => o.quantity).First();
            }

            part.SelectedSupplierPartCostPerUnit = bestOffer.price;
            part.SelectedSupplierName            = bestOffer.supplier;
            part.SelectedSupplierSku             = bestOffer.sku;
        }
Ejemplo n.º 7
0
 public Image(byte[] content, short sortOrder, FlatOffer flatOffer)
 {
     FlatOffer = flatOffer;
     Content   = content;
     SortOrder = sortOrder;
 }
Ejemplo n.º 8
0
 public Link(string url, long uniqueId, FlatOffer offer)
 {
     FlatOffer = offer;
     Url       = url;
     UniqueId  = uniqueId;
 }
Ejemplo n.º 9
0
        public Task UpdateOfferInfo(ChromeDriver chromeDriver)
        {
            return(Task.Run(() =>
            {
                MongoCRUD db = new MongoCRUD(DatabaseSecret, "FlatScraper");
                while (offerNum < offerLinks.Count)
                {
                    string url = "";
                    try
                    {
                        url = offerLinks[offerNum];
                        offerNum++;
                        Console.WriteLine($"{offerNum}/{offerLinks.Count}");
                        chromeDriver.Navigate().GoToUrl(url);
                        WaitTillLoaded(chromeDriver, "offerProps", 30);

                        Dictionary <string, string> stateProps = new Dictionary <string, string>();
                        // title properties
                        string titleProp = chromeDriver.FindElement(By.XPath(xpaths["titleProp"])).Text;
                        stateProps["titleProp"] = titleProp;
                        string address = chromeDriver.FindElement(By.XPath(xpaths["address"])).Text;
                        stateProps["address"] = address;
                        // string priceShort = chromeDriver.FindElement(By.XPath(xpaths["priceShort"])).Text;
                        // stateProps["priceShort"] = priceShort;

                        // body properties
                        IWebElement offerProps = chromeDriver.FindElement(By.XPath(xpaths["offerProps"]));
                        IReadOnlyList <IWebElement> propComposites = offerProps.FindElements(By.TagName("li"));
                        foreach (IWebElement prop in propComposites)
                        {
                            IWebElement propNameElement = prop.FindElement(By.TagName("label"));
                            string propName = propNameElement.Text.Split(':')[0];
                            IWebElement propValueElement = prop.FindElement(By.TagName("strong"));
                            string propValue = propValueElement.Text;
                            if (propValue != "")
                            {
                                stateProps[propName] = propValue;
                            }
                            else
                            {
                                IWebElement propIcon = prop.FindElements(By.TagName("span"))[1];
                                string iconClass = propIcon.GetAttribute("class");
                                stateProps[propName] = iconClass;
                            }
                        }

                        FlatOffer newFlatOffer = new FlatOffer
                        {
                            Link = url,
                            State = new FlatOfferState
                            {
                                LastChecked = DateTime.UtcNow,
                                Created = DateTime.UtcNow,
                                Properties = stateProps
                            },
                        };

                        UpdateSavedOffer(db, newFlatOffer);
                    }
                    catch (Exception e)
                    {
                        log.Information(url);
                        log.Information(e.ToString());
                    }
                }
            }));
        }
Ejemplo n.º 10
0
 public Notification(FlatOffer flatOffer, NotificationType type)
 {
     FlatOffer = flatOffer;
     Type      = type;
 }