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/user/dpng.py
2021-08-01 22:26:55 +08:00

28 lines
755 B
Python

import os
from os.path import abspath
import aiohttp
from modules.wiki.wikilib import wikilib
async def dpng(link, ss):
imgurl = await wikilib().get_image('File:Wiki.png', link)
d = abspath('./assets/Favicon/' + ss + '/')
if not os.path.exists(d):
os.makedirs(d)
path = d + '/Wiki.png'
try:
if not os.path.exists(d):
os.mkdir(d)
if not os.path.exists(path):
async with aiohttp.ClientSession() as session:
async with session.get(imgurl) as resp:
with open(path, 'wb+') as jpg:
jpg.write(await resp.read())
return True
else:
return True
except Exception:
return False