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

36 lines
934 B
Python
Raw Normal View History

2020-06-13 12:43:43 +00:00
import os
2020-08-12 16:01:34 +00:00
import re
2020-09-19 10:35:13 +00:00
from os.path import abspath
2020-08-12 16:01:34 +00:00
import requests
from bs4 import BeautifulSoup as bs
def dpng(link, ss):
2020-09-25 15:19:54 +00:00
print(link)
q = requests.get(link + 'File:Wiki.png', timeout=10)
2020-08-12 16:01:34 +00:00
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)
2020-09-20 10:36:32 +00:00
d = abspath('./assets/Favicon/' + ss + '/')
2020-06-13 12:43:43 +00:00
if not os.path.exists(d):
os.makedirs(d)
2020-08-12 16:01:34 +00:00
path = d + '/Wiki.png'
2020-06-13 12:43:43 +00:00
try:
if not os.path.exists(d):
os.mkdir(d)
if not os.path.exists(path):
2020-08-12 16:01:34 +00:00
r = requests.get(url, timeout=30)
2020-06-13 12:43:43 +00:00
r.raise_for_status()
2020-08-12 16:01:34 +00:00
with open(path, 'wb') as f:
2020-06-13 12:43:43 +00:00
f.write(r.content)
f.close()
2020-09-25 15:19:54 +00:00
return True
2020-06-13 12:43:43 +00:00
else:
2020-09-25 15:19:54 +00:00
return True
except Exception:
return False