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
2020-09-25 23:19:54 +08:00

35 lines
934 B
Python

import os
import re
from os.path import abspath
import requests
from bs4 import BeautifulSoup as bs
def dpng(link, ss):
print(link)
q = requests.get(link + 'File:Wiki.png', timeout=10)
soup = bs(q.text, 'html.parser')
aa = soup.find('div', id='mw-content-text')
src = aa.find_all('div', class_='fullImageLink')
z = re.match('.*<a href="(.*)"><.*', str(src), re.S)
url = z.group(1)
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):
r = requests.get(url, timeout=30)
r.raise_for_status()
with open(path, 'wb') as f:
f.write(r.content)
f.close()
return True
else:
return True
except Exception:
return False