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

33 lines
984 B
Python
Raw Normal View History

2020-06-13 12:43:43 +00:00
import os
2020-09-19 10:35:13 +00:00
from os.path import abspath
2021-02-09 15:33:37 +00:00
import aiohttp
2020-08-12 16:01:34 +00:00
2022-04-08 07:17:39 +00:00
from modules.wiki.wikilib import WikiLib
2020-08-12 16:01:34 +00:00
2021-02-09 15:33:37 +00:00
async def dpng(link, ss):
2022-02-09 12:25:25 +00:00
check = await WikiLib(link).check_wiki_available()
if check:
imgurl = check.value.logo_url
if imgurl is not None:
d = abspath('./assets/Favicon/' + ss + '/')
if not os.path.exists(d):
os.makedirs(d)
path = d + '/Wiki.png'
2020-06-13 12:43:43 +00:00
2022-02-09 12:25:25 +00:00
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
return False