Example #1
0
        public NoticiaKnewin CapturaNoticia(int idKnewin)
        {
            string Key = "2e9ee79e-7a4f-4f2f-bca3-25402e113997";

            //try
            //{
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://data.knewin.com/news");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = "";

                json = "{" +
                       "\"key\":\"" + Key + "\"," +
                       "\"newsId\": [" + idKnewin + "]}";

                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var response       = (HttpWebResponse)httpWebRequest.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            var resposta       = JsonConvert.DeserializeObject <RootObject>(responseString);
            var n = resposta.hits[0];

            DateTime dtTest;

            NoticiaKnewin noticia = new NoticiaKnewin()
            {
                idfonte           = n.source_id,
                autor             = n.author,
                conteudo          = n.content,
                datacapturaknewin = DateTime.Parse(n.crawled_date),
                datapublicacao    = DateTime.TryParse(n.published_date, out dtTest) ? DateTime.Parse(n.published_date) : DateTime.Parse(n.crawled_date),
                idnoticia_knewin  = n.id,
                nomefonte         = n.source,
                titulo            = n.title,
                subtitulo         = n.subtitle,
                linguagem         = n.lang,
                url       = n.url,
                categoria = n.category,
            };

            noticia.imagens = new List <NoticiaImagem>();
            if (n.image_hits != null)
            {
                foreach (var img in n.image_hits)
                {
                    NoticiaImagem imagem = new NoticiaImagem()
                    {
                        url      = img.url,
                        titulo   = img.caption,
                        creditos = img.credit
                    };
                    noticia.imagens.Add(imagem);
                }
            }
            return(noticia);

            //}
            //catch (Exception ex)
            //{
            //    return null;
            //}
        }
Example #2
0
        public ZAdmin_RN.NoticiasElastic.Noticia ConverteKnewinElastic(int idnoticia, NoticiaKnewin noticiaK)
        {
            ZAdmin_RN.NoticiasElastic.Noticia noticiaE = new NoticiasElastic.Noticia()
            {
                idnoticia          = idnoticia,
                idnoticiaknewin    = noticiaK.idnoticia_knewin,
                idfonte            = noticiaK.idfonte,
                nomefonte          = noticiaK.nomefonte,
                titulo             = noticiaK.titulo,
                subtitulo          = noticiaK.subtitulo,
                dominio            = noticiaK.dominio,
                autor              = noticiaK.autor,
                conteudo           = noticiaK.conteudo,
                url                = noticiaK.url,
                localidade         = noticiaK.localidade,
                linguagem          = noticiaK.linguagem,
                datapublicacao     = noticiaK.datapublicacao.ToString("dd/MM/yyyy HH:mm:ss"),
                datacaptura_knewin = noticiaK.datacapturaknewin.ToString("dd/MM/yyyy HH:mm:ss"),
                datacaptura_zeeng  = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"),
            };

            noticiaE.imagens = new List <ZAdmin_RN.NoticiasElastic.NoticiaImagem>();

            foreach (var img in noticiaK.imagens)
            {
                var imag = new ZAdmin_RN.NoticiasElastic.NoticiaImagem()
                {
                    url      = img.url,
                    titulo   = img.titulo,
                    creditos = img.creditos
                };
                noticiaE.imagens.Add(imag);
            }

            return(noticiaE);
        }