Skip to content

Commit 4d559fb

Browse files
author
Andrew Brookins
committed
Use httpx for requests
1 parent 8817607 commit 4d559fb

File tree

5 files changed

+152
-185
lines changed

5 files changed

+152
-185
lines changed

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.8.11

app/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from typing import Union
1212

1313
import aioredis
14-
import requests
14+
import httpx
1515
from aioredis.exceptions import ResponseError
1616
from fastapi import BackgroundTasks
1717
from fastapi import Depends
@@ -188,8 +188,9 @@ async def calculate_three_hours_of_data(keys: Keys) -> Dict[str, str]:
188188

189189
@app.post('/refresh')
190190
async def bitcoin(background_tasks: BackgroundTasks, keys: Keys = Depends(make_keys)):
191-
data = requests.get(SENTIMENT_API_URL).json()
192-
await persist(keys, data)
191+
async with httpx.AsyncClient() as client:
192+
data = await client.get(SENTIMENT_API_URL)
193+
await persist(keys, data.json())
193194
data = await calculate_three_hours_of_data(keys)
194195
background_tasks.add_task(set_cache, data, keys)
195196

0 commit comments

Comments
 (0)