tianyun преди 2 години
родител
ревизия
d7a6ea35cc
променени са 2 файла, в които са добавени 13 реда и са изтрити 13 реда
  1. 5 2
      project/compress_db_img.py
  2. 8 11
      tmp1.py

+ 5 - 2
project/compress_db_img.py

@@ -7,7 +7,7 @@ conn = sqlite3.connect('/Users/alvin/memos_prod.db')
 cursor = conn.cursor()
 
 # 查询不是webp格式的图片数据
-cursor.execute("SELECT id, filename, `blob`, type, size FROM resource WHERE type like 'image%' AND type != 'image/webp'")
+cursor.execute("SELECT id, filename, `blob`, type, size FROM resource WHERE type like 'image%'  AND type != 'image/webp'")
 
 # 获取查询结果的所有行
 rows = cursor.fetchall()
@@ -28,7 +28,7 @@ for row in rows:
     new_blob = io.BytesIO()
 
     # 将图片压缩为webp格式并保存到新的内存缓冲区
-    image.save(new_blob, format='webp', quality=90)
+    image.save(new_blob, format='webp', quality=50)
 
     # 获取新的图片数据和相关信息
     new_blob_data = new_blob.getvalue()
@@ -36,6 +36,9 @@ for row in rows:
     new_filename = filename.rsplit('.', 1)[0] + '.webp'
     new_type = 'image/webp'
 
+    # 日志打印
+    print(f'{image_id}压缩前: {old_size}, 压缩后:{new_size}')
+
     # 更新数据库中的记录
     cursor.execute("UPDATE resource SET filename=?, blob=?, type=?, size=? WHERE id=?", (new_filename, new_blob_data, new_type, new_size, image_id))
 

+ 8 - 11
tmp1.py

@@ -1,12 +1,9 @@
-from tps_util import test_api_tps
+def print_time(code_str, number=1):
+    import timeit
+    sum_result = timeit.timeit(code_str, number=number, globals=globals(), setup='pass')
+    sum_result *= 1000
+    print(f"执行时间: {int(sum_result)} 毫秒")
 
-for i in range(5):
-    test_api_tps('http://172.18.196.182:8000/categoryscope/', 'post', json={
-        "spmc": ["*通用设备*水机配件"],
-        "scope": "制造、研发、设计、销售、安装、维修、租赁:太空能热水设备、太阳能热水器系统、空气能热泵热水设备、太阳能光伏系统、净水设备、饮水设备、保温水箱、给排水系统设备、水平衡测试、空调设备、空气净化设备、通风系统、电子产品,承接:市政工程、太阳能与热泵联合节能热水系统改造工程及维护保养、制冷空调系统安装及维护保养、机电设备节能改造工程及维护保养、节水改造工程、消防工程、地基与基础工程。(依法须经批准的项目,经相关部门批准后方可开展经营活动)",
-        "je": [1123.710],
-        "se": [179.790],
-        "taxpayerId": "91440606784867381F",
-        "kprq": ["2019-03-14 00:00:00"],
-        "fpdm": ["4400181130"]
-    }, concurrency=i + 1, duration=10, print_res=False)
+
+a = 123
+print_time("print(a)")