gold_readbag and russian

This commit is contained in:
hibiki
2021-06-15 10:57:08 +08:00
parent 95209093de
commit ea620fdae9
125 changed files with 2106 additions and 1244 deletions
+24
View File
@@ -0,0 +1,24 @@
from models.group_member_info import GroupInfoUser
# 生成通用排行榜
async def init_rank(users: list, all_user_data: list, group_id: int):
all_user_id = [user.user_qq for user in users]
rst = ''
for i in range(len(all_user_id) if len(all_user_id) < 10 else 10):
max_gold = max(all_user_data)
max_user_id = all_user_id[all_user_data.index(max_gold)]
all_user_id.remove(max_user_id)
all_user_data.remove(max_gold)
try:
user_name = (await GroupInfoUser.select_member_info(max_user_id, group_id)).user_name
except AttributeError:
user_name = f'{max_user_id}'
rst += f'{user_name}: {max_gold}\n'
return rst[:-1]
+140
View File
@@ -0,0 +1,140 @@
import requests
from util.user_agent import get_user_agent
from bs4 import BeautifulSoup
from time import sleep
import threading
import os
from configs.path_config import IMAGE_PATH
lock = threading.Lock()
url = "https://search.bilibili.com/article"
# path = IMAGE_PATH + "setu/"
index = 1
THREAD_SUM_REMAINDER = 2 # 越小线程越多
class bilibiliThread (threading.Thread):
def __init__(self, threadId, url_list, path, nolist):
threading.Thread.__init__(self)
self.threadId = threadId
self.url_list = url_list
self.path = path
self.nolist = nolist
def run(self):
print("开始线程<><><><><><><><><> " + self.threadId)
thread_get_url(self.threadId, self.url_list, self.path, self.nolist)
def get_bilibili_img(name, path, nolist=None):
global index
index = get_dirfile_len(path)
print("index===", index)
threadId = 1
params = {
'keyword': name,
'page': '1'
}
res = requests.get(url, headers=get_user_agent(), params=params)
sleep(8)
soup = BeautifulSoup(res.text, 'html.parser')
# print(soup.text)
try:
total_page = soup.find_all('button', {'class': 'pagination-btn'})[-1].text.strip()
print("1 try")
except:
try:
total_page = soup.find_all('button', {'class': 'pagination-btn num-btn'})[-1].text.strip()
print("2 try")
except:
total_page = 1
print("3 except")
print(total_page)
url_list = []
for page in range(1, int(total_page)+1):
url_r = "https://search.bilibili.com/article?keyword=" + name + "&page=" + str(page)
url_list.append(url_r)
if page % THREAD_SUM_REMAINDER == 0:
print('-----> ' + str(page) + " =======>", url_list)
# _thread.start_new_thread(thread_get_url, (url_list, path,))
bilibiliThread(str(threadId), url_list, path, nolist).start()
threadId += 1
sleep(0.5)
url_list = []
if url_list:
print("=========================最后一个线程启动========================= url数量: ", len(url_list))
bilibiliThread(str(threadId), url_list, path, nolist).start()
def thread_get_url(threadId, url_list, path, nolist):
for url in url_list:
res = requests.get(url, headers=get_user_agent())
sleep(2)
soup = BeautifulSoup(res.text, 'lxml')
alist = soup.find_all('a', {'class': 'poster'})
img_content_page = []
# print(alist)
for a in alist:
if nolist != None:
if a.get('href') not in nolist:
img_content_page.append("https://" + a.get('href')[2:])
else:
img_content_page.append("https://" + a.get('href')[2:])
pic_url = []
for img_content in img_content_page:
print("开始获取---------->", img_content)
res = requests.get(img_content, headers=get_user_agent())
sleep(2)
soup = BeautifulSoup(res.text, 'lxml')
figure_ls = soup.body.find_all('figure')
# print(figure_ls)
for figure in figure_ls:
try:
_ = figure.img.attrs['class']
except:
data_src = figure.img.attrs['data-src']
pic_url.append('https:' + data_src)
print("线程 " + threadId + " 获取完毕------> 开始存储")
for url in pic_url:
print("线程 " + threadId + "正在存储---------------->", url)
res = requests.get(url, headers=get_user_agent())
save_img(res.content, path, threadId)
pic_url = []
print("线程 " + threadId + " ---------------->执行完毕")
def save_img(img, path, threadId):
global index
try:
lock.acquire()
img_index = index
finally:
lock.release()
try:
with open(path + str(img_index) + ".jpg", 'wb') as f:
f.write(img)
lock.acquire()
index += 1
except:
print("线程 " + threadId + "存储失败-------->" + str(img_index) + ".jpg")
finally:
lock.release()
def get_dirfile_len(path):
return len(os.listdir(path))
if __name__ == '__main__':
# url = "https://search.bilibili.com" \
# "/article?keyword=%23%E4%BB%8A%E6%97%A5%E4%BB%BD%E7%9A%84%E5%8F%AF%E7%88%B1%" \
# "E5%B0%8F%E8%90%9D%E8%8E%89%EF%BC%8C%E8%BF%9B%E6%9D%A5%E7%9C%8B%E7%9C%8B%EF%BC%8C%E" \
# "6%8F%90%E7%A5%9E%E9%86%92%E8%84%91%EF%BC%81"
# res = requests.get(url, headers=get_user_agent())
# sleep(2)
# soup = BeautifulSoup(res.text, 'lxml')
# alist = soup.find_all('button', {'class': 'pagination-btn num-btn'})
# total_page = soup.find_all('button', {'class': 'pagination-btn num-btn'})[-1].text.strip()
# print(total_page)
get_bilibili_img("精选动漫壁纸手机电脑壁纸&动漫游戏专题", IMAGE_PATH + "bizhi/")
+29 -3
View File
@@ -246,8 +246,13 @@ class CreateImg:
self.markImg.show(self.markImg)
# 压缩
def resize(self, ratio):
self.markImg = self.markImg.resize((int(self.w * ratio), int(self.h * ratio)), Image.ANTIALIAS)
def resize(self, ratio=0, w=0, h=0):
if not w and not h and not ratio:
raise Exception('缺少参数...')
if not w and not h and ratio:
w = int(self.w * ratio)
h = int(self.h * ratio)
self.markImg = self.markImg.resize((w, h), Image.ANTIALIAS)
self.w, self.h = self.markImg.size
self.size = self.w, self.h
self.draw = ImageDraw.Draw(self.markImg)
@@ -273,12 +278,33 @@ class CreateImg:
buf = BytesIO()
self.markImg.save(buf, format='PNG')
base64_str = base64.b64encode(buf.getvalue()).decode()
return 'base64://' + base64_str
return base64_str
#
def convert(self, itype):
self.markImg = self.markImg.convert(itype)
# 变圆
def circle(self):
self.convert('RGBA')
r2 = min(self.w, self.h)
if self.w != self.h:
self.resize(w=r2, h=r2)
r3 = int(r2 / 2)
imb = Image.new('RGBA', (r3 * 2, r3 * 2), (255, 255, 255, 0))
pima = self.markImg.load() # 像素的访问对象
pimb = imb.load()
r = float(r2 / 2)
for i in range(r2):
for j in range(r2):
lx = abs(i - r) # 到圆心距离的横坐标
ly = abs(j - r) # 到圆心距离的纵坐标
l = (pow(lx, 2) + pow(ly, 2)) ** 0.5 # 三角函数 半径
if l < r3:
pimb[i - (r - r3), j - (r - r3)] = pima[i, j]
self.markImg = imb
if __name__ == '__main__':
pass
+2
View File
@@ -2,6 +2,7 @@ from configs.path_config import IMAGE_PATH, VOICE_PATH
from nonebot.adapters.cqhttp.message import MessageSegment
import os
from services.log import logger
import ujson
def image(img_name: str = None, path: str = '', abspath: str = None, b64: str = None):
@@ -68,6 +69,7 @@ def xml(data):
def json(data):
data = ujson.dumps(data)
return MessageSegment.json(data)