From 003a77e0260d0df5e2d3a7d6cbb5cf465d6bf045 Mon Sep 17 00:00:00 2001 From: liaozetao <1107136310@qq.com> Date: Wed, 18 Oct 2023 11:13:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/download_gift.py | 73 +++++++++++++++++++++++++ python/peko_seize_treasure_user_info.py | 1 - 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 python/download_gift.py diff --git a/python/download_gift.py b/python/download_gift.py new file mode 100644 index 000000000..0154d1b79 --- /dev/null +++ b/python/download_gift.py @@ -0,0 +1,73 @@ +import os +import pymysql +import uuid +import requests +import json + +MYSQL_CONFIG = { + "host": "172.22.0.8", + "port": 3306, + "username": "root", + "password": "pc8DphhaXwTe2jyv", + "db": "peko" +} + + +def connect(): + return pymysql.connect( + host=MYSQL_CONFIG['host'], + user=MYSQL_CONFIG['username'], + password=MYSQL_CONFIG['password'], + db=MYSQL_CONFIG['db'], + charset='utf8' + ) + + +def select_list(sql): + conn = connect() + cursor = conn.cursor() + cursor.execute(sql) + results = cursor.fetchall() + fields = [field[0] for field in cursor.description] + result = [dict(zip(fields, result)) for result in results] + conn.close() + return result + + +def update(sql): + conn = connect() + cursor = conn.cursor() + cursor.execute(sql) + conn.commit() + conn.close() + + +def parse(data): + if data is None or len(data) == 0: + return + print(data) + for item in data: + gift_id = item['gift_id'] + gift_name = item['gift_name'] + vgg_url = item['vgg_url'] + download(gift_id, gift_name, vgg_url) + + +def download(gift_id, gift_name, url): + filename = str(gift_id) + '_' + gift_name + print('gift_id : ', gift_id, ', gift_name : ', gift_name) + try: + response = requests.get(url) + if response.status_code == 200: + with open(filename, 'wb') as f: + f.write(response.content) + else: + filename = None + print('download failed, ', url) + except Exception as e: + print(e) + return filename + + +if __name__ == '__main__': + parse(select_list('select gift_id, gift_name, gold_price, gift_status, vgg_url from gift where gold_price > 10000;')) \ No newline at end of file diff --git a/python/peko_seize_treasure_user_info.py b/python/peko_seize_treasure_user_info.py index 3194bc565..bba139e2f 100644 --- a/python/peko_seize_treasure_user_info.py +++ b/python/peko_seize_treasure_user_info.py @@ -1,7 +1,6 @@ # pip3 install redis import redis -import json from concurrent.futures import ThreadPoolExecutor res = None