doordesk-js/dennis/src/dennis.py

133 lines
3.3 KiB
Python
Raw Normal View History

2023-04-11 00:36:07 -04:00
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
2023-06-16 22:46:29 -04:00
from datetime import date
2023-04-11 00:36:07 -04:00
api = FastAPI()
api.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
2023-06-17 00:21:50 -04:00
allow_methods=["GET"],
allow_headers=[],
2023-04-11 00:36:07 -04:00
)
2023-06-16 22:46:29 -04:00
class Article(BaseModel):
content_type: str
title: str
date: date
content: str
def get_html(content):
with open('./static/'+content) as file:
return file.read();
fake_db = [
Article(
2023-06-17 04:15:28 -04:00
content_type='project',
title='''Cartman is public!''',
date=date(2022, 10, 20),
content=get_html('projects/20221020-cartman.html'),
2023-06-16 22:46:29 -04:00
),
Article(
2023-06-17 04:15:28 -04:00
content_type='game',
title='''fps''',
date=date(2022, 10, 9),
content=get_html('games/fps.html'),
),
Article(
content_type='game',
title='''balls''',
date=date(2022, 9, 13),
content=get_html('games/balls.html'),
2023-06-16 22:46:29 -04:00
),
2023-04-11 00:36:07 -04:00
Article(
2023-06-16 22:46:29 -04:00
content_type='game',
title='''adam''', # this stuff will change
2023-06-17 04:15:28 -04:00
date=date(2022, 9, 11),
2023-06-16 22:46:29 -04:00
content=get_html('games/adam.html'),
2023-06-17 04:15:28 -04:00
),
2023-06-16 22:46:29 -04:00
Article(
content_type='blog',
2023-04-11 00:36:07 -04:00
title='''It's a post about nothing!''',
2023-06-16 22:46:29 -04:00
date=date(2022, 7, 1),
content=get_html('blog/20220701-progress.html'),
),
Article(
content_type='project',
title='''What Goes Into a Successful Reddit Post?''',
2023-06-17 04:15:28 -04:00
date=date(2022, 6, 16),
2023-06-16 22:46:29 -04:00
content=get_html('projects/20220614-reddit.html'),
),
2023-04-11 00:36:07 -04:00
Article(
2023-06-16 22:46:29 -04:00
content_type='blog',
2023-04-11 00:36:07 -04:00
title='''Back to School''',
2023-06-16 22:46:29 -04:00
date=date(2022, 6, 2),
content=get_html('blog/20220602-back.html'),
2023-04-11 00:36:07 -04:00
),
2023-06-16 22:46:29 -04:00
2023-04-11 00:36:07 -04:00
Article(
2023-06-17 04:15:28 -04:00
content_type='game',
title='''snek''',
date=date(2022, 5, 29),
content=get_html('games/snek.html'),
),
2023-06-16 22:46:29 -04:00
2023-04-11 00:36:07 -04:00
Article(
2023-06-16 22:46:29 -04:00
content_type='project',
title='''Predicting Housing Prices''',
date=date(2022, 5, 29),
content=get_html('projects/20220529-housing.html'),
2023-06-17 04:15:28 -04:00
),
2023-04-11 00:36:07 -04:00
Article(
2023-06-17 04:15:28 -04:00
content_type='blog',
title='''It's about time, NVIDIA''',
date=date(2022, 5, 20),
content=get_html('blog/20220520-nvidia.html'),
2023-04-11 00:36:07 -04:00
),
2023-06-16 22:46:29 -04:00
2023-04-11 00:36:07 -04:00
Article(
2023-06-16 22:46:29 -04:00
content_type='blog',
title='''Change''',
date=date(2022, 5, 6),
content=get_html('blog/20220506-change.html'),
2023-04-11 00:36:07 -04:00
),
2023-06-16 22:46:29 -04:00
2023-04-11 00:36:07 -04:00
Article(
2023-06-16 22:46:29 -04:00
content_type='blog',
title='''Hume''',
2023-06-17 04:15:28 -04:00
date=date(2022, 2, 7),
2023-06-16 22:46:29 -04:00
content=get_html('blog/000000000-swim.html'),
2023-04-11 00:36:07 -04:00
),
2023-06-16 22:46:29 -04:00
];
@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():
2023-06-17 04:15:28 -04:00
return [entry for entry in fake_db if entry.content_type == 'project' or entry.content_type == 'game']
2023-06-16 22:46:29 -04:00
@api.get('/dennis/bots')
async def serve_bots():
return [entry for entry in fake_db if entry.content_type == 'chatbot']