# -*- coding: utf-8 -*- """为商品评价接口造黄金样本数据(本地库 192.168.1.177/shop)。 本地 PHP 站点(php -S 127.0.0.1:8899)与 Java 共用同一个库,造完即可双端对比。 用法:python seed_comment_golden.py [--cleanup] """ import sys import pymysql HOST = "192.168.1.177" USER = "root" PASSWORD = "@@qinys12346.." DB = "shop" NOW = 1792250000 # 固定时间,便于双端逐字段对照 def connect(): return pymysql.connect(host=HOST, user=USER, password=PASSWORD, database=DB, autocommit=True, charset="utf8mb4") def cleanup(cur): cur.execute("delete from yoshop_comment_image where comment_id in (10001,10002,10003,10004)") cur.execute("delete from yoshop_comment where comment_id in (10001,10002,10003,10004)") def seed(cur): cleanup(cur) rows = [ # comment_id, score, content, is_picture, status, sort, user, order, goods, order_goods, # is_delete, create, update (10001, 10, "很好吃,包装也扎实", 1, 1, 0, 10001, 10001, 10004, 10001, 0, NOW - 300, NOW - 300), (10002, 20, "一般般吧", 0, 1, 0, 10001, 10002, 10003, 10002, 0, NOW - 200, NOW - 200), (10003, 30, "差评,不推荐", 0, 0, 1, 10001, 10001, 10004, 10001, 0, NOW - 100, NOW - 100), (10004, 10, "这条应被过滤", 0, 1, 0, 10001, 10001, 10004, 10001, 1, NOW, NOW), ] cur.executemany( "insert into yoshop_comment (comment_id, score, content, is_picture, status, sort, user_id," " order_id, goods_id, order_goods_id, store_id, is_delete, create_time, update_time)" " values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,10001,%s,%s,%s)", rows) cur.executemany( "insert into yoshop_comment_image (comment_id, image_id, store_id, create_time)" " values (%s,%s,10001,%s)", [(10001, 10001, NOW - 300), (10001, 10002, NOW - 300), (10002, 10005, NOW - 200)]) def main(): conn = connect() cur = conn.cursor() if "--cleanup" in sys.argv: cleanup(cur) print("已清理评价测试数据") else: seed(cur) print("已写入评价测试数据:comment 10001-10004 / comment_image 3 条") conn.close() if __name__ == "__main__": main()