コード例 #1
0
    #pragma warning restore 4014, 1998

        public static void ConvertCsvToDynamo(string path)
        {
            StreamReader reader = null;

            try
            {
                AmazonDynamoDBClient client = Logger.createClient();
                Table priceTable            = Table.LoadTable(client, "LotPrices");
                reader = new StreamReader(path, true);
                do
                {
                    string  item = reader.ReadLine();
                    LotItem i    = new LotItem(item);

                    Document newItemDocument = new Document();
                    newItemDocument["Id"]    = i.LotNumber;
                    newItemDocument["Year"]  = i.Year;
                    newItemDocument["Info"]  = i.MakeModel;
                    newItemDocument["Price"] = i.Bid;

                    priceTable.PutItemAsync(newItemDocument).Wait();
                } while (reader.Peek() > 0);
                reader?.Close();
            }
            catch
            {
                reader?.Close();
            }
        }
コード例 #2
0
    #pragma warning disable 4014, 1998
        public async void Log(LotItem item)
        {
            int    index = -1;
            string bid   = "??";

            // Remove $ and , before saving
            if (item.Bid != null)
            {
                bid   = item.Bid;
                index = bid.IndexOf('$');
                if (index >= 0)
                {
                    bid = bid.Remove(0, 1);
                }

                index = bid.IndexOf(',');
                if (index >= 0)
                {
                    bid = bid.Remove(index, 1);
                }
            }

            string logItem = $"{item.LotNumber}, {item.Year}, {item.MakeModel}, {bid}";
            await writer.WriteLineAsync(logItem);
        }
コード例 #3
0
ファイル: PriceScraper.cs プロジェクト: TJbrunk/PriceGrabber
        private void Scrape()
        {
            try
            {
                // Check if a new lot has started
                LotItem newLot = this.GetLotDetails();
                if (newLot != null && this.currentLot.LotNumber != newLot.LotNumber)
                {
                    // New lot, save the last lot details
                    this.logger.Log(this.currentLot);

                    Console.WriteLine($"High bid: {currentLot.Bid}");

                    newLot.Bid = GetBid();

                    Console.Write($"New Lot: {newLot}");
                    // Update the current lot to the new lot
                    this.currentLot = newLot;
                }
                else
                {
                    // Same lot as last call, Check for a new bid
                    string newBid = this.GetBid();
                    currentLot.Bid = string.IsNullOrEmpty(newBid) ? currentLot.Bid : newBid;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine($"ERROR: {ex}");
                this.auctionRunning = false;
            }
        }
コード例 #4
0
ファイル: PriceScraper.cs プロジェクト: TJbrunk/PriceGrabber
 public Task Start()
 {
     try
     {
         this.webDriver = this.CreateWebDriver();
         this.PrepareWebDriver();
         // Get all the info about the current lot
         this.currentLot = this.GetLotDetails();
         if (currentLot != null)
         {
             this.currentLot.Bid = this.GetBid();
             Console.Write($"First lot: {this.currentLot}");
             this.task.Start();
             return(this.task);
         }
     }
     catch (System.Exception ex)
     {
         Console.WriteLine($"Error in price scrapper. {ex}");
     }
     // return a completed task immediatly
     return(Task.Run(() => {}));
 }
コード例 #5
0
ファイル: PriceScraper.cs プロジェクト: TJbrunk/PriceGrabber
        // Try's to find the LotDescription on the current page.
        // Will stop Scaper task if 'sale-end' element is found
        // Returns NULL if details aren't found
        private LotItem GetLotDetails()
        {
            LotItem i;

            try
            {
                //*[@id="lotDesc-COPART078A"]
                IWebElement lotDescription = webDriver.FindElement(By.ClassName("lotdesc"));
                i = new LotItem(lotDescription);
            }
            // IFrame might update while looking up the lot number. Continue
            catch (StaleElementReferenceException)
            {
                i = null;
            }
            catch (NoSuchElementException)
            {
                try
                {
                    // Couldn't find the lot description.
                    // Check if the sale is over
                    IWebElement ended = webDriver.FindElement(By.ClassName("sale-end"));
                    i = null;
                    if (ended != null)
                    {
                        Console.WriteLine($"Auction {this.auctionId} Ended");
                    }
                    this.auctionRunning = false;
                }
                catch (System.Exception)
                {
                    i = null;
                    this.auctionRunning = false;
                }
            }
            return(i);
        }