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/userp/puserlib.py

71 lines
3.1 KiB
Python
Raw Normal View History

2020-08-12 16:01:34 +00:00
import os
2020-06-13 12:43:43 +00:00
import re
2020-08-12 16:01:34 +00:00
from os.path import abspath
2020-08-15 07:10:30 +00:00
import aiohttp
from bs4 import BeautifulSoup as bs
from .hh import hh, hh1
2020-08-07 14:27:37 +00:00
from .tpg import tpg
2020-08-12 08:01:00 +00:00
2020-08-12 16:01:34 +00:00
2020-08-12 08:01:00 +00:00
async def get_data(url: str, fmt: str):
async with aiohttp.ClientSession() as session:
2020-08-12 16:01:34 +00:00
async with session.get(url, timeout=aiohttp.ClientTimeout(total=20)) as req:
2020-08-12 08:01:00 +00:00
if hasattr(req, fmt):
return await getattr(req, fmt)()
else:
raise ValueError(f"NoSuchMethod: {fmt}")
2020-08-15 07:10:30 +00:00
def ddk(str1):
2020-08-15 07:11:46 +00:00
a = re.sub(r'<dd>|</dd>', '', str1)
2020-08-15 07:10:30 +00:00
return a
2020-08-12 16:01:34 +00:00
2020-08-13 10:31:52 +00:00
async def PUser1(url, str3, ss, User, Gender, Registration, Blockedby='0', Blockedtimestamp='0', Blockexpiry='0', Blockreason='0'):
2020-06-13 12:43:43 +00:00
q = str3
2020-08-12 16:01:34 +00:00
url2 = url + '/api.php?action=query&meta=allmessages&ammessages=mainpage&format=json'
file2 = await get_data(url2, 'json')
2020-06-13 12:43:43 +00:00
try:
Wikiname = file2['query']['allmessages'][0]['*']
except Exception:
Wikiname = 'Unknown'
2020-08-12 16:01:34 +00:00
d = abspath('./assests/Favicon/' + ss + '/')
2020-06-13 12:43:43 +00:00
if not os.path.exists(d):
os.mkdir(d)
2020-08-12 16:01:34 +00:00
ddd = abspath('./assests/Favicon/' + ss + '/Wiki.png')
2020-06-13 12:43:43 +00:00
if not os.path.exists(ddd):
from .dpng import dpng
2020-08-12 16:01:34 +00:00
dpng(url, ss)
url2 = url + '/UserProfile:' + q
res = await get_data(url2, 'text')
2020-08-12 08:01:00 +00:00
soup = bs(res, 'html.parser')
2020-08-07 14:27:37 +00:00
stats = soup.find('div', class_='section stats')
point = soup.find('div', class_='score').text
dd = stats.find_all('dd')
for tag in dd:
pass
g = re.sub('User:', '', str3)
2020-08-13 10:31:52 +00:00
if Blockedby == '0':
2020-08-15 07:10:30 +00:00
tpg(favicon=abspath('./assests/Favicon/' + ss + '/Wiki.png'), wikiname=hh(Wikiname),
username=User, gender=Gender, registertime=Registration,
contributionwikis=ddk(str(dd[0])), createcount=ddk(str(dd[1])),
editcount=ddk(str(dd[2])), deletecount=ddk(str(dd[3])), patrolcount=ddk(str(dd[4])),
2020-08-13 10:31:52 +00:00
sitetop=ddk(str(dd[5])), globaltop=ddk(str(dd[6])), wikipoint=point)
else:
if Blockreason == '0':
2020-08-15 07:10:30 +00:00
tpg(favicon=abspath('./assests/Favicon/' + ss + '/Wiki.png'), wikiname=hh(Wikiname), username=User,
gender=Gender, registertime=Registration, contributionwikis=ddk(str(dd[0])),
createcount=ddk(str(dd[1])), editcount=ddk(str(dd[2])), deletecount=ddk(str(dd[3])),
patrolcount=ddk(str(dd[4])), sitetop=ddk(str(dd[5])), globaltop=ddk(str(dd[6])),
wikipoint=point, blockbyuser=Blockedby, blocktimestamp1=Blockedtimestamp, blocktimestamp2=Blockexpiry,
2020-08-13 10:31:52 +00:00
bantype='YN')
else:
2020-08-15 07:10:30 +00:00
tpg(favicon=abspath('./assests/Favicon/' + ss + '/Wiki.png'), wikiname=hh(Wikiname), username=User,
gender=Gender, registertime=Registration, contributionwikis=ddk(str(dd[0])),
createcount=ddk(str(dd[1])), editcount=ddk(str(dd[2])), deletecount=ddk(str(dd[3])),
patrolcount=ddk(str(dd[4])), sitetop=ddk(str(dd[5])), globaltop=ddk(str(dd[6])),
wikipoint=point, blockbyuser=Blockedby, blocktimestamp1=Blockedtimestamp, blocktimestamp2=Blockexpiry,
blockreason=hh1(Blockreason), bantype='Y')
2020-08-12 16:01:34 +00:00