Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/ask/formatting.py

26 lines
1 KiB
Python

import aiohttp
import ujson as json
async def generate_latex(formula: str):
async with aiohttp.ClientSession() as session:
async with session.post(url='https://wikimedia.org/api/rest_v1/media/math/check/inline-tex', data=json.dumps({
'q': formula
}), headers={'content-type': 'application/json'}) as req:
headers = req.headers
location = headers.get('x-resource-location')
async with session.get(url=f'https://wikimedia.org/api/rest_v1/media/math/render/png/{location}') as img:
return await img.read()
async def generate_code_snippet(code: str, language: str):
async with aiohttp.ClientSession() as session:
async with session.post(url='https://sourcecodeshots.com/api/image', data=json.dumps({
'code': code,
'settings': {
'language': language,
'theme': 'night-owl',
}
}), headers={'content-type': 'application/json'}) as req:
return await req.read()