예제 #1
0
        public static Boolean ContainsItem(EbayItem ei)
        {
            //geval 1 ,check matching id's
            //geval 2 ,zowel titel ,startprice als imageurl zijn gelijk
            //

            string          query = "select * from lootcrate.ebay where itemid='" + ei.ItemID + "' ;";
            MySqlConnection conn  = EstablishConn();
            MySqlCommand    comm  = new MySqlCommand(query, conn);

            MySqlDataReader dataReader = comm.ExecuteReader();
            Boolean         hasrows    = dataReader.HasRows;

            dataReader.Close();
            if (hasrows == true)
            {
                conn.Close();
                return(true);
            }
            else
            {
                string query2 = "select * from lootcrate.ebay where imageurl='" + ei.PictureUrl +
                                "' and title='" + ei.Title +
                                "' and startprice='" + ei.Startprice + "';";
                comm       = new MySqlCommand(query, conn);
                dataReader = comm.ExecuteReader();
                hasrows    = dataReader.HasRows;
            }
            conn.Close();
            return(hasrows);
        }
예제 #2
0
 /// <summary>
 /// Takes an eBayItem and tries to generate a SKU from it
 /// </summary>
 /// <param name="ebayItem"></param>
 /// <returns></returns>
 public static string GetSKUFromItem(EbayItem ebayItem)
 {
     try
     {
         var v   = ebayItem.Colour.Replace(" ", "").ToLower();
         var e   = Enum.Parse(typeof(ColourCode), v);
         var x   = Enum.Format(typeof(ColourCode), e, "d").PadLeft(3, '0');
         var SKU = ebayItem.Item + x + ebayItem.Size.ToString().PadLeft(3, 'O');
         return(SKU);
     }
     catch
     {
         Process.Summary.AppendLine("Couldn't parse eBayItem");
         return("");
     }
 }
예제 #3
0
        public IList <EbayItem> getDetails(string search)
        {
            List <EbayItem> items = new List <EbayItem>();

            /*
             * eBay API Details
             *
             **/
            string service_url = "https://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=";
            string appId       = "SimonGie-lapscrap-PRD-e5d8a3c47-da2fb544";
            string operations  = "&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&keywords=";
            string keywords    = search;
            string settings    = "&itemFilter(0).name=Condition&itemFilter(0).value=2000&itemFilter(0).value=2500&itemFilter(0).value=3000&paginationInput.entriesPerPage=12&GLOBAL-ID=EBAY-DE&siteid=77";

            string url = service_url + appId + operations + keywords + settings;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            // Set credentials to use for this request.
            request.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            // Get the stream associated with the response.
            Stream receiveStream = response.GetResponseStream();

            // Pipes the stream to a higher level stream reader with the required encoding format.
            StreamReader readStream   = new StreamReader(receiveStream, Encoding.UTF8);
            string       ebayResponse = readStream.ReadToEnd();

            response.Close();
            readStream.Close();

            // Malformed json String --> replace unfitting parts
            ebayResponse = ebayResponse.Replace("/**/_cb_findItemsByKeywords(", "");
            ebayResponse = ebayResponse.Remove(ebayResponse.Length - 1, 1);

            JsonTextReader reader     = new JsonTextReader(new StringReader(ebayResponse));
            JObject        ebayParser = JObject.Parse(ebayResponse);
            JToken         jEbay      = ebayParser.First.First.First["searchResult"][0];

            foreach (JToken item in jEbay["item"])
            {
                EbayItem eItem = new EbayItem(item);
                items.Add(eItem);
            }
            return(items);
        }
예제 #4
0
        /// <summary>
        /// Takes an eBay item description,
        /// and converts this into an EbayItem object with it's own Description, Colour, Size and Item type enum properties
        /// </summary>
        /// <param name="itemDescription">An eBay itemdescription such as: "Plain Zipped Hooded Sweatshirt Boys Girls Childrens Kids Hoodie All Colours"</param>
        /// <returns>EbayItem object</returns>
        public static EbayItem ParseEbayItem(string itemDescription)
        {
            //try
            //{
            EbayItem ebayItem = new EbayItem();

            if (itemDescription.Contains("\r\n"))
            {
                itemDescription = itemDescription.Replace("\r\n", "");
            }
            Match match = Regex.Match(itemDescription, @"(.*)\[(Black|Red|Charcoal|Navy Blue|Navy|Light Grey|Royal Blue|Green|Turquoise Blue|Turquise Blue|Orange|Baby Pink|Sky Blue|Purple|Beige)\s*,(.*)\s*\]*", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                ebayItem.Decription = match.Groups[1].Value.Trim();
                ebayItem.Colour     = match.Groups[2].Value;
                ebayItem.Item       = DetermineItemTypeFromDescription(ebayItem.Decription);
                ebayItem.Size       = DetermineItemSizeFromSizestring(match.Groups[3].Value, ebayItem.Item);
                ebayItem.SKU        = GetSKUFromItem(ebayItem);
                return(ebayItem);
            }
            else
            {
                Match matchOtherWay = Regex.Match(itemDescription, @"(.*)\[(.*),(Black|Red|Charcoal|Navy Blue|Navy|Light Grey|Royal Blue|Green|Turquoise Blue|Turquise Blue|Orange|Baby Pink|Sky Blue|Purple|Beige)\s*\]*", RegexOptions.IgnoreCase);
                if (matchOtherWay.Success)
                {
                    ebayItem.Decription = matchOtherWay.Groups[1].Value.Trim();
                    ebayItem.Colour     = matchOtherWay.Groups[3].Value;
                    ebayItem.Item       = DetermineItemTypeFromDescription(ebayItem.Decription);
                    ebayItem.Size       = DetermineItemSizeFromSizestring(matchOtherWay.Groups[2].Value, ebayItem.Item);
                    ebayItem.SKU        = GetSKUFromItem(ebayItem);
                    return(ebayItem);
                }
            }
            return(null);
            //}
            //catch
            //{
            //    Process.Summary.AppendLine ("not an ebay item");
            //    return null;
            //}
        }
예제 #5
0
        public static void AddEbayItemToDB(EbayItem ei)
        {
            MySqlConnection conn = EstablishConn();

            try
            {
                String query = "insert into lootcrate.ebay(itemid,title,url,startprice,endprice,clock,followers,imageurl) " +
                               "values ('" + ei.ItemID + "','" + ei.Title + "','" + ei.Url + "','" + ei.Startprice + "','" + ei.Endprice + "','" + ei.Date + "','" + ei.Followers + ei.PictureUrl + "');";
                MySqlCommand comm = new MySqlCommand(query, conn);
                comm.ExecuteNonQuery();
                conn.Close();
            } catch (Exception e)
            {
                conn.Close();
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine("Error : trying to write to DB.");
                Console.WriteLine("EbayItemdetails: " + ei);
            }
        }
예제 #6
0
        internal async Task <EbayProduct> Get(string productId)
        {
            EbayItem item = await httpService.Get <EbayItem>(
                string.Format(getSingleItem, productId), null,
                (content) => { return(JsonConvert.DeserializeObject <EbayItem>(content)); });

            EbayProduct product = new EbayProduct();

            product.Condition     = item?.Item?.ConditionDisplayName;
            product.GalleryURL    = item?.Item?.GalleryURL;
            product.ItemId        = item?.Item?.ItemId;
            product.Location      = item?.Item?.Location;
            product.PaymentMethod = item?.Item?.PaymentMethods?[0];
            product.CategoryName  = item?.Item?.PrimaryCategoryName;
            product.CurrencyId    = item?.Item?.CurrentPrice?.CurrencyId;
            product.CurrentPrice  = item?.Item?.CurrentPrice?.Value;
            product.Title         = item?.Item?.Title;
            product.Subtitle      = item?.Item?.Subtitle;
            product.ViewItemURL   = item?.Item?.ViewItemURLForNaturalSearch;

            return(await Task.FromResult <EbayProduct>(product));
        }
예제 #7
0
        public IHttpActionResult GetItem(string ItemId)
        {
            var res = EbayItem.GetItemRequest(ItemId);

            return(Json(res));
        }
예제 #8
0
        //create ebayitems and returns url to next page
        public override List <EbayItem> CreateItems(String filename)
        {
            HtmlDocument doc  = new HtmlDocument();
            var          path = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this.GetType().Name), filename);

            doc.Load(path, Encoding.UTF8);
            EbayItem        ei;
            List <EbayItem> list = new List <EbayItem>();

            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//li[@class='s-item  ']"))
            {
                try
                {
                    String itemlink = GetItemLink(node);
                    String itemid   = TextExtractorEbayCom.ExtractItemIdFromUrl(itemlink);
                    String piclink  = GetImageLink(node);
                    String title    = GetTitle(node);

                    int followers = GetFollowers(node);

                    String location = "";
                    if (node.InnerHtml.Contains("From"))
                    {
                        location = GetLocation(node);
                    }

                    DateTime clock = DateTime.Now;
                    if (node.InnerHtml.Contains("Time left"))
                    {
                        foreach (HtmlNode n in node.SelectNodes("descendant::span[contains(@class,'s-item__time-left')]"))
                        {
                            clock = TextExtractorEbayCom.ExtractEbayComTimeLeft(n.OuterHtml, DateTime.Now);
                        }
                    }
                    double exchange = Double.Parse(Properties.Resources.europerdollar);

                    string price      = node.SelectSingleNode("descendant::span[contains(@class,'s-item__price')]").InnerText;
                    double startPrice = exchange * Double.Parse(TextExtractorEbayCom.ExtractEbayComStartPrice(price));
                    double endPrice   = exchange * Double.Parse(TextExtractorEbayCom.ExtractEbayComEndPrice(price));
                    double shipping   = 0;
                    if (node.InnerHtml.Contains("shipping"))
                    {
                        shipping = exchange * TextExtractorEbayCom.ExtractShipping(node.SelectSingleNode("descendant::span[contains(@class,'s-item__shipping s-item__logisticsCost')]").InnerText);
                    }

                    if (startPrice > 0)
                    {
                        ei = new EbayItem(startPrice, endPrice, title, itemlink, itemid, clock, followers, shipping, location, piclink);
                        list.Add(ei);
                        Console.Write("+");
                    }
                    else
                    {
                        ei = new EbayItem(startPrice, endPrice, title, itemlink, itemid, clock, followers, shipping, location, piclink);
                        list.Add(ei);
                        Console.WriteLine("==================================================\n" + ei);
                    }
                }
                catch (Exception e)
                {
                    CsvController.CreateDocument(list, filename + ".csv");
                    Console.WriteLine("Problem with creating Ebayitem, check " + filename + ".csv");
                    Console.WriteLine(e.Message);
                }
            }

            return(list);
        }
예제 #9
0
        //create ebayitems
        public override List <EbayItem> CreateItems(String filename)
        {
            HtmlDocument doc  = new HtmlDocument();
            var          path = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this.GetType().Name), filename);

            doc.Load(path, Encoding.UTF8);
            EbayItem        ei;
            List <EbayItem> list = new List <EbayItem>();

            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//li[@class='sresult lvresult clearfix li' or @class='sresult lvresult clearfix li shic']"))
            {
                try
                {
                    //Console.WriteLine("#########");
                    string itemid   = node.Attributes["id"].Value;
                    string itemlink = node.SelectSingleNode(".//h3[@class='lvtitle']").SelectSingleNode("a").Attributes["href"].Value;
                    string piclink  = node.SelectSingleNode(".//div[@class='lvpicinner full-width picW']").SelectSingleNode(".//img").Attributes["src"].Value;

                    //check once if there exists a better picurl , 2nd condition makes sure there even is an imageurl
                    if (piclink.Contains(".gif") && node.SelectSingleNode(".//div[@class='lvpicinner full-width picW']").SelectSingleNode(".//img").Attributes["imgurl"] != null)
                    {
                        piclink = node.SelectSingleNode(".//div[@class='lvpicinner full-width picW']").SelectSingleNode(".//img").Attributes["imgurl"].Value;
                    }
                    //Console.WriteLine(itemid+"\n"+itemlink+"\n"+piclink);
                    string title     = TextExtractorEbayCoUk.ExtractTitle(node.SelectSingleNode(".//h3[@class='lvtitle']").SelectSingleNode("a").Attributes["title"].Value);
                    int    followers = int.Parse(TextExtractorEbayCoUk.ExtractFollowers(node.SelectSingleNode(".//li[@class='lvextras']").InnerText.TrimEnd().TrimStart()));
                    string location  = "";
                    if (null != node.SelectSingleNode(".//ul[@class='lvdetails left space-zero full-width']"))
                    {
                        location = TextExtractorEbayCoUk.ExtractLocation(node.SelectSingleNode(".//ul[@class='lvdetails left space-zero full-width']").InnerHtml);
                    }

                    else
                    {
                        location = null;
                    }
                    //Console.WriteLine(title + "\n" + followers + "\n" + location);
                    string timeleft = null;
                    if (null != node.SelectSingleNode(".//span[@class='tme']"))
                    {
                        timeleft = TextExtractorEbayCom.ExtractTime(node.SelectSingleNode(".//span[@class='tme']").InnerHtml);
                    }
                    DateTime clock = GetEnddate(timeleft);

                    double exchange = Double.Parse(Properties.Resources.europerpound);

                    string price = node.SelectSingleNode(".//li[@class='lvprice prc']").InnerText.TrimStart().TrimEnd();
                    //Console.WriteLine("====="+price);
                    double startPrice = exchange * Double.Parse(TextExtractorEbayCoUk.ExtractEbayCoUkStartPrice(price));

                    double endPrice = exchange * Double.Parse(TextExtractorEbayCoUk.ExtractEbayCoUkEndPrice(price));
                    //Console.WriteLine(clock+"\n"+ startPrice + "\n" + endPrice + "\n");
                    double shipping;
                    if (null != node.SelectSingleNode("//span[@class='ship']"))
                    {
                        shipping = exchange * Double.Parse(TextExtractorEbayCoUk.ExtractShippingEbayCoUk(node.SelectSingleNode(".//span[@class='ship']").InnerText));
                    }
                    else
                    {
                        shipping = 0;
                    }

                    if (startPrice > 0)
                    {
                        ei = new EbayItem(startPrice, endPrice, title, itemlink, itemid, clock, followers, shipping, location, piclink);
                        list.Add(ei);
                        Console.Write("+");
                    }
                    else
                    {
                        ei = new EbayItem(startPrice, endPrice, title, itemlink, itemid, clock, followers, shipping, location, piclink);
                        list.Add(ei);
                        Console.Write("+");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Problem with creating Ebayitem");
                    Console.WriteLine(e.Message);
                }
            }
            return(list);
        }