public string dangTin(ReqTinDang reqTinDang) { var indexaccount = DataMasterHelper.getAccounts().IndexOf(reqTinDang.Data.TenDangNhap.ToLower()); if (indexaccount < 0) { if (!Variables.SELENIUM_ALLOW_ANY_ACCOUNT) { string er = $"Tài khoản {reqTinDang.Data.TenDangNhap} không thể đăng tin do không nằm trong danh sách tài khoản cho phép"; CommonMethods.notifycation_tele(er); throw new Exception(er); } else { CommonMethods.notifycation_tele($"Tài khoản {reqTinDang.Data.TenDangNhap} không nằm trong danh sách cho phép đang thực hiện đăng tin"); } } var error = "Không tìm thấy nguồn phù hợp"; if (reqTinDang.Sources.ToString().IndexOf(Variables.NguonTinDang.BatDongSan.ToString()) >= 0) { error = null; return(new ProcessDangTin_BDS().dangTin(reqTinDang.Data)); } if (!String.IsNullOrEmpty(error)) { throw new Exception(error); } return(""); }
public IActionResult Settings([FromBody] JObject value) { CustomResult cusRes = new CustomResult(); try { List <string> accounts = value.GetValue("accounts")?.Values <string> ()?.ToList <String> (); string str_allow_any = value.GetValue("allow_any")?.ToString(); if (accounts == null && str_allow_any == null) { cusRes.SetException(new Exception($"Bạn chưa nhập thông tin: List<string> accounts || bool allow_any")); } else { var acc = DataMasterHelper.getAccounts(); DataMasterHelper.setAccounts(accounts ?? acc); Variables.SELENIUM_ALLOW_ANY_ACCOUNT = str_allow_any != null?bool.Parse(str_allow_any) : Variables.SELENIUM_ALLOW_ANY_ACCOUNT; cusRes.IntResult = 1; } } catch (System.Exception ex) { cusRes.SetException(ex.InnerException.ToString()); } return(Ok(cusRes)); }
public JObject checkLinks(List <String> links, int top) { List <string> listLinkChecked = DataMasterHelper.getLinkChecked(); List <string> listAccounts = DataMasterHelper.getAccounts(); if (listLinkChecked == null) { listLinkChecked = new List <string> (); } JObject ob = new JObject(); String mess = String.Empty; mess += $"DANH SÁCH TIN MỚI - TOP {top}%0A"; JObject obRes = new JObject(); try { foreach (var link in links) { try { driver.Navigate().GoToUrl(link); Thread.Sleep(300); var ewrapplinks = driver.FindElements(By.ClassName("wrap-plink")); List <String> wrapplinks = ewrapplinks.Select(item => item.GetAttribute("href")).ToList(); String tenNguoiDang = String.Empty; String tenDangNhap = String.Empty; String gia = String.Empty; String dienTich = String.Empty; String email = string.Empty; String phone = string.Empty; int index = 1; var obWrappLink = new JObject(); JObject obItemRes = new JObject(); top = top <= wrapplinks.Count ? top : wrapplinks.Count; for (int i = 0; i < top; i++) { var wrapplink = wrapplinks[i]; var isExist = listLinkChecked.IndexOf(wrapplink) >= 0; if (!isExist) { try { driver.Navigate().GoToUrl(wrapplink); var user = driver.FindElements(By.XPath("//div[@class = 'user']/div")); foreach (var elDiv in user) { var cl = elDiv.GetAttribute("class"); switch (cl) { case "mail": string pattern = "mailto:(.+)\\?subject(.+)"; email = Regex.Replace(CommonMethods.FindElement(elDiv, By.TagName("a"))?.GetAttribute("href"), pattern, "$1")?.ToLower(); break; case "phone text-center": phone = CommonMethods.FindElement(elDiv, By.TagName("span"))?.GetAttribute("raw"); break; case "name": tenNguoiDang = elDiv.GetAttribute("title"); break; } } var detail = driver.FindElement(By.ClassName("short-detail-wrap")); var detailLi = detail.FindElements(By.TagName("li")); if (detailLi != null && detailLi.Count >= 2) { var elGia = CommonMethods.FindElement(detailLi[0], By.ClassName("sp2")); gia = elGia == null ? string.Empty : elGia.Text; var elDienTich = CommonMethods.FindElement(detailLi[1], By.ClassName("sp2")); dienTich = elDienTich == null ? string.Empty : elDienTich.Text; } tenDangNhap = string.IsNullOrEmpty(email) ? phone : email; int indexEmail = listAccounts.IndexOf(tenDangNhap); if (string.IsNullOrEmpty(tenDangNhap) || indexEmail < 0) { obWrappLink[wrapplink] = $"{index++}. {tenNguoiDang} - {gia} - {dienTich} - {phone} "; dynamic jsonObject = new JObject(); jsonObject.TenNguoiDang = tenNguoiDang; jsonObject.Gia = gia; jsonObject.DienTich = dienTich; jsonObject.DienThoai = phone; obItemRes[wrapplink] = jsonObject; listLinkChecked.Add(wrapplink); } } catch (Exception ex) { obWrappLink[wrapplink] = $"+ Chưa xác định: {wrapplink}"; } } } if (obWrappLink.HasValues) { ob[link] = $"Có {obWrappLink.Keys().Count} tin đăng mới.%0A" + string.Join("%0A", obWrappLink.Values().ToList()); obRes[link] = obItemRes; } } catch (Exception ex) { ob[link] = ex.InnerException.ToString(); } } if (ob.HasValues) { DataMasterHelper.setLinkChecked(listLinkChecked); foreach (var item in ob) { mess += $"{item.Key}: {item.Value}%0A"; } List <string> lMessage = CommonMethods.Split(mess, 4000); foreach (var m in lMessage) { CommonMethods.notifycation_tele(m); } } } catch (System.Exception ex) { mess += ex.InnerException.ToString(); LogSystem.Write($"checkLinks: {mess}"); CommonMethods.notifycation_tele(mess); } driver.Quit(); return(obRes); }