Spaces:
Sleeping
Sleeping
class Post(object): | |
id:str | |
fecha:str | |
titulo:str | |
contenido:str | |
categorias:list[str] | |
def __init__(self, id:str): | |
self.__id = id | |
self.fecha = str() | |
self.titulo = str() | |
self.contenido = str() | |
self.categorias = ["Nuevos"] | |
def id(self): | |
return self.__id | |
def to_json(self): | |
_json = {"id": self.id, | |
"fecha": self.fecha, | |
"titulo": self.titulo, | |
"contenido": self.contenido, | |
"categorias": self.categorias} | |
return _json | |
class Base_Blog_Data(object): | |
nombre:str | |
descripcion:str | |
url:str | |
posts:list[Post] | |
categorias:list[str] | |
def __init__(self, id:str): | |
self.__id = id | |
self.nombre = str() | |
self.descripcion = str() | |
self.url = str() | |
self.posts = [] | |
self.categorias = ["Nuevos"] | |
def id(self): | |
return self.__id | |
def filtrar_por_categorias(posts:list[Post], categorias:list[str]): | |
posts_filtrados = [] | |
for post in posts: | |
for cat in categorias: | |
if cat in post.categorias and post not in posts_filtrados: | |
posts_filtrados.append(post) | |
return posts_filtrados | |
def filtrar_por_categoria(posts:list[Post], categoria:str): | |
posts_filtrados = [] | |
for post in posts: | |
if categoria in post.categorias: | |
posts_filtrados.append(post) | |
return posts_filtrados | |
def filtrar_por_fecha(posts:list[Post], fecha_inicio:str, fecha_fin:str): | |
posts_filtrados = [] | |
for post in posts: | |
if fecha_inicio <= post.fecha <= fecha_fin: | |
posts_filtrados.append(post) | |
return posts_filtrados | |
def filtrar_por_titulo(posts:list[Post], titulo:str): | |
posts_filtrados = [] | |
for post in posts: | |
if titulo in post.titulo: | |
posts_filtrados.append(post) | |
return posts_filtrados | |
def filtrar_por_contenido(posts:list[Post], contenido:str): | |
posts_filtrados = [] | |
for post in posts: | |
if contenido in post.contenido: | |
posts_filtrados.append(post) | |
return posts_filtrados | |
def to_json(self): | |
_json = {"id": self.id, | |
"nombre": self.nombre, | |
"descripcion": self.descripcion, | |
"url": self.url, | |
"posts": [post.to_json() for post in self.posts], | |
"categorias": self.categorias} | |
return _json | |