Beispiel #1
0
        private static void Main(string[] args)
        {
            VirusDAL virusDal = new VirusDAL();

            try
            {
                string url = "https://www.worldometers.info/coronavirus/";

                Task <IHtmlDocument> documentTask = GetHtmlDocument(url);

                documentTask.Wait();

                var document = documentTask.Result;

                CaseBlobs caseBlobs = GetCasesFromHtmlDoc(document);

                virusDal.SaveDataCaseBlob(caseBlobs);
            }
            catch (Exception e)
            {
                var error = new VirusErrorLog();

                error.ApplicationName  = "VirusScraper";
                error.ExceptionMessage = e.Message;
                error.StackTrace       = e.StackTrace;
                error.DateAdded        = DateTime.Now;

                virusDal.SaveErrorLog(error);
            }
        }
Beispiel #2
0
        private static CaseBlobs GetCasesFromHtmlDoc(IHtmlDocument document)
        {
            CaseBlobs c = new CaseBlobs();

            var stats = document.GetElementsByClassName("maincounter-number");


            c.DateScraped         = DateTime.Now;
            c.TotalCasesBlob      = stats[0].InnerHtml;
            c.TotalDeathsBlob     = stats[1].InnerHtml;
            c.TotalRecoveriesBlob = stats[2].InnerHtml;
            c.Processed           = false;


            return(c);
        }
Beispiel #3
0
        public List <CaseBlobs> GetUnprocessedCaseBlobs()
        {
            List <CaseBlobs> blobs = new List <CaseBlobs>();

            SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Josh;Integrated Security=SSPI;");

            connection.Open();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = @"SELECT [casesBlobId]
                                      ,[DateScraped]
                                      ,[TotalCasesBlob]
                                      ,[TotalDeathsBlob]
                                      ,[TotalRecoveriesBlob]
                                      ,[Processed]
                                  FROM [dbo].[CaseBlobs]
                                  WHERE Processed = 0";

            cmd.Connection = connection;

            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                CaseBlobs l = new CaseBlobs();

                l.casesBlobId         = reader.GetInt32(0);
                l.DateScraped         = reader.GetDateTime(1);
                l.TotalCasesBlob      = reader.GetString(2);
                l.TotalDeathsBlob     = reader.GetString(3);
                l.TotalRecoveriesBlob = reader.GetString(4);
                l.Processed           = reader.GetBoolean(5);


                blobs.Add(l);
            }

            cmd.Connection = connection;

            return(blobs);
        }
Beispiel #4
0
        public void SaveDataCaseBlob(CaseBlobs caseBlobs)
        {
            SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Josh;Integrated Security=SSPI;");

            connection.Open();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = @"Insert into CaseBlobs Values (@casesBlobId, @DateScraped, @TotalCasesBlob, @TotalDeathsBlob, @TotalRecoveriesBlob, @Processed)";

            cmd.Parameters.AddWithValue("@casesBlobId", caseBlobs.casesBlobId);
            cmd.Parameters.AddWithValue("@DateScraped", caseBlobs.DateScraped);
            cmd.Parameters.AddWithValue("@TotalCasesBlob", caseBlobs.TotalCasesBlob);
            cmd.Parameters.AddWithValue("@TotalDeathsBlob", caseBlobs.TotalDeathsBlob);
            cmd.Parameters.AddWithValue("@TotalRecoveriesBlob", caseBlobs.TotalRecoveriesBlob);
            cmd.Parameters.AddWithValue("@Processed", caseBlobs.Processed);

            cmd.Connection = connection;

            cmd.ExecuteNonQuery();

            connection.Close();
        }