Ejemplo n.º 1
0
        /// <summary>
        /// gets the amazon link of a post from the website
        /// </summary>
        /// <param name="driver"></param>
        /// <param name="wait"></param>
        /// <param name="post"></param>
        /// <returns></returns>
        public static String getLink(IWebDriver driver, WebDriverWait wait, Post post)
        {
            int    totalPages;
            String tag = Wordpress.SendGetTag(Wordpress.GetTag(post));

            driver.FindElement(By.XPath("//div [@class = 'wp-menu-image dashicons-before dashicons-admin-post']")).Click();
            if (driver.FindElements(By.XPath("//span [@class = 'total-pages']")).Count > 0)
            {
                totalPages = int.Parse(driver.FindElement(By.XPath("//span [@class = 'total-pages']")).Text);
            }
            else
            {
                totalPages = 1;
            }

            for (int x = 1; x <= totalPages; x++)
            {
                List <IWebElement> elements = driver.FindElements(By.XPath("//td [@class = 'tags column-tags']")).ToList();
                foreach (IWebElement element in elements)
                {
                    if (element.Text == tag)
                    {
                        return(driver.FindElement(By.XPath("(//span [@class = 'url'])[" + (elements.IndexOf(element) + 1).ToString() + "]")).GetAttribute("innerHTML"));
                    }
                }
                if (x != totalPages)
                {
                    driver.FindElement(By.XPath("//a [@class = 'next-page button']")).Click();
                    wait.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(By.XPath("//td [@id = 'cb']")));
                }
            }
            MessageBox.Show("Link not found");
            return("Not Found");
        }
Ejemplo n.º 2
0
        public static void WriteProducts()
        {
            SqlCommand cmd = new SqlCommand("TRUNCATE TABLE Products", con);

            cmd.ExecuteNonQuery();
            List <Post> WP = Wordpress.SendGetPosts(Wordpress.GetPosts());

            foreach (Post post in WP)
            {
                String id       = Wordpress.SendGetTag(Wordpress.GetTag(post));
                String name     = post.Title.Rendered;
                int    price    = int.Parse(Formatting.GetPrice(post.Content.Rendered));
                int    xprice   = int.Parse(Formatting.GetXprice(post.Content.Rendered));
                String category = Formatting.CatIDtoCategory(post.Categories[0]);
                String url      = post.Link;

                cmd.CommandText = $"INSERT INTO Products VALUES ('{id}', '{name}', {price}, {xprice}, '{category}', '{url}');";
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 3
0
        public static void WriteHHPosts()
        {
            IWorkbook wb = new XSSFWorkbook();
            ISheet    ws = wb.CreateSheet();

            IRow header = ws.CreateRow(0);

            header.CreateCell(0).SetCellValue("Name");
            header.CreateCell(1).SetCellValue("Price");
            header.CreateCell(2).SetCellValue("Old Price");
            header.CreateCell(3).SetCellValue("Difference");
            header.CreateCell(4).SetCellValue("Category");
            header.CreateCell(5).SetCellValue("ID");
            header.CreateCell(6).SetCellValue("URL");

            int         rowcount = 1;
            List <Post> WP       = Wordpress.SendGetPosts(Wordpress.GetPosts());

            foreach (Post post in WP)
            {
                IRow row = ws.CreateRow(rowcount);

                row.CreateCell(0).SetCellValue(post.Title.Rendered);
                row.CreateCell(1).SetCellValue(int.Parse(Formatting.GetPrice(post.Content.Rendered)));
                row.CreateCell(2).SetCellValue(int.Parse(Formatting.GetXprice(post.Content.Rendered)));
                row.CreateCell(3).SetCellValue(int.Parse(Formatting.GetXprice(post.Content.Rendered)) - int.Parse(Formatting.GetPrice(post.Content.Rendered)));
                row.CreateCell(4).SetCellValue(Formatting.CatIDtoCategory(post.Categories[0]));
                row.CreateCell(5).SetCellValue(Wordpress.SendGetTag(Wordpress.GetTag(post)));
                row.CreateCell(6).SetCellValue(post.Link);

                rowcount++;
            }

            ws.CreateRow(rowcount).CreateCell(0).SetCellValue("Stop");
            rowcount++;
            ws.CreateRow(rowcount).CreateCell(0).SetCellValue(DateTime.Now.ToString("D"));

            wb.Write(new FileStream(@"C:\Users\email\Desktop\Hardware Hub\HHPosts.xlsx", FileMode.Create, FileAccess.Write, FileShare.ReadWrite));
            wb.Close();
        }