From 48364cfc64dc43a842fdd2e5c3353651ae5c6c0d Mon Sep 17 00:00:00 2001 From: MarkusJoe Date: Sat, 19 Feb 2022 10:45:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 3 +-- bin/tests/arg.py | 4 ---- bin/tests/connectdb.py | 27 ------------------------- bin/tests/download.py | 25 ----------------------- bin/tests/findrootdir.py | 28 -------------------------- bin/tests/get_all_theme.py | 34 ------------------------------- bin/tests/img2base64.py | 11 ---------- bin/tests/init_db.py | 8 ++++++-- bin/tests/read_db.py | 40 ------------------------------------- bin/tests/test.http | 4 ++++ db/count.db | Bin 12288 -> 12288 bytes db/sqlite.py | 3 +++ 12 files changed, 14 insertions(+), 173 deletions(-) delete mode 100644 bin/tests/arg.py delete mode 100644 bin/tests/connectdb.py delete mode 100644 bin/tests/download.py delete mode 100644 bin/tests/findrootdir.py delete mode 100644 bin/tests/get_all_theme.py delete mode 100644 bin/tests/img2base64.py delete mode 100644 bin/tests/read_db.py create mode 100644 bin/tests/test.http diff --git a/app.py b/app.py index f5fb9e4..e9add49 100644 --- a/app.py +++ b/app.py @@ -114,8 +114,6 @@ def main() -> Response or str: if theme == 'ls': return ErrorProcess().get_theme_list() if name and name != 'null': - if not length: - length = 7 if not theme: theme = 'lewd' build_page_result = build_page(name, length, theme) # 开始处理整体页面 @@ -131,6 +129,7 @@ def main() -> Response or str: elif build_page_result[1] == 'BadTheme': # 输入的主题错误 return ErrorProcess().error_theme(theme) else: # 长度过长无法计数重置数据库内的已有数据 + logger.critical(f'用户: {name} 数据已被重置') return build_page_result[1] else: return ErrorProcess().arg_not_be_full() diff --git a/bin/tests/arg.py b/bin/tests/arg.py deleted file mode 100644 index 78c3793..0000000 --- a/bin/tests/arg.py +++ /dev/null @@ -1,4 +0,0 @@ -import sys - - -print(sys.argv) \ No newline at end of file diff --git a/bin/tests/connectdb.py b/bin/tests/connectdb.py deleted file mode 100644 index 5b80143..0000000 --- a/bin/tests/connectdb.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 -# -- coding:utf-8 -- -# @Author: markushammered@gmail.com -# @Development Tool: PyCharm -# @Create Time: 2022/2/16 -# @File Name: connectdb.py - - -import sqlite3 - - -def exec(cmd): - try: - conn = sqlite3.connect('../../db/count.db') - cursor = conn.cursor() - cursor.execute(cmd) - return cursor.fetchall() - finally: - cursor.close() - conn.close() - - -if __name__ == '__main__': - while True: - cmd = input('>>>') - print(exec(cmd)) - diff --git a/bin/tests/download.py b/bin/tests/download.py deleted file mode 100644 index f3597c2..0000000 --- a/bin/tests/download.py +++ /dev/null @@ -1,25 +0,0 @@ -import base64 -from PIL import Image -import os -import sqlite3 - - -conn = sqlite3.connect('../../db/.db') -cursor = conn.cursor() - -file_list = os.listdir('../assets/themes/') -for i in file_list: - img = Image.open(f'../assets/themes/{i}/0.gif') - w = img.width - h = img.height - img.close() - for n in range(0, 10): - with open(f'../assets/themes/{i}/{n}.gif', 'rb') as f: - base64_data = base64.b64encode(f.read()) - base64_code = f'data:image/gif;base64,' + base64_data.decode('utf-8') - - try: - cursor.execute('insert into %(name)s values(?, ?, ?, ?)' % {'name': i}, (n, base64_code, w, h)) - conn.commit() - except Exception: - cursor.execute('create table %(name)s (k text, v text, w integer, h integer)' % {'name': i}) \ No newline at end of file diff --git a/bin/tests/findrootdir.py b/bin/tests/findrootdir.py deleted file mode 100644 index f15c89e..0000000 --- a/bin/tests/findrootdir.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python3 -# -- coding:utf-8 -- -# @Author: markushammered@gmail.com -# @Development Tool: PyCharm -# @Create Time: 2022/2/16 -# @File Name: findrootdir.py - - -import os - - -class Checkout: - def __init__(self, path: str): - self.path = path.split('/')[:-1] - - def checkout_path(self, path: str): - if os.path.exists(f'{path}/utils'): - return True - else: - return False - - def run(self): - for i in range(len(self.path)): - current_path = '/'.join('/'.join(self.path).split('/')[:-i]) - if self.checkout_path(current_path): - return current_path - - diff --git a/bin/tests/get_all_theme.py b/bin/tests/get_all_theme.py deleted file mode 100644 index d9e2e24..0000000 --- a/bin/tests/get_all_theme.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python3 -# -- coding:utf-8 -- -# @Author: markushammered@gmail.com -# @Development Tool: PyCharm -# @Create Time: 2022/2/11 -# @File Name: get_all_theme.py - - -import random -import base64 -import sqlite3 - -conn = sqlite3.connect('../../db/style.db') -cursor = conn.cursor() - - -def get_all_theme(): - cursor.execute('select * from sqlite_master where type="table"') - table_list = cursor.fetchall() - table_name_list = [] - for i in table_list: - table_name_list.append(i[1]) - - for n in table_name_list: - cursor.execute('select * from %(name)s' % {'name': n}) - for i in cursor.fetchall(): - img_data = base64.b64decode(i[1].replace('data:image/gif;base64,', '')) - with open(str(random.randint(0, 9999)) + '.gif', 'wb') as fp: - fp.write(img_data) - # if i[1] == '': - # print(n) - - -get_all_theme() diff --git a/bin/tests/img2base64.py b/bin/tests/img2base64.py deleted file mode 100644 index 94c1255..0000000 --- a/bin/tests/img2base64.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python3 -# -- coding:utf-8 -- -# @Author: markushammered@gmail.com -# @Development Tool: PyCharm -# @Create Time: 2022/2/12 -# @File Name: img2base64.py - - -import base64 - -print(base64.b64encode(open('example.png', 'rb').read()).decode('utf-8')) \ No newline at end of file diff --git a/bin/tests/init_db.py b/bin/tests/init_db.py index 3d19af6..77f9976 100644 --- a/bin/tests/init_db.py +++ b/bin/tests/init_db.py @@ -13,8 +13,12 @@ if __name__ == '__main__': while True: yes_or_no = input('该操作会将数据库初始化输入y继续:') if yes_or_no == 'y': - os.remove('../../db/data.db') - conn = sqlite3.connect('../../db/data.db') + try: + os.remove('../../db/count.db') + except PermissionError: + print('有其他程序正在使用此数据库无法删除') + sys.exit(-1) + conn = sqlite3.connect('../../db/count.db') cursor = conn.cursor() cursor.execute('create table ReqCount (name text primary key, times integer )') sys.exit(0) diff --git a/bin/tests/read_db.py b/bin/tests/read_db.py deleted file mode 100644 index d38323c..0000000 --- a/bin/tests/read_db.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python3 -# -- coding:utf-8 -- -# @Author: markushammered@gmail.com -# @Development Tool: PyCharm -# @Create Time: 2022/2/18 -# @File Name: read_db.py - - -# import sqlite3 -# -# -# conn = sqlite3.connect('../../db/style.db') -# cursor = conn.cursor() -# cursor.execute('drop table dollstuffing') - - -import requests -import threading -from bs4 import BeautifulSoup - -saved = ['gelbooru', 'moebooru', 'g', 'cripple', 'blacked', 'rule34', 'steambanner', 'lefty', 'crewbooru', 'sthg', - 'rfck', 'lisu', 'tv', 'lewd', 'amibooru', 'blankatlas', 'mmballbusting', 'sss', 'legolamb', 'goldengator', - 'r6gdrawfriends', 'vivi', 'twifanartsfw', 'hololive', 'vglobby', 'jaypee', 'melanin', 'orb', 'min', 'mjg', - 'cloppers', 'townofgravityfalls', 'brown', 'enacdoa', 'daifuku', 'osc', 'girlsfeet', 'hybreedsgeneral', 'sr', - 'mono', 'riskofrain', 'neovb', 'ffsr'] - - -def req(name): - print(name) - resp = requests.get(f'http://127.0.0.1:5000/get?name=sdsa&theme={name}') - soup = BeautifulSoup(resp.text, 'html.parser').findAll('image') - for i in soup: - with open(f'{name}.txt', 'w') as fp: - fp.write(f'{i}\n') - - -for i in saved: - a = threading.Thread(target=req, args=(i,)) - a.start() - a.join() diff --git a/bin/tests/test.http b/bin/tests/test.http new file mode 100644 index 0000000..fbc4864 --- /dev/null +++ b/bin/tests/test.http @@ -0,0 +1,4 @@ +# http +GET http://localhost:5000/get?name=HTTPtest +Accept: application/json + diff --git a/db/count.db b/db/count.db index 5858b715c39594ef038c49bad4852bcfabb5f412..b34b700a3560c86989a4dbf6d438d14f6beb63fa 100644 GIT binary patch delta 115 zcmZojXh@hK#l%oQQN{^KZcJFn&&|NVz{LNAf&VlAlg)|>Q~4)0IBW1SG0QXhCKhFv r7JKEV)^am4%W`^zgankN7ME~=H9TYB|HA(as=-x?7g;?MH15QOh;bMJ1`Or9aA!5@-3kS2A0z&kjtgcK)O`hJ48A&rH#gg_u&iZp3b zSc#oj2?`R@Xysl&o85t7=9{{ztJ|(IUw3DHxwGmXr+8M3iNY&(c*g^_SYwGtOy*^) z#tkza>l8x_J>Q^?zC6E<#(PmQg?Pe_Iwpx!pT3~B2`OswR_u%M_-cf2#hfFBrc!DK zj;NjMj;tZ*V3bmhQ*6p-EEM*5!U`{V!w){NfZoWADTe~ PLmSx<7}*2MQYolkbhJIQ diff --git a/db/sqlite.py b/db/sqlite.py index 7cfd4cb..6a0e85d 100644 --- a/db/sqlite.py +++ b/db/sqlite.py @@ -111,3 +111,6 @@ def fetch_style_data(style: str) -> list[dict[str, Any]]: finally: cursor.close() conn.close() + + +__all__ = ['fetch_table', 'fetch_data', 'fetch_style_data', 'update_data', 'insert_data']