public List <Region> GetRegions(bool reload = false) { if (!reload && regions != null) { return(regions); } regions = new List <Region>(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(regionsUrl); } catch (Exception e) { regions = null; throw new LocationLoadException(); } JArray arr = JArray.Parse(json); foreach (JObject x in arr) { Region r = new Region(); r.Id = Int32.Parse(x["id"].ToString()); r.Name = x["name"].ToString(); regions.Add(r); } return(regions.Count == 0 ? null : regions); }
public List <Advertisement> GetClosed() { List <Advertisement> list = new List <Advertisement>(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(web.DownloadString(oldItemsUrl)); HtmlNodeCollection all = doc.DocumentNode.SelectNodes("//div[contains(@class,'item')]"); if (all != null) { foreach (HtmlNode node in all) { Advertisement ad = new Advertisement(); ad.Id = Int32.Parse(node.SelectSingleNode(".//input").GetAttributeValue("value", "0")); ad.Url = baseUrlSecure + node.SelectSingleNode(".//a[starts-with(@name,'item_')]").GetAttributeValue("href", ""); ad.Title = node.SelectSingleNode(".//a[starts-with(@name,'item_')]").InnerText; ad = Get(ad.Url); list.Add(ad); } } return(list); }
public UserLocation Default(bool reload = false) { if (!reload && def != null) { return(def); } def = new UserLocation(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); try { doc.LoadHtml(web.DownloadString(settingsUrl)); } catch (Exception e) { def = null; throw new LocationLoadException(); } HtmlNode tmp; // City tmp = doc.DocumentNode.SelectSingleNode("//*[@id='region']/option[@selected]"); if (tmp != null) { def.City = new City { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } // Metro tmp = doc.DocumentNode.SelectSingleNode("//*[@id='metro_id']/option[@selected]"); if (tmp != null) { def.Metro = new Metro { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } // District tmp = doc.DocumentNode.SelectSingleNode("//*[@id='district_id']/option[@selected]"); if (tmp != null) { def.District = new District { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } return(def); }
public UserLocation Default(bool reload = false) { if (!reload && def != null) return def; def = new UserLocation(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); try { doc.LoadHtml(web.DownloadString(settingsUrl)); } catch(Exception e) { def = null; throw new LocationLoadException(); } HtmlNode tmp; // City tmp = doc.DocumentNode.SelectSingleNode("//*[@id='region']/option[@selected]"); if (tmp != null) { def.City = new City { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } // Metro tmp = doc.DocumentNode.SelectSingleNode("//*[@id='metro_id']/option[@selected]"); if (tmp != null) { def.Metro = new Metro { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } // District tmp = doc.DocumentNode.SelectSingleNode("//*[@id='district_id']/option[@selected]"); if (tmp != null) { def.District = new District { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } return def; }
public User GetDefault(bool reload = false) { if (!reload && def != null) { return(def); } def = new User(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); try { doc.LoadHtml(web.DownloadString(settingsUrl)); } catch (Exception e) { def = null; throw new UserLoadException(); } string tmp; // Id def.Id = Int32.Parse(doc.DocumentNode.SelectSingleNode("//*[@id='profile']/div[1]/div[2]/div[3]/div[1]/div[2]/span").InnerText); // Name def.Name = doc.DocumentNode.SelectSingleNode("//*[@id='fld_name']").GetAttributeValue("value", ""); // Manager def.Manager = doc.DocumentNode.SelectSingleNode("//*[@id='fld_manager']").GetAttributeValue("value", ""); // Phone def.Phone = doc.DocumentNode.SelectSingleNode("//*[@id='fld_phone']").GetAttributeValue("value", ""); // Email tmp = doc.DocumentNode.SelectSingleNode("//*[@id='profile']/div[1]/div[2]/div[3]/div[1]/div[1]/span").InnerText; tmp = tmp.Substring(0, tmp.IndexOf(' ')); def.Email = tmp; // Deny emails // TODO: get from local settings return(def); }
public User GetDefault(bool reload = false) { if (!reload && def != null) return def; def = new User(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); try { doc.LoadHtml(web.DownloadString(settingsUrl)); } catch(Exception e) { def = null; throw new UserLoadException(); } string tmp; // Id def.Id = Int32.Parse(doc.DocumentNode.SelectSingleNode("//*[@id='profile']/div[1]/div[2]/div[3]/div[1]/div[2]/span").InnerText); // Name def.Name = doc.DocumentNode.SelectSingleNode("//*[@id='fld_name']").GetAttributeValue("value", ""); // Manager def.Manager = doc.DocumentNode.SelectSingleNode("//*[@id='fld_manager']").GetAttributeValue("value", ""); // Phone def.Phone = doc.DocumentNode.SelectSingleNode("//*[@id='fld_phone']").GetAttributeValue("value", ""); // Email tmp = doc.DocumentNode.SelectSingleNode("//*[@id='profile']/div[1]/div[2]/div[3]/div[1]/div[1]/span").InnerText; tmp = tmp.Substring(0, tmp.IndexOf(' ')); def.Email = tmp; // Deny emails // TODO: get from local settings return def; }
public List <Road> GetRoads(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(roadsUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return(null); } List <Road> roads = new List <Road>(); foreach (JObject x in arr) { Road r = new Road(); r.Id = Int32.Parse(x["id"].ToString()); r.Name = x["name"].ToString(); roads.Add(r); } return(roads.Count == 0 ? null : roads); }
public List <District> GetDistricts(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(districtsUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return(null); } List <District> districts = new List <District>(); foreach (JObject x in arr) { District d = new District(); d.Id = Int32.Parse(x["id"].ToString()); d.Name = x["name"].ToString(); districts.Add(d); } return(districts.Count == 0 ? null : districts); }
public List <Metro> GetMetros(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(metrosUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return(null); } List <Metro> metros = new List <Metro>(); foreach (JObject x in arr) { Metro m = new Metro(); m.Id = Int32.Parse(x["id"].ToString()); m.Name = x["name"].ToString(); metros.Add(m); } return(metros.Count == 0 ? null : metros); }
public List <City> GetCities(int RegionId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(citiesUrl, RegionId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return(null); } List <City> cities = new List <City>(); foreach (JObject x in arr) { City c = new City(); c.Id = Int32.Parse(x["id"].ToString()); c.Name = x["name"].ToString(); cities.Add(c); } return(cities.Count == 0 ? null : cities); }
public List<Road> GetRoads(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(roadsUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return null; } List<Road> roads = new List<Road>(); foreach (JObject x in arr) { Road r = new Road(); r.Id = Int32.Parse(x["id"].ToString()); r.Name = x["name"].ToString(); roads.Add(r); } return roads.Count == 0 ? null : roads; }
public List<Region> GetRegions(bool reload = false) { if (!reload && regions != null) return regions; regions = new List<Region>(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(regionsUrl); } catch (Exception e) { regions = null; throw new LocationLoadException(); } JArray arr = JArray.Parse(json); foreach (JObject x in arr) { Region r = new Region(); r.Id = Int32.Parse(x["id"].ToString()); r.Name = x["name"].ToString(); regions.Add(r); } return regions.Count == 0 ? null : regions; }
public List<Metro> GetMetros(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(metrosUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return null; } List<Metro> metros = new List<Metro>(); foreach (JObject x in arr) { Metro m = new Metro(); m.Id = Int32.Parse(x["id"].ToString()); m.Name = x["name"].ToString(); metros.Add(m); } return metros.Count == 0 ? null : metros; }
public List<District> GetDistricts(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(districtsUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return null; } List<District> districts = new List<District>(); foreach (JObject x in arr) { District d = new District(); d.Id = Int32.Parse(x["id"].ToString()); d.Name = x["name"].ToString(); districts.Add(d); } return districts.Count == 0 ? null : districts; }
public Advertisement Get(string url) { string tmpurl = url; url = editUrl + url.Substring(url.IndexOf(".ru/") + 4).Replace('/', '_'); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(web.DownloadString(url)); HtmlNode node = doc.DocumentNode.SelectSingleNode("//form[@id='f_item']"); HtmlNode tmp; Advertisement ad = new Advertisement(); ad.User = new UserInfo.User(); ad.Location = new UserLocation(); ad.Parameters = new Dictionary<int, int>(); ad.Images = new List<Image>(); // Id ad.Id = Int32.Parse(url.Substring(url.LastIndexOf('_') + 1)); // URL ad.Url = tmpurl; // Title ad.Title = ""; // Body ad.Body = node.SelectSingleNode("//*[@name='description']").InnerText; // Name //ad.User.Name = "������� ����"; // Manager ad.User.Manager = node.SelectSingleNode("//*[@name='manager']").GetAttributeValue("value", ""); // Phone ad.User.Phone = node.SelectSingleNode("//*[@name='phone']").GetAttributeValue("value", ""); // Allow Mails ad.User.DenyEmails = node.SelectSingleNode("//*[@name='allow_mails']").GetAttributeValue("checked", "xxx") == "xxx"; // Email //ad.User.Email = "*****@*****.**"; // Location // Region ad.Location.Region = new Region { Id = Int32.Parse(node.SelectSingleNode("//*[@id='region']").GetAttributeValue("value", "0")) }; // City ad.Location.City = new City { Id = Int32.Parse(node.SelectSingleNode("//*[@name='location_id']").GetAttributeValue("value", "0")) }; // Metro tmp = node.SelectSingleNode("//*[@name='metro_id']//*[@selected]"); if (tmp != null) ad.Location.Metro = new Metro { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) }; // Road tmp = node.SelectSingleNode("//*[@name='road_id']//*[@selected]"); if (tmp != null) ad.Location.Road = new Road { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) }; // District tmp = node.SelectSingleNode("//*[@name='district_id']//*[@selected]"); if (tmp != null) ad.Location.District = new District { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) }; // End Location // Category ad.CategoryId = Int32.Parse(node.SelectSingleNode("//*[@name='category_id']").GetAttributeValue("value", "")); // Parameters HtmlNodeCollection par = node.SelectNodes("//*[contains(@name,'params')]"); foreach (HtmlNode x in par) { string id = x.GetAttributeValue("name", "").Substring(7); id = id.Substring(0, id.IndexOf(']')); int value = Int32.Parse(x.SelectSingleNode(".//*[@selected]").GetAttributeValue("value", "")); ad.Parameters.Add(Int32.Parse(id), value); } // Geo tmp = node.SelectSingleNode("//*[@name='coords[lat]']"); if (tmp != null) { ad.Coordinates = new GeoCoords { Latitude = tmp.GetAttributeValue("value", ""), Longitude = node.SelectSingleNode("//*[@name='coords[lng]']").GetAttributeValue("value", ""), Zoom = node.SelectSingleNode("//*[@name='coords[zoom]']").GetAttributeValue("value", "") }; } // Price ad.Price = Int32.Parse(node.SelectSingleNode("//*[@name='price']").GetAttributeValue("value", "")); // Images par = node.SelectSingleNode("//*[@name='images[]']").ParentNode.SelectNodes(".//img"); foreach (HtmlNode x in par) { string[] arr = x.GetAttributeValue("src", "").Split('/'); arr[3] = "640x480"; byte[] data; try { data = web.DownloadData(String.Join("/", arr)); } catch (Exception e) { return null; } MemoryStream ms = new MemoryStream(); ms.Write(data, 0, data.Length); Image im = Image.FromStream(ms); ad.Images.Add(im); } // End return ad; }
public List<City> GetCities(int RegionId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(citiesUrl,RegionId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch(Exception e) { return null; } List<City> cities = new List<City>(); foreach (JObject x in arr) { City c = new City(); c.Id = Int32.Parse(x["id"].ToString()); c.Name = x["name"].ToString(); cities.Add(c); } return cities.Count == 0 ? null : cities; }
public Advertisement Get(string url) { string tmpurl = url; url = editUrl + url.Substring(url.IndexOf(".ru/") + 4).Replace('/', '_'); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(web.DownloadString(url)); HtmlNode node = doc.DocumentNode.SelectSingleNode("//form[@id='f_item']"); HtmlNode tmp; Advertisement ad = new Advertisement(); ad.User = new UserInfo.User(); ad.Location = new UserLocation(); ad.Parameters = new Dictionary <int, int>(); ad.Images = new List <Image>(); // Id ad.Id = Int32.Parse(url.Substring(url.LastIndexOf('_') + 1)); // URL ad.Url = tmpurl; // Title ad.Title = ""; // Body ad.Body = node.SelectSingleNode("//*[@name='description']").InnerText; // Name //ad.User.Name = "Частное лицо"; // Manager ad.User.Manager = node.SelectSingleNode("//*[@name='manager']").GetAttributeValue("value", ""); // Phone ad.User.Phone = node.SelectSingleNode("//*[@name='phone']").GetAttributeValue("value", ""); // Allow Mails ad.User.DenyEmails = node.SelectSingleNode("//*[@name='allow_mails']").GetAttributeValue("checked", "xxx") == "xxx"; // Email //ad.User.Email = "*****@*****.**"; // Location // Region ad.Location.Region = new Region { Id = Int32.Parse(node.SelectSingleNode("//*[@id='region']").GetAttributeValue("value", "0")) }; // City ad.Location.City = new City { Id = Int32.Parse(node.SelectSingleNode("//*[@name='location_id']").GetAttributeValue("value", "0")) }; // Metro tmp = node.SelectSingleNode("//*[@name='metro_id']//*[@selected]"); if (tmp != null) { ad.Location.Metro = new Metro { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) } } ; // Road tmp = node.SelectSingleNode("//*[@name='road_id']//*[@selected]"); if (tmp != null) { ad.Location.Road = new Road { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) } } ; // District tmp = node.SelectSingleNode("//*[@name='district_id']//*[@selected]"); if (tmp != null) { ad.Location.District = new District { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) } } ; // End Location // Category ad.CategoryId = Int32.Parse(node.SelectSingleNode("//*[@name='category_id']").GetAttributeValue("value", "")); // Parameters HtmlNodeCollection par = node.SelectNodes("//*[contains(@name,'params')]"); foreach (HtmlNode x in par) { string id = x.GetAttributeValue("name", "").Substring(7); id = id.Substring(0, id.IndexOf(']')); int value = Int32.Parse(x.SelectSingleNode(".//*[@selected]").GetAttributeValue("value", "")); ad.Parameters.Add(Int32.Parse(id), value); } // Geo tmp = node.SelectSingleNode("//*[@name='coords[lat]']"); if (tmp != null) { ad.Coordinates = new GeoCoords { Latitude = tmp.GetAttributeValue("value", ""), Longitude = node.SelectSingleNode("//*[@name='coords[lng]']").GetAttributeValue("value", ""), Zoom = node.SelectSingleNode("//*[@name='coords[zoom]']").GetAttributeValue("value", "") }; } // Price ad.Price = Int32.Parse(node.SelectSingleNode("//*[@name='price']").GetAttributeValue("value", "")); // Images par = node.SelectSingleNode("//*[@name='images[]']").ParentNode.SelectNodes(".//img"); foreach (HtmlNode x in par) { string[] arr = x.GetAttributeValue("src", "").Split('/'); arr[3] = "640x480"; byte[] data; try { data = web.DownloadData(String.Join("/", arr)); } catch (Exception e) { return(null); } MemoryStream ms = new MemoryStream(); ms.Write(data, 0, data.Length); Image im = Image.FromStream(ms); ad.Images.Add(im); } // End return(ad); }
public List<Advertisement> GetClosed() { List<Advertisement> list = new List<Advertisement>(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(web.DownloadString(oldItemsUrl)); HtmlNodeCollection all = doc.DocumentNode.SelectNodes("//div[contains(@class,'item')]"); if (all != null) { foreach (HtmlNode node in all) { Advertisement ad = new Advertisement(); ad.Id = Int32.Parse(node.SelectSingleNode(".//input").GetAttributeValue("value", "0")); ad.Url = baseUrlSecure + node.SelectSingleNode(".//a[starts-with(@name,'item_')]").GetAttributeValue("href", ""); ad.Title = node.SelectSingleNode(".//a[starts-with(@name,'item_')]").InnerText; ad = Get(ad.Url); list.Add(ad); } } return list; }