missed a file

This commit is contained in:
Adam 2023-06-16 22:46:29 -04:00
parent e838bd368b
commit fb7a44bbe9

View file

@ -1,19 +1,10 @@
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel from pydantic import BaseModel
from datetime import date
class Article(BaseModel):
content_type: str
title: str
date: str # use datetime
url: str
api = FastAPI() api = FastAPI()
api.add_middleware( api.add_middleware(
CORSMiddleware, CORSMiddleware,
allow_origins=['*'], allow_origins=['*'],
@ -22,62 +13,132 @@ api.add_middleware(
allow_headers=["*"], allow_headers=["*"],
) )
class Article(BaseModel):
content_type: str
title: str
date: date
content: str
@api.get('/dennis/blog') def get_html(content):
async def make_a_database(): with open('./static/'+content) as file:
return [ return file.read();
Article(
content_type='article',
title='''It's a post about nothing!''',
date='Jul 01, 2022',
url='blog/20220701-progress.html',
),
Article(
content_type='article',
title='''Back to School''',
date='Jun 02, 2022',
url='blog/20220602-back.html',
),
Article(
content_type='article',
title='''It's about time, NVIDIA''',
date='May 20, 2022',
url='blog/20220520-nvidia.html',
),
Article(
content_type='article',
title='''Change''',
date='May 06, 2022',
url='blog/20220506-change.html',
),
Article(
content_type='article',
title='''''',
date='',
url='blog/00000000-swim.html',
),
]
fake_db = [
@api.get('/dennis/projects')
async def make_a_daatabase():
return [
Article( Article(
content_type='chatbot', content_type='chatbot',
title='''cartman''', # this stuff will change
date=date(2023, 2, 17),
content=get_html('bots/cartman.html'),
),
Article(
content_type='project',
title='''Cartman''', # this stuff will change title='''Cartman''', # this stuff will change
date='Feb 17, 2023', date=date(2023, 2, 17),
url='projects/20230217-cartman.html', content=get_html('projects/20230217-cartman.html'),
), ),
Article( Article(
content_type='article', content_type='game',
title='''adam''', # this stuff will change
date=date(2023, 2, 17),
content=get_html('games/adam.html'),
),
Article(
content_type='blog',
title='''It's a post about nothing!''',
date=date(2022, 7, 1),
content=get_html('blog/20220701-progress.html'),
),
Article(
content_type='project',
title='''What Goes Into a Successful Reddit Post?''', title='''What Goes Into a Successful Reddit Post?''',
date='Jun 14, 2022', date=date(2022, 6, 14),
url='projects/20220614-reddit.html', content=get_html('projects/20220614-reddit.html'),
), ),
Article( Article(
content_type='article', content_type='game',
title='''Predicting Housing Prices''', title='''fps''',
date='May 29, 2022', date=date(2022, 6, 14),
url='projects/20220529-housing.html', content=get_html('games/fps.html'),
), ),
]
Article(
content_type='blog',
title='''Back to School''',
date=date(2022, 6, 2),
content=get_html('blog/20220602-back.html'),
),
Article(
content_type='blog',
title='''It's about time, NVIDIA''',
date=date(2022, 5, 20),
content=get_html('blog/20220520-nvidia.html'),
),
Article(
content_type='project',
title='''Predicting Housing Prices''',
date=date(2022, 5, 29),
content=get_html('projects/20220529-housing.html'),
),
Article(
content_type='game',
title='''snek''',
date=date(2022, 5, 29),
content=get_html('games/snek.html'),
),
Article(
content_type='game',
title='''balls''',
date=date(2022, 5, 29),
content=get_html('games/balls.html'),
),
Article(
content_type='blog',
title='''Change''',
date=date(2022, 5, 6),
content=get_html('blog/20220506-change.html'),
),
Article(
content_type='blog',
title='''Hume''',
date=date(2020, 6, 23),
content=get_html('blog/000000000-swim.html'),
),
];
@api.get('/dennis/home')
async def serve_home():
return fake_db
@api.get('/dennis/blog')
async def serve_blog():
return [entry for entry in fake_db if entry.content_type == 'blog']
@api.get('/dennis/projects')
async def serve_projects():
return [entry for entry in fake_db if entry.content_type == 'project']
@api.get('/dennis/games')
async def serve_games():
return [entry for entry in fake_db if entry.content_type == 'game']
@api.get('/dennis/bots')
async def serve_bots():
return [entry for entry in fake_db if entry.content_type == 'chatbot']