Commit adc1f5c8 by 岳巧源

add pop update

parent efbabccd
Showing with 88 additions and 0 deletions
"""
拉取及更新pop店铺最新数据。
"""
from common import request_to_jd_pop
import pymysql
import time
import sys
config_dev = {
"mysql": {
"host": "192.168.1.238",
"port": 3306,
"user": "liexin_data_distribution",
"password": "liexin_data_distribution#zsyM",
"database": "liexin_data_distribution"
},
"redis": {
"host": "192.168.1.235",
"port": 6379,
"password": "icDb29mLy2s"
}
}
config_prod = {
"mysql": {
"host": "bigdata2.ichunt.db",
"port": 3306,
"user": "DsbuUx",
"password": "sfj09JjsfpQx0",
"database": "liexin_data_distribution"
},
"redis": {
"host": "172.18.137.38",
"port": 6379,
"password": "icDb29mLy2s"
}
}
def update_pop_class(conf: dict):
"""
更新pop得分类
"""
method_name = "jingdong.vender.category.getFullValidCategoryResultByVenderId"
token = "74ee3f2fa54d489da0d1b94ca83c9bc7lztn"
app_key = "CCE6563827D13EDF4769C01E7429378D"
app_secret = "98c72374c5b045529879786fc4e5c20e"
param = {
}
ans = request_to_jd_pop(method_name, token, app_key, app_secret, param)
data = ans["jingdong_vender_category_getFullValidCategoryResultByVenderId_responce"]["returnType"]["list"]
db = pymysql.connect(host=conf["mysql"]["host"],
port=conf["mysql"]["port"],
user=conf["mysql"]["user"],
database=conf["mysql"]["database"],
password=conf["mysql"]["password"])
cursor = db.cursor()
for i in range(len(data)):
parent_id = data[i]["fid"]
class_id = data[i]["id"]
class_name = data[i]["name"]
depth = data[i]["lev"]
status = 1
platform = 3
create_time = int(time.time())
select_sql = "select id from lie_shop_class where platform = 3 and class_id = %s"
cursor.execute(query=select_sql, args=(class_id,))
db_result = cursor.fetchall()
if len(db_result) == 0:
sql = "insert into lie_shop_class (parent_id, class_id, class_name, depth, status, platform, create_time) values (%s, %s, %s, %s, %s, %s, %s)"
cursor.execute(query=sql, args=(parent_id, class_id, class_name, depth, status, platform, create_time))
db.commit()
print(sql % (parent_id, class_id, class_name, depth, status, platform, create_time))
if __name__ == '__main__':
option = {"dev", "prod"}
if len(sys.argv) >= 2 and sys.argv[1] in option:
environment = sys.argv[1]
else:
print("命令选项:\n线上:python3 crontab_pop.py prod\n测试:python3 crontab_pop.py dev\n")
sys.exit(1)
config = config_dev
if environment == "dev":
config = config_dev
elif environment == "prod":
config = config_prod
update_pop_class(config)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment