Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            FileReader handler = new FileReader();

            HtmlService htmlService = new HtmlService();

            Console.WriteLine("Enter full path to file...");
            string path = Console.ReadLine();
            IEnumerable<string> companies = handler.ReadAllRows(path);
            decimal counter = 0;

            var itemList = new List<ProfileListItem>();
            foreach (var companyName in companies)
            {
                Thread.Sleep(2000);
                var html = await htmlService.GetDocument($"https://www.allabolag.se/what/{companyName}");
                try
                {
                    Result<ProfileListItem> item = new ProfileBuilder().Build(new ProfileListItemStrategy(html));
                    counter++;
                    Console.Clear();

                    Console.WriteLine($"{(counter / companies.Count()):P2}");
                }
                catch (AggregateException)
                {

                    itemList.Add(new ProfileListItem { Header = companyName });
                }
            }

            using (StreamWriter outputFile = new StreamWriter("C:\\Users\\F.Boethius-Fjarem\\source\\repos\\AllaBolag\\AllaBolag.Infrastructure.Tests\\Companies_Output.csv"))
            {
                outputFile.WriteLine($"Bolagsnamn\tOrg.Nr\tCEO\tTelefon\tAntal Anställda\tOmsättning(tkr)\tBRUTTOVINSTMARGINAL\tVINSTMARGINAL\tKASSALIKVIDITET\tSOLIDITET");
                counter = 0;
                foreach (ProfileListItem item in itemList.Where(i => !string.IsNullOrEmpty(i.ProfileLink)))
                {
                    counter++;
                    Console.Clear();
                    Console.WriteLine($"{counter / itemList.Count:P4}");
                    try
                    {
                        Task<HtmlResult> document = htmlService.GetDocument(item.ProfileLink);
                        string result = new ProfileBuilder().Build(new ProfileItemStrategy(document.Result)).ToString();
                        outputFile.WriteLine(result);
                    }
                    catch (Exception)
                    {

                        outputFile.WriteLine(new ProfileItem { CompanyName = item.Header }.ToString());
                    }

                    Thread.Sleep(2000);

                }
            }
        }
Ejemplo n.º 2
0
        public void Get_Item_By_Url_Returns_Existing_Organisation_Number()
        {
            //Arrange
            var document = _htmlService.GetDocument("https://www.allabolag.se/5564480282/atea-sverige-ab").Result;
            var expected = new ProfileItem()
            {
                CompanyName        = "Atea Sverige AB",
                OrganisationNumber = "556448-0282",
            };
            //Act
            var actual = _profileBuilder.Build(new ProfileItemStrategy(document));

            //Assert
            Assert.AreEqual(expected.OrganisationNumber, actual.Object.OrganisationNumber);
        }