补充
This commit is contained in:
73
python/download_gift.py
Normal file
73
python/download_gift.py
Normal file
@@ -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;'))
|
@@ -1,7 +1,6 @@
|
|||||||
# pip3 install redis
|
# pip3 install redis
|
||||||
|
|
||||||
import redis
|
import redis
|
||||||
import json
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
res = None
|
res = None
|
||||||
|
Reference in New Issue
Block a user