- commit
- eda9aed4d363e669a60e7160cb055efa41ca2ad1
- parent
- 220d6dad6099c0a6966562d6d0fd8d612c3e5643
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-10-03 04:20
port fetch to aiohttp
Diffstat
M | neddit.py | 22 | +++++++++++----------- |
1 files changed, 11 insertions, 11 deletions
diff --git a/neddit.py b/neddit.py
@@ -2,7 +2,7 @@ import re 2 2 import functools 3 3 from datetime import datetime 4 45 -1 import requests-1 5 import aiohttp 6 6 import jinja2 7 7 from aiohttp import web 8 8 @@ -69,16 +69,16 @@ env.filters['dash_resize'] = dash_resize 69 69 70 70 71 71 async def fetch(url, **params):72 -1 r = requests.get(73 -1 url,74 -1 headers={'User-agent': 'neddit'},75 -1 params={**params, 'raw_json': 1},76 -1 )77 -1 if r.status_code != 200:78 -1 if r.status == 404:79 -1 raise web.HTTPNotFound80 -1 r.raise_for_status()81 -1 return r.json()-1 72 async with aiohttp.ClientSession() as session: -1 73 async with session.get( -1 74 url, -1 75 headers={'User-agent': 'neddit'}, -1 76 params={**params, 'raw_json': 1}, -1 77 ) as response: -1 78 if response.status == 404: -1 79 raise web.HTTPNotFound -1 80 response.raise_for_status() -1 81 return await response.json() 82 82 83 83 84 84 @async_cache()