Пример #1
0
        public void Write(int row, ShipData ship)
        {
            row++;
            if (ship == null)
            {
                return;
            }

            ws.Cells[row, 1].Value2         = ship.imo;
            ws.Cells[row, 2].Value2         = ship.name;
            ws.Cells[row, 3].Value2         = ship.departurePort;
            ws.Cells[row, 4].Value2         = ship.destinationPort;
            ws.Cells[row, 5].Value2         = ship.ATD;
            ws.Cells[row, 6].Value2         = ship.ETA;
            ws.Cells[row, 7].Formula        = string.Format("=IFERROR(LEFT($C{0}, SEARCH(CHAR(10), $C{0})-1),$C{0})& \" \" &MID($E{0},6,10)", row);
            ws.Cells[row, 8].Formula        = string.Format("=IFERROR(LEFT($D{0}, SEARCH(CHAR(10), $D{0})-1),$D{0})&\" \"&MID($F{0},6,10)", row);
            ws.Cells[row, 7].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
            ws.Cells[row, 8].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
        }
Пример #2
0
        public ShipData GetShipData(string imo)
        {
            Console.WriteLine("Getting vessel data");
            ShipData shipData = null;
            int      retries  = 0;

            while (retries < max_retry_count)
            {
                retries++;
                try
                {
                    driver.Navigate().GoToUrl(shipDataUrl + imo);
                }
                catch
                {
                    if (retries == max_retry_count)
                    {
                        Console.WriteLine("Couldn't connect site");
                        return(shipData);
                    }
                    else
                    {
                        Console.WriteLine("RetryCount: " + retries);
                    }
                }
            }
            retries = 0;
            while (retries < max_retry_count)
            {
                retries++;
                try
                {
                    Thread.Sleep(sleep_ms);
                    var t           = driver.FindElementById("vesselDetails_voyageInfoSection");
                    var detailItems = t.FindElements(By.ClassName("MuiGrid-item"));

                    shipData                 = new ShipData();
                    shipData.imo             = imo;
                    shipData.departurePort   = detailItems[1].Text;
                    shipData.destinationPort = detailItems[2].Text;
                    shipData.departurePort.Replace('\n', ' ');
                    shipData.destinationPort.Replace('\n', ' ');
                    shipData.ATD = detailItems[8].Text;
                    shipData.ETA = detailItems[9].Text;
                    var shipNameElement = driver.FindElement(By.TagName("h1"));
                    shipData.name = shipNameElement.Text;
                }
                catch
                {
                    if (retries == max_retry_count)
                    {
                        Console.WriteLine("COULDN'T GET THE DATA");
                    }
                    else
                    {
                        Console.WriteLine("Retry Count: " + retries);
                    }
                }
            }

            return(shipData);
        }
Пример #3
0
        private async void processButton_Click(object sender, EventArgs e)
        {
            processButton.Enabled = false;
            UpdatePercentage(0);
            Log("Arama Baþlatýlýyor.");
            Properties.Settings.Default.sleepTime  = (int)sleepTimeInput.Value;
            Properties.Settings.Default.retryCount = (int)retryCountInput.Value;
            Properties.Settings.Default.Save();
            try
            {
                sc = new Scraper(Properties.Settings.Default.retryCount, Properties.Settings.Default.sleepTime);
                Log("Tarayýcý açýldý.");
            }
            catch (Exception exception)
            {
                logList.Items.Add(exception.Message);
                processButton.Enabled = true;
                return;
            }
            string[] lines = new string[imoNumberInput.Lines.Length];
            imoNumberInput.Lines.CopyTo(lines, 0);
            await Task.Run(() =>
            {
                Excel excel = new Excel("save_file");        // @"C:\Users\Cengiz\Desktop\marine_test1.xlsx", 1);
                excel.Write(0, 0, "IMO");
                excel.Write(0, 1, "Name");
                excel.Write(0, 2, "Departure");
                excel.Write(0, 3, "Destination");

                excel.Write(0, 4, "ATD");
                excel.Write(0, 5, "ETA");

                for (int i = 0; i < lines.Length; i++)
                {
                    if (lines[i] == string.Empty)
                    {
                        UpdatePercentage((float)(i + 1) / lines.Length * 100);
                        continue;
                    }

                    Log("IMO:" + lines[i] + " verisi alýnýyor");
                    ShipData ship = sc.GetShipData(lines[i]);

                    if (ship != null)
                    {
                        excel.Write(i + 1, ship);
                        Log(lines[i] + " verisi alýndý.");
                    }
                    else
                    {
                        excel.Write(i + 1, 0, lines[i - 1]);
                        excel.Write(i + 1, 1, "VERÝ ALINAMADI.");
                        Log("IMO: " + lines[i] + " VERÝSÝ ALINAMADI.");
                    }
                    UpdatePercentage((float)(i + 1) / lines.Length * 100);

                    excel.Save();
                }
                excel.Close();
                excel.Display();
            });

            if (sc != null)
            {
                sc.Quit();
            }

            Log("Arama Bitti.");

            processButton.Enabled = true;
        }