public List<ClHtml.resultadoClima> ClimaSvc() { Metodos mt = new Metodos(); List<ClHtml.resultadoClima> cl = new List<ClHtml.resultadoClima>(); XDocument xml = XDocument.Parse(mt.getPage("http://www.climatempo.com.br/rss/capitais.xml")); XmlTempo xt = (from n1 in xml.Descendants("channel").Elements("item") where n1.Element("title").Value == "saopaulo/sp - Previsão do Tempo" select new XmlTempo { title = n1.Element("title").Value, description = n1.Element("description").Value }).First(); cl = mt.preencherClima(xt); string[] HtmlResp; List<ClHtml.ResultadoHtml> RespList = new List<ClHtml.ResultadoHtml>(); string url = "http://www.climatempo.com.br/previsao-do-tempo/cidade/558/saopaulo-sp"; HtmlResp = mt.getPage(url).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); foreach (string s in HtmlResp) { RespList.Add(new ClHtml.ResultadoHtml() { resultado = s }); } Regex filtro = new Regex("((googletag.pubads)(.*?)(setTargeting))|(<span class=\"dados-momento-li-span-first-child\">Umidade:)|(Intensidade do Vento:)"); RespList = RespList.Where(a => filtro.IsMatch(a.resultado)).ToList(); Regex filtroTipo; string replaceTipo; replaceTipo = @"((.*?)("",""))|(""\);)"; filtroTipo = new Regex("(.*?)(tmomento)(.*?)"); cl[0].tmomento = Convert.ToInt32(mt.adicionarTransito(filtroTipo, replaceTipo, RespList)); filtroTipo = new Regex("(.*?)(cmomento)(.*?)"); cl[0].status = mt.adicionarTransito(filtroTipo, replaceTipo, RespList); filtroTipo = new Regex("(.*?)(regiao)(.*?)"); cl[0].vento = mt.adicionarTransito(filtroTipo, replaceTipo, RespList); filtroTipo = new Regex("(.*?)(Umidade:)(.*?)"); replaceTipo = @"((.*?)(<li)(.*?)(<span>))|(%</span></li>)"; cl[0].umidade = Convert.ToInt32(mt.adicionarTransito(filtroTipo, replaceTipo, RespList)); filtroTipo = new Regex("(.*?)(Intensidade do Vento:)(.*?)"); replaceTipo = @"((.*?)(<li)(.*?)(<span>))|(</span></li>)"; cl[0].velocidadevento = mt.adicionarTransito(filtroTipo, replaceTipo, RespList); return cl; }
public string ArSvc() { string ar = ""; try { Metodos mt = new Metodos(); List<ClHtml.ResultadoHtml> RespList = new List<ClHtml.ResultadoHtml>(); string url = "http://sistemasinter.cetesb.sp.gov.br/Ar/php/ar_resumo_hora.php"; string[] HtmlResp = mt.getPage(url).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); foreach (string s in HtmlResp) { RespList.Add(new ClHtml.ResultadoHtml() { resultado = s }); } Regex filtro = new Regex("(.*?)(Parque D.Pedro II)(.*?)"); RespList = RespList.Where(a => filtro.IsMatch(a.resultado)).ToList(); string filtroAr = "((.*?)(Parque D.Pedro II)(.*?)(quadro))|(.gif)(.*?)(</tr></table></td>)"; int vl = Convert.ToInt32(Regex.Replace(RespList[0].resultado, filtroAr, "")); switch (vl) { case 1: ar = "Boa"; break; case 2: ar = "Moderada"; break; case 3: ar = "Ruim"; break; case 4: ar = "Muito Ruim"; break; case 5: ar = "Péssima"; break; } } catch { ar = ""; } return ar; }
public List<ClHtml.ResultadoHtml> filtroHtmlISO(string reg, string url) { string[] HtmlResp; List<ClHtml.ResultadoHtml> RespList = new List<ClHtml.ResultadoHtml>(); Metodos mt = new Metodos(); HtmlResp = mt.getPageISO(url).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); foreach (string s in HtmlResp) { RespList.Add(new ClHtml.ResultadoHtml() { resultado = s }); } Regex filtro = new Regex(reg); return RespList = RespList.Where(a => filtro.IsMatch(a.resultado)).ToList(); }
public ClHtml.resultadoTransito TransitoSvc() { Metodos mt = new Metodos(); string filtro = "(<div id=\")((CentroLentidao)|(LesteLentidao)|(NorteLentidao)|(OesteLentidao)|(SulLentidao))(\")(.*?)(</div>)"; string url = "http://cetsp1.cetsp.com.br/monitransmapa/agora/"; List<ClHtml.ResultadoHtml> RespList = mt.filtroHtml(filtro, url); ClHtml.resultadoTransito Transito = new ClHtml.resultadoTransito(); Regex filtroTipo; string replaceTipo; filtroTipo = new Regex("(.*?)(NorteLentidao)(.*?)"); replaceTipo = @"((.*?)(<div id)(.*?)(>))|( km)(.*?)(</div>)"; Transito.norte = mt.adicionarTransito(filtroTipo,replaceTipo,RespList); filtroTipo = new Regex("(.*?)(LesteLentidao)(.*?)"); Transito.leste = mt.adicionarTransito(filtroTipo, replaceTipo, RespList); filtroTipo = new Regex("(.*?)(CentroLentidao)(.*?)"); Transito.centro = mt.adicionarTransito(filtroTipo, replaceTipo, RespList); filtroTipo = new Regex("(.*?)(OesteLentidao)(.*?)"); Transito.oeste = mt.adicionarTransito(filtroTipo, replaceTipo, RespList); filtroTipo = new Regex("(.*?)(SulLentidao)(.*?)"); Transito.sul = mt.adicionarTransito(filtroTipo, replaceTipo, RespList); int total = 0; total += Convert.ToInt32(Transito.norte); total += Convert.ToInt32(Transito.sul); total += Convert.ToInt32(Transito.leste); total += Convert.ToInt32(Transito.oeste); total += Convert.ToInt32(Transito.centro); Transito.total = total.ToString(); return Transito; }
public List<ClHtml.resultadoTransporte> SptransSvc() { List<ClHtml.resultadoTransporte> rst = new List<ClHtml.resultadoTransporte>(); Metodos mt = new Metodos(); string filtro = "(<li><a href=\"noticias)(.*?)(</strong>)"; string url = "http://www.sptrans.com.br/"; List<ClHtml.ResultadoHtml> RespList = mt.filtroHtmlISO(filtro, url); foreach (ClHtml.ResultadoHtml item in RespList) { rst.Add(new ClHtml.resultadoTransporte() { ocorrencia = Regex.Replace(item.resultado, "(^(.*?)(ng> - ))|((</a>)(.*?)$)", "") }); } return rst; }