From 3126e748591deb201571d2e06adca505435c7404 Mon Sep 17 00:00:00 2001 From: Vicki Date: Wed, 26 Oct 2022 23:02:34 -0400 Subject: [PATCH 1/4] Adding more links and slight reorg --- .DS_Store | Bin 6148 -> 6148 bytes Dockerfile | 12 ++- README.md | 18 ++-- app/.DS_Store | Bin 6148 -> 6148 bytes app/__init__.py | 4 +- app/goodies/links.txt | 4 + app/goodies/{ => media}/normconf_ascii.txt | 0 app/goodies/{ => media}/normconf_logo.png | Bin app/goodies/{ => media}/zen_of_normcore.txt | 4 +- app/goodies/rickroll.txt | 1 - app/normconf.py | 91 ++++++++++---------- pyproject.toml | 12 +-- 12 files changed, 74 insertions(+), 72 deletions(-) create mode 100644 app/goodies/links.txt rename app/goodies/{ => media}/normconf_ascii.txt (100%) rename app/goodies/{ => media}/normconf_logo.png (100%) rename app/goodies/{ => media}/zen_of_normcore.txt (81%) delete mode 100644 app/goodies/rickroll.txt diff --git a/.DS_Store b/.DS_Store index e7a827c3244ac155ad496dd9410e3f693807141c..4e02974e4b2d705ecbc4d13c0a1a53282f6f0675 100644 GIT binary patch delta 68 zcmZoMXfc=|#>B)qF;Q%yo+6{b#(>?7i~^f^Seh9(^RxY6+*r`Sw3(fQp9837vmnQJ W=E?jbjvNd?z{tSBvN=Lz4Kn~>1rQ7X delta 196 zcmZoMXfc=|#>B!kF;Q%yo+6{j#(>?7iv?Ji7)3VoFf}vQvoh#0lrf|-;*yk;p9B=;U|?vFJXU+e5nV+J0Tl%q2pd$cf-KtH$NZCV iGdl-A2hfe18CkwFPv#eKp6F!wdkbB`mu~2NHo}wrV0|Nsi1A_nqLncEiLvc>JVQ_N(#KPr_ER**zP2T*K nS%_s5OBmB;b`E|HpsvjynZGkn<`=Q#0O|v2WZE1cvV|D{eaIA4 literal 6148 zcmeHKu};G<5IvVlw3MMEW7t?bv4$$_Nd169lBz`{BoZ(%Ao<%6EPMkCdL}MZvpfL7^s9J*m=hBFt&m01c>m#Ep%4kIknm5>* z_=^tk*o`n+bE@ePWA{CN^I|!fWmQ>=?BmaFW?3akT2v_*{Ghx&KfRpoV&^|#*Q-qx z7wDGuX-O4+IbGvPy9;#|?@dOi&z`)BzO8=BYExGiE7W6I&ya4R<{ny7r|V{0)4^#w zE7V0F-nW+iLT$U4p+0`EHPiuhKpki}fH|9EFcQ>S9Z(0;jcFo$@CBeebPE6g diff --git a/app/__init__.py b/app/__init__.py index 0d1284d..14aaeaa 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -33,5 +33,5 @@ def configure_logger() -> Logger: return structlog.get_logger() -goodies_path = 'app/goodies/' -surprises = [goodies_path + file for file in listdir(Path(goodies_path))] \ No newline at end of file +goodies_path = "app/goodies/media/" +surprises = [goodies_path + file for file in listdir(Path(goodies_path))] diff --git a/app/goodies/links.txt b/app/goodies/links.txt new file mode 100644 index 0000000..6cbfb7f --- /dev/null +++ b/app/goodies/links.txt @@ -0,0 +1,4 @@ +https://www.youtube.com/watch?v=eBGIQ7ZuuiU +https://www.destroyallsoftware.com/talks/wat +https://www.ftrain.com/wwic +https://e2eml.school/interviewing_2022.html diff --git a/app/goodies/normconf_ascii.txt b/app/goodies/media/normconf_ascii.txt similarity index 100% rename from app/goodies/normconf_ascii.txt rename to app/goodies/media/normconf_ascii.txt diff --git a/app/goodies/normconf_logo.png b/app/goodies/media/normconf_logo.png similarity index 100% rename from app/goodies/normconf_logo.png rename to app/goodies/media/normconf_logo.png diff --git a/app/goodies/zen_of_normcore.txt b/app/goodies/media/zen_of_normcore.txt similarity index 81% rename from app/goodies/zen_of_normcore.txt rename to app/goodies/media/zen_of_normcore.txt index 89c95a8..6cd8712 100644 --- a/app/goodies/zen_of_normcore.txt +++ b/app/goodies/media/zen_of_normcore.txt @@ -1,12 +1,12 @@ the zen of normcore sometimes it’s hardcore science, but deep down in our heart, -we know that a for loop in a python file, +we know that a for loop in a Python file, can outperform the state of the art all programs live in a system forgetting this will make somebody sad. this algorithm has the best metrics, -so why is everone getting the same ad? +so why is everyone getting the same ad? try to think about your tools, try to limit your needs, try not not to be the optimal model, diff --git a/app/goodies/rickroll.txt b/app/goodies/rickroll.txt deleted file mode 100644 index 116b3b6..0000000 --- a/app/goodies/rickroll.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.youtube.com/watch?v=eBGIQ7ZuuiU \ No newline at end of file diff --git a/app/normconf.py b/app/normconf.py index 225aaa8..17f42aa 100644 --- a/app/normconf.py +++ b/app/normconf.py @@ -6,7 +6,7 @@ import structlog from fastapi import APIRouter -from fastapi.responses import FileResponse, StreamingResponse +from fastapi.responses import FileResponse, StreamingResponse, PlainTextResponse, Response from pandas import read_html from requests import post @@ -19,10 +19,11 @@ normie_router = APIRouter(responses={404: {"description": "Auth router not found"}}) -goodies_path = 'app/goodies/' +goodies_path = "app/goodies/" -@normie_router.get('/schedule') -def get_schedule(as_markdown:bool=True, as_csv:bool=False, as_excel:bool=False): + +@normie_router.get("/schedule") +def get_schedule(as_markdown: bool = True, as_csv: bool = False, as_excel: bool = False): """Return NormConf Schedule\n Args:\n @@ -33,7 +34,7 @@ def get_schedule(as_markdown:bool=True, as_csv:bool=False, as_excel:bool=False): Returns:\n DataFrame: Returns schedule as Pandas DataFrame """ - schedule = read_html('https://normconf.com/', header=0)[0] + schedule = read_html("https://normconf.com/", header=0)[0] if sum([as_markdown, as_csv, as_excel]) != 1: raise ValueError("Only one file return type expected, but got multiple or none!") @@ -41,70 +42,68 @@ def get_schedule(as_markdown:bool=True, as_csv:bool=False, as_excel:bool=False): if as_csv: return schedule.to_csv() - elif as_excel: - return schedule.to_excel("ye_olde_nc_schedule.xlsx", sheet_name='Ye Olde NormConf Schedule') + elif as_excel: + return schedule.to_excel( + "ye_olde_nc_schedule.xlsx", sheet_name="Ye Olde NormConf Schedule" + ) elif as_markdown: return schedule.to_markdown(tablefmt="github", index=False) return schedule -@normie_router.get('/normconf') + +@normie_router.get("/normconf") def get_normconf(): - """Return ASCII file of normconf - """ - return FileResponse(Path(f'{goodies_path}normconf_ascii.txt')) + """Return ASCII file of normconf""" + return FileResponse(Path(f"{goodies_path}normconf_ascii.txt")) -@normie_router.get('/zen') +@normie_router.get("/zen") def get_zen(): - """Return Zen of Normcore by Vincent D. Warmerdam - """ - return FileResponse(Path(f'{goodies_path}zen_of_normcore.txt')) + """Return Zen of Normcore by Vincent D. Warmerdam""" + return FileResponse(Path(f"{goodies_path}zen_of_normcore.txt")) + + +@normie_router.post("/get_talk") +def get_talk(request: GetTalkRequest): # -> TalkResponse: -@normie_router.post('/get_talk') -def get_talk(request: GetTalkRequest): #-> TalkResponse: - API_URL = "https://api-inference.huggingface.co/models/gpt2" headers = {"Authorization": f"Bearer {settings.hugging_face_api_key}"} - - response = post(API_URL, headers=headers, json=request.talk_title) + + response = post(API_URL, headers=headers, json=request.talk_title) content = loads(response.text)[0]["generated_text"] - + return TalkResponse(talk_content=content) -@normie_router.get('/random_goodies') + +@normie_router.get("/random_goodies") def get_random_goodie(): - """Return random goodie file from goodies directory - """ - goodie = choice(surprises) + """Return random goodie file from goodies directory""" + link_path = Path("app/goodies/links.txt") + links = open(link_path).read().splitlines() - if goodie.endswith('.png'): - return FileResponse(goodie, - media_type='image/png', - filename=goodie[len(goodies_path):], - headers={'Cache-Control': 'no-cache'}) + goodie = choice(surprises) - return FileResponse(Path(f'{goodie}'), headers={'Cache-Control': 'no-cache'}) + if goodie.endswith(".png"): + return FileResponse( + goodie, + media_type="image/png", + filename=goodie[len(goodies_path) :], + headers={"Cache-Control": "no-cache"}, + ) + return FileResponse(Path(f"{goodie}"), headers={"Cache-Control": "no-cache"}) -@normie_router.get('/allthegoodies') -def get_goodies(): - """Return all the goodes from goodies directory - """ - goodies_len = len(goodies_path) - zip_io = BytesIO() - with ZipFile(zip_io, mode='w', compression=ZIP_DEFLATED) as temp_zip: - for file in surprises: - if "rickroll" in file: - continue - temp_zip.write(file, file[goodies_len:]) +@normie_router.get("/wisdom", response_class=Response) +async def get_random_wisdom(): + """Get a random hand-picked link""" - return StreamingResponse(iter([zip_io.getvalue()]), - media_type="application/x-zip-compressed", - headers = { "Content-Disposition": f"attachment; filename=allthegoodies.zip"} - ) + link_path = Path("app/goodies/links.txt") + links = open(link_path).read().splitlines() + random_link = choice(links) + return Response(random_link + "\n") diff --git a/pyproject.toml b/pyproject.toml index 9531ebd..168240b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,18 +5,18 @@ description = "" authors = ["Ben Labaschin "] [tool.poetry.dependencies] -python = "3.10.4" -uvicorn = "^0.17.6" boto3 = "^1.23.9" fastapi = "^0.78.0" -pydantic = "^1.9.1" +lxml = "^4.9.1" +openpyxl = "^3.0.10" pandas = "^1.4.2" -requests = "^2.27.1" +pydantic = "^1.9.1" +python = "3.10.4" python-dotenv = "^0.20.0" structlog = "^22.1.0" -lxml = "^4.9.1" tabulate = "^0.9.0" -openpyxl = "^3.0.10" +requests = "^2.27.1" +uvicorn = "^0.17.6" [tool.poetry.dev-dependencies] ipykernel = "^6.13.0" From 83e783f599ae3ba6936a918b548890bdd5b5f3cd Mon Sep 17 00:00:00 2001 From: Vicki Date: Thu, 27 Oct 2022 08:56:06 -0400 Subject: [PATCH 2/4] remove unused async calls --- app/main.py | 16 ++++++++-------- app/normconf.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/main.py b/app/main.py index 1e3f87a..43e809b 100644 --- a/app/main.py +++ b/app/main.py @@ -24,7 +24,7 @@ "http://localhost", "http://localhost:8000", "https://localhost:8000", - "https://localhost:443" + "https://localhost:443", ] middleware = [ @@ -40,12 +40,12 @@ # App Setup app = FastAPI( - title="NormConf Goodies App", - description="Send random goods to the normies", - docs_url="/docs", - openapi_url="/api", - middleware=middleware, - ) + title="NormConf Goodies App", + description="Send random goods to the normies", + docs_url="/docs", + openapi_url="/api", + middleware=middleware, +) @app.get("/", tags=["health"], response_model=HealthCheck, name="App Health Check") @@ -67,7 +67,7 @@ def info(settings_: Settings = Depends(get_settings)): @app.get("/v1", tags=["status"], name="V1 Status Check") -async def root(): +def root(): return {"message": f"{settings.app_version}"} diff --git a/app/normconf.py b/app/normconf.py index 17f42aa..4136799 100644 --- a/app/normconf.py +++ b/app/normconf.py @@ -98,7 +98,7 @@ def get_random_goodie(): @normie_router.get("/wisdom", response_class=Response) -async def get_random_wisdom(): +def get_random_wisdom(): """Get a random hand-picked link""" link_path = Path("app/goodies/links.txt") From ddbac244daf6ee44006da61597bb4a6f2efd3051 Mon Sep 17 00:00:00 2001 From: Vicki Date: Thu, 27 Oct 2022 09:00:03 -0400 Subject: [PATCH 3/4] tests --- app/test_main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/test_main.py diff --git a/app/test_main.py b/app/test_main.py new file mode 100644 index 0000000..3190752 --- /dev/null +++ b/app/test_main.py @@ -0,0 +1,10 @@ +from fastapi.testclient import TestClient + +from .main import app + +client = TestClient(app) + + +def test_read_main(): + response = client.get("/") + assert response.status_code == 200 From ebe39f0aa9a20d246f1a073fe590aa33396e3d7a Mon Sep 17 00:00:00 2001 From: Vicki Date: Thu, 27 Oct 2022 09:00:59 -0400 Subject: [PATCH 4/4] add .DS_ignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1cc3fd8..273510e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ /app/__pycache__ /app/*.env -app/__pycache__ \ No newline at end of file +app/__pycache__ + +.DS_Store \ No newline at end of file