def presidencia_discursos(): """ ?limitstart=5 Limita de 5 en 5 los discursos servira para que en el json se vayan recuperando en base a esa cantidad. """ url = 'http://www.presidencia.gob.pe/discursos-del-presidente/blog' root = parse(url).getroot() news = [] discursos = root.xpath("//div[@class='entryContent entry']") for discurso in discursos: descripcion = join([ '<p>' + p.text_content() + '</p>' for p in discurso.xpath("div[@class='entry-body']")[0].xpath( "p[@style='text-align: justify;']") ], '') news.append( dict( titular=discurso.xpath("h2")[0].text_content(), link=u'%s%s' % ('http://presidencia.gob.pe/', slugify(discurso.xpath("h2")[0].text_content())), descripcion=descripcion, )) return news
def presidencia_noticias(): """ ?limitstart=5 Limita de 5 en 5 los discursos servira para que en el json se vayan recuperando en base a esa cantidad. """ url = 'http://www.presidencia.gob.pe/ollanta/blog' root = parse(url).getroot() news = [] discursos = root.xpath("//div[@class='entryContent entry']") for discurso in discursos: #print discurso.xpath( # "div[@class='entry-body']")[0].xpath( # "p[@style='text-align: justify;']//em/img") descripcion = join(['<p>'+p.text_content()+'</p>' for p in discurso.xpath( "div[@class='entry-body']")[0].xpath( "p[@style='text-align: justify;']")],'') news.append(dict( titular = discurso.xpath("h2")[0].text_content(), link = u'%s%s' % ('http://presidencia.gob.pe/', slugify(discurso.xpath("h2")[0].text_content())), descripcion = descripcion, )) return news
def test_join(self): self.assertEqual(join([0, 1, 2], 'glue'), '0glue1glue2')
def test_autoescape_off(self): self.assertEqual( join(['<a>', '<img>', '</a>'], '<br>', autoescape=False), '<a><br><img><br></a>', )
def test_autoescape(self): self.assertEqual( join(['<a>', '<img>', '</a>'], '<br>'), '<a><br><img><br></a>', )
def test_noniterable_arg_autoescape_off(self): obj = object() self.assertEqual(join(obj, '<br>', autoescape=False), obj)
def test_noniterable_arg(self): obj = object() self.assertEqual(join(obj, '<br>'), obj)
}, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/3.1/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.1/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = '' STATICFILES_DIRS = (join(BASE_DIR, 'static'), )
def test_autoescape_off(self): self.assertEqual( join(["<a>", "<img>", "</a>"], "<br>", autoescape=False), "<a><br><img><br></a>", )
def test_autoescape(self): self.assertEqual( join(["<a>", "<img>", "</a>"], "<br>"), "<a><br><img><br></a>", )
def test_list(self): self.assertEqual(join([0, 1, 2], "glue"), "0glue1glue2")