upload
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,72 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import jsonpath
|
||||
|
||||
import newsetting as ten
|
||||
|
||||
tent2 = ten.All_Setting(host='183.6.7.91',port=33016,db='mt_all_medince')
|
||||
|
||||
|
||||
def get_path2(path):
|
||||
li = []
|
||||
|
||||
for a,b,c in os.walk(path):
|
||||
if len(c)>0:
|
||||
for d in c:
|
||||
if 'food' in d:
|
||||
li.append(os.path.join(a,d))
|
||||
return li
|
||||
|
||||
|
||||
|
||||
|
||||
def rec_food(req,workid,business_code,mt_org_id,parent_id):
|
||||
def get_coupon():
|
||||
li = []
|
||||
coupon_list = poi_coupon['coupon_list']
|
||||
for i in coupon_list:
|
||||
coupon_id = i.get('coupon_id')
|
||||
|
||||
coupon_name = i.get('coupon_name')
|
||||
new_limit_price = i.get('new_limit_price')
|
||||
coupon_type_label = i.get('coupon_type_label')
|
||||
tabName = i.get('tabName')
|
||||
product_num = i.get('product_num')
|
||||
label_doc = jsonpath.jsonpath(i, '$..label_doc')
|
||||
da = (poi_id_str, coupon_id, coupon_name, new_limit_price, coupon_type_label, tabName, product_num,
|
||||
label_doc)
|
||||
li.append(da)
|
||||
return li
|
||||
def get_discounts2():
|
||||
li = []
|
||||
for i in discounts2:
|
||||
id = i.get('id')
|
||||
info = i.get('info')
|
||||
da = (poi_id_str, id, info)
|
||||
li.append(da)
|
||||
return li
|
||||
wm_poi_id = req['data']['poi_info']['id']
|
||||
poi_id_str = req['data']['poi_info']['poi_id_str']
|
||||
shop_name = req['data']['poi_info']['name']
|
||||
address = req['data']['poi_info']['address']
|
||||
poi_coupon = req['data']['poi_info'].get('poi_coupon')
|
||||
discounts2 = req['data']['poi_info']['discounts2']
|
||||
poi_info = req['data']['poi_info']
|
||||
idd = poi_info['id']
|
||||
poi_id_str = poi_info['poi_id_str']
|
||||
shipping_fee_tip = poi_info['shipping_fee_tip']
|
||||
min_price_tip = poi_info['min_price_tip']
|
||||
packet_fee_tip = poi_info['packet_fee_tip']
|
||||
shipping_time = poi_info['shipping_time']
|
||||
|
||||
da = (workid ,parent_id,business_code, mt_org_id, poi_id_str,'', shop_name, shipping_fee_tip, min_price_tip, packet_fee_tip, shipping_time,
|
||||
address)
|
||||
|
||||
# insert_food_table = """
|
||||
# INSERT INTO food_table_copy1 (workid, parent_id, business_code, mt_org_id, poi_id_str, mt_org_name, shop_name, shipping_fee_tip, min_price_tip, packet_fee_tip, shipping_time, address)
|
||||
# VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
# ON DUPLICATE KEY UPDATE poi_id_str = VALUES(poi_id_str);
|
||||
# """
|
||||
# tent2.write_data_one(insert_food_table, da)
|
||||
return poi_id_str
|
||||
@@ -0,0 +1,144 @@
|
||||
import re
|
||||
import pymysql
|
||||
|
||||
class All_Setting():
|
||||
def __init__(self,host,port,db):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.db = db
|
||||
|
||||
def remove_symbols(self,text):
|
||||
pattern = re.compile(r'[^\w\s]')
|
||||
return pattern.sub('', text)
|
||||
|
||||
def get_chinese(self,text,printTxt=False):
|
||||
# text = "海王星辰(广州智慧城店)"
|
||||
pattern = r'[^\w\s]'
|
||||
result = re.sub(pattern, '', text)
|
||||
if printTxt:
|
||||
print(result)
|
||||
return result
|
||||
|
||||
def get_shoppingmalls(self,sql):
|
||||
res_list = []
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
if conn:
|
||||
print('ok')
|
||||
cursor = conn.cursor()
|
||||
res = cursor.execute(sql)
|
||||
c2 = cursor.fetchall()
|
||||
return c2
|
||||
|
||||
def write_data(self,sql,data):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.executemany(sql,data)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
|
||||
def update_data(self,sql):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
def write_data_one(self,sql,data):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(sql,data)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
import json
|
||||
import time,requests
|
||||
|
||||
|
||||
def get_sign_meituan(url, dfpid, data):
|
||||
url_mtg = "http://118.89.119.254:18003/mt_jym_1_2"
|
||||
payload = json.dumps({
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "POST",
|
||||
"ua_type": "android"
|
||||
})
|
||||
headers = {
|
||||
'token': 'j760kynsopjfm0sa9ghjwsd',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response1 = requests.request("POST", url_mtg, headers=headers, data=payload)
|
||||
print(response1.text)
|
||||
mtgsig1 = response1.json()
|
||||
return str(mtgsig1)
|
||||
|
||||
def get_sign_waimai(url, dfpid, data):
|
||||
print('我是外卖mtg')
|
||||
|
||||
url_mtg = "http://118.89.119.254:18003/get_mt_tg_0507_jym"
|
||||
payload = json.dumps({
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "POST",
|
||||
# "ua_type": "android"
|
||||
})
|
||||
headers = {
|
||||
'token': 'j760kynsopjfm0sa9ghjwsd',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("POST", url_mtg, headers=headers, data=payload)
|
||||
mtgsig = response.json()
|
||||
print(mtgsig)
|
||||
return str(mtgsig)
|
||||
|
||||
def get_Datatext(dataq):
|
||||
str1 = ''
|
||||
for i in dataq:
|
||||
key, value = i, dataq[i]
|
||||
str2 = f'{key}={value}&'
|
||||
str1 = str1 + str2
|
||||
data = str1[0:-1]
|
||||
return data
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import time
|
||||
import sys
|
||||
import json
|
||||
import requests
|
||||
|
||||
def get_sign_new(url, data, dfpid, mtg_origin):
|
||||
headers = {"content-type": "application/json", "token": "test_fhbosdhf789folhwdjfbiugwqedfrfugdsfsdf"}
|
||||
|
||||
body = {
|
||||
"mtg_origin":mtg_origin,
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "POST"}
|
||||
|
||||
url = "http://124.222.120.219:18003/hz_wm_jym_1008"
|
||||
# url = '124.222.190.152:10011/getmtgsig'
|
||||
|
||||
req = requests.post(url, headers=headers, json=body, proxies={'http': None, 'https': None}, verify=False).text
|
||||
print(req)
|
||||
return req
|
||||
|
||||
|
||||
def get_Datatext(dataq):
|
||||
str1 = ''
|
||||
for i in dataq:
|
||||
key, value = i, dataq[i]
|
||||
str2 = f'{key}={value}&'
|
||||
str1 = str1 + str2
|
||||
data = str1[0:-1]
|
||||
return data
|
||||
|
||||
def req_food(wm_poi_id,poi_id_str):
|
||||
# headersdata = mtgsig.get_headers()
|
||||
# headersdata = mtgsig.get_headers2()
|
||||
path = r'C:\Users\Administrator\PycharmProjects\pythonProject\A8_菜单爬取\headers_data\买药\2vw87249zvu854v40vu4vww7v010zx768006u34533577978631z96x8\food\food'
|
||||
with open(path,'r',encoding='utf-8') as f:
|
||||
headersdata = json.load(f)
|
||||
# headers,url,data,repp = hd
|
||||
headers = headersdata['headers']
|
||||
url = headersdata['url']
|
||||
data = headersdata['data']
|
||||
headers = headersdata['headers']
|
||||
url = headersdata['url']
|
||||
data = headersdata['data']
|
||||
# title = 'waimai'
|
||||
|
||||
req_time = int(time.time()*1000)
|
||||
data['req_time'] = req_time
|
||||
data['wm_poi_id'] = '-100'
|
||||
data['poi_id_str'] = poi_id_str
|
||||
mtg_origin = eval(headers['mtgsig'])
|
||||
dfpid = mtg_origin['a3']
|
||||
data2 = get_Datatext(data)
|
||||
headers['mtgsig'] = get_sign_new(url,data2,dfpid,mtg_origin)
|
||||
req = requests.post(url, headers=headers, data=data2,proxies={'http':None},verify=False)
|
||||
print(req.text)
|
||||
if req.json()['msg'] == "成功":
|
||||
return req.json()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
req_food('-100','0vkcs4t5bAISemtc5799wAI')
|
||||
@@ -0,0 +1,81 @@
|
||||
import datetime
|
||||
import os.path
|
||||
import random
|
||||
import time
|
||||
import sys
|
||||
import json
|
||||
import sys
|
||||
sys.path.append('../../setting')
|
||||
import requests
|
||||
|
||||
prox_confings = [
|
||||
{"http": None, "https": None}
|
||||
]
|
||||
def get_Datatext(dataq):
|
||||
str1 = ''
|
||||
for i in dataq:
|
||||
key, value = i, dataq[i]
|
||||
str2 = f'{key}={value}&'
|
||||
str1 = str1 + str2
|
||||
data = str1[0:-1]
|
||||
return data
|
||||
|
||||
def get_sign_new(url, data, dfpid, mtg_origin):
|
||||
headers = {"content-type": "application/json", "token": "test_fhbosdhf789folhwdjfbiugwqedfrfugdsfsdf"}
|
||||
|
||||
body = {
|
||||
"mtg_origin":mtg_origin,
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "POST"}
|
||||
|
||||
# url = "http://124.222.120.219:18003/hz_wm_jym_1008"
|
||||
url = 'http://8.138.127.139:10063/newmtgsig'
|
||||
req = requests.post(url, headers=headers, json=body, proxies={'http': None, 'https': None}, verify=False).text
|
||||
print(req)
|
||||
return req
|
||||
|
||||
|
||||
def req_food(wm_poi_id,poi_id_str, headersdata):
|
||||
# path = r'C:\Users\Administrator\PycharmProjects\pythonProject\商超全店项目-zhuifeng\headers_data2\2vw87249zvu854v40vu4vww7v010zx768006u34533577978631z96x8\food\food'
|
||||
# with open(path,'r',encoding='utf-8') as f:
|
||||
# headersdata = json.load(f)
|
||||
# headers = headersdata['headers']
|
||||
# url = headersdata['url']
|
||||
# data = headersdata['data']
|
||||
|
||||
if type(headersdata) == str:
|
||||
headersdata = json.loads(headersdata)
|
||||
headers = headersdata[1]
|
||||
url = headersdata[0]
|
||||
data = headersdata[2]
|
||||
req_time = int(time.time()*1000)
|
||||
data['req_time'] = req_time
|
||||
data['wm_poi_id'] = '-100'
|
||||
data['poi_id_str'] = poi_id_str
|
||||
mtg_origin = eval(headers['mtgsig'])
|
||||
dfpid = mtg_origin['a3']
|
||||
data2 = get_Datatext(data)
|
||||
headers['mtgsig'] = get_sign_new(url,data2,dfpid,mtg_origin)
|
||||
req = requests.post(url, headers=headers, data=data2,proxies=prox_confings[random.randint(0,len(prox_confings))-1],verify=False)
|
||||
|
||||
print(req.text[:2000])
|
||||
|
||||
if '"msg":"成功"' in req.text:
|
||||
today = datetime.date.today()
|
||||
formatted_date = f"{today.year}{today.month}{today.day}"
|
||||
sv = os.path.join('rawdata', formatted_date)
|
||||
os.makedirs(sv, exist_ok=True)
|
||||
with open(f'{sv}/{poi_id_str}',
|
||||
'w', encoding='utf-8') as f:
|
||||
f.write(req.text)
|
||||
return req.json()
|
||||
elif '"msg":"您的网络好像不太给力,请稍后再试"' in req.text:
|
||||
return 418
|
||||
elif '403 Forbidden' in req.text:
|
||||
return 403
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
req_food('-100','0vkcs4t5bAISemtc5799wAI')
|
||||
@@ -0,0 +1,76 @@
|
||||
import datetime
|
||||
import random
|
||||
import time
|
||||
import sys
|
||||
sys.path.append('../../setting')
|
||||
import newsetting as ten
|
||||
import get_food
|
||||
import reqFOOD2
|
||||
tent2 = ten.All_Setting(host='183.6.7.91',port=33016,db='mt_all_medince')
|
||||
tent3 = ten.All_Setting(host='183.6.7.91',port=23016,db='headers_project')
|
||||
# import schedule
|
||||
|
||||
def run(workid,headers):
|
||||
sql =f""" select `index`,mt_org_id,business_code FROM food_table_copy1 where business_code='TEST' and is_ok is null"""
|
||||
|
||||
a1 = tent2.get_shoppingmalls(sql)
|
||||
id=headers[0]
|
||||
headersdata=headers[3]
|
||||
print(a1)
|
||||
print(len(a1))
|
||||
# input(2222)
|
||||
for i in a1[:]:
|
||||
index,poiid,business_code = i
|
||||
print(i)
|
||||
# reqs = reqFOOD.req_food(wmid,poiid)#wss
|
||||
reqs = reqFOOD2.req_food('-100', poiid, headersdata)#小程序
|
||||
if type(reqs) == int:
|
||||
sql = f'''
|
||||
update market_food_headers set is_ok={reqs} where id='{id}'
|
||||
'''
|
||||
tent3.update_data(sql)
|
||||
break
|
||||
sql = f'''
|
||||
update market_food_headers set req_count=req_count+1 where id='{id}'
|
||||
'''
|
||||
tent3.update_data(sql)
|
||||
poi_id_str = get_food.rec_food(reqs,workid,business_code,poiid,index)
|
||||
update_sql = """
|
||||
update food_table_copy1 set is_ok =1,poi_id_str='%s' where `index` = %s
|
||||
"""%(poi_id_str,index)
|
||||
tent2.update_data(update_sql)
|
||||
# time.sleep(random.randint(3,8))
|
||||
|
||||
|
||||
def daily_task():
|
||||
"""每日执行的任务"""
|
||||
print(f"开始执行定时任务: {datetime.datetime.now()}")
|
||||
|
||||
sql = '''
|
||||
select * from market_food_headers where is_ok is null and title like '%买药%'
|
||||
'''
|
||||
products = []
|
||||
ids = []
|
||||
rt = tent3.get_shoppingmalls(sql)
|
||||
business_code = ''
|
||||
format_today = str(datetime.date.today()).replace("-", "")
|
||||
|
||||
for j in rt[10:]:
|
||||
for i in range(1):
|
||||
run(workid=f'{format_today}', headers=j)
|
||||
|
||||
print(f"任务执行完成: {datetime.datetime.now()}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# # 设置每天早上7点执行
|
||||
# schedule.every().day.at("07:00").do(daily_task)
|
||||
#
|
||||
# print("定时任务已启动,每天早上7点执行")
|
||||
# print("按 Ctrl+C 停止程序")
|
||||
#
|
||||
# # 保持程序运行
|
||||
# while True:
|
||||
# schedule.run_pending()
|
||||
# time.sleep(60) # 每分钟检查一次
|
||||
daily_task()
|
||||
@@ -0,0 +1,58 @@
|
||||
import os.path
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
# ------------------- 配置 -------------------
|
||||
SERVER_URL = "http://183.6.7.91:5123/save-file" # 替换为你的公网IP
|
||||
# 例如: SERVER_URL = "http://123.123.123.123:5123/save-file"
|
||||
|
||||
|
||||
def send_data(channel,master,business_code,file_name,data,file_dict=False):
|
||||
# 要发送的数据
|
||||
data_to_send = {
|
||||
"channel": channel, # 通道
|
||||
"master": master, # 主体/用户
|
||||
"business_code": business_code, # 业务代码
|
||||
"file_name": f"{file_name}", # 实际文件名
|
||||
'file_dict':file_dict,
|
||||
"data": data
|
||||
}
|
||||
|
||||
# ------------------- 发送请求 -------------------
|
||||
try:
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(
|
||||
SERVER_URL,
|
||||
json=(data_to_send),
|
||||
headers=headers,
|
||||
proxies={'http': None},
|
||||
verify=False,
|
||||
timeout=30
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
print("Success:", result)
|
||||
return True
|
||||
else:
|
||||
print(f"Error {response.status_code}: {response.text}")
|
||||
return False
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Request failed: {e}")
|
||||
return False
|
||||
except requests.exceptions.JSONDecodeError as e:
|
||||
print(f"Invalid JSON response: {e}, Response text: {response.text}")
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
with open('productlist','r',encoding='utf-8') as f:
|
||||
req = json.load(f)
|
||||
|
||||
|
||||
|
||||
send_data('supermaket','大时尚','2025810',poi_id,req,True)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,133 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import jsonpath
|
||||
|
||||
import newsetting as ten
|
||||
|
||||
tent2 = ten.All_Setting(host='183.6.7.91',port=23016,db='pyui_all_market')
|
||||
|
||||
|
||||
def get_path2(path):
|
||||
li = []
|
||||
|
||||
for a,b,c in os.walk(path):
|
||||
if len(c)>0:
|
||||
for d in c:
|
||||
if 'food' in d:
|
||||
li.append(os.path.join(a,d))
|
||||
return li
|
||||
|
||||
|
||||
|
||||
|
||||
def rec_food(req,workid,business_code,mt_org_id,parent_id,lat,lng,prox,city):
|
||||
def get_coupon():
|
||||
li = []
|
||||
coupon_list = poi_coupon['coupon_list']
|
||||
for i in coupon_list:
|
||||
coupon_id = i.get('coupon_id')
|
||||
|
||||
coupon_name = i.get('coupon_name')
|
||||
new_limit_price = i.get('new_limit_price')
|
||||
coupon_type_label = i.get('coupon_type_label')
|
||||
tabName = i.get('tabName')
|
||||
product_num = i.get('product_num')
|
||||
label_doc = jsonpath.jsonpath(i, '$..label_doc')
|
||||
da = (poi_id_str, coupon_id, coupon_name, new_limit_price, coupon_type_label, tabName, product_num,
|
||||
label_doc)
|
||||
li.append(da)
|
||||
return li
|
||||
def get_discounts2():
|
||||
li = []
|
||||
for i in discounts2:
|
||||
id = i.get('id')
|
||||
info = i.get('info')
|
||||
da = (poi_id_str, id, info)
|
||||
li.append(da)
|
||||
return li
|
||||
try:
|
||||
print('返回响应格式1')
|
||||
poi_info = req['data']['poi_info']
|
||||
except:
|
||||
print('返回响应格式2')
|
||||
poi_info = req["data"]["ext"]["common_info"]["v9_data"]["poi_info"]
|
||||
wm_poi_id = poi_info['id']
|
||||
poi_id_str = poi_info['poi_id_str']
|
||||
shop_name = poi_info['name']
|
||||
address = poi_info['address']
|
||||
poi_coupon = poi_info.get('poi_coupon')
|
||||
discounts2 = poi_info['discounts2']
|
||||
poi_info = poi_info
|
||||
idd = poi_info['id']
|
||||
poi_id_str = poi_info['poi_id_str']
|
||||
shipping_fee_tip = poi_info['shipping_fee_tip']
|
||||
min_price_tip = poi_info['min_price_tip']
|
||||
try:packet_fee_tip = poi_info['packet_fee_tip']
|
||||
except:packet_fee_tip = ''
|
||||
shipping_time = poi_info['shipping_time']
|
||||
|
||||
da = (workid ,parent_id,business_code, mt_org_id, poi_id_str,'', shop_name, shipping_fee_tip, min_price_tip, packet_fee_tip, shipping_time,
|
||||
address)
|
||||
|
||||
insert_food_table = """
|
||||
insert into food_table (workid ,parent_id,business_code, mt_org_id, poi_id_str,mt_org_name, shop_name, shipping_fee_tip, min_price_tip, packet_fee_tip, shipping_time,
|
||||
address) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);
|
||||
"""
|
||||
tent2.write_data_one(insert_food_table, da)
|
||||
# if bool(poi_coupon):
|
||||
# coupon_list = get_coupon()
|
||||
#
|
||||
# insert_coupon = """
|
||||
# insert into coupon_table2 (workid, coupon_id, coupon_name,new_limit_price,coupon_type_label,tabName,product_num,label_doc) values (%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
# """
|
||||
# try:
|
||||
# tent2.write_data(insert_coupon, coupon_list)
|
||||
# except:
|
||||
# pass
|
||||
# if bool(discounts2):
|
||||
# discounts_list = get_discounts2()
|
||||
# insert_discounts_list = """
|
||||
# insert into discounts_table (workid, coupon_id, coupon_name) values (%s,%s,%s)
|
||||
# """
|
||||
# tent2.write_data(insert_discounts_list, discounts_list)
|
||||
da3 = (workid,parent_id,business_code,mt_org_id,poi_id_str,shop_name,address)
|
||||
need1 = ['tag','name','tags','type','has_next_page','product_count','allSortedSpuId']
|
||||
da = req["data"]["ext"]["common_info"]["v9_data"]['food_spu_tags']
|
||||
# try:
|
||||
for i in da:
|
||||
for b in list(i.keys()):
|
||||
if b not in need1:
|
||||
i.pop(b)
|
||||
|
||||
categoryList = []
|
||||
for i in da:
|
||||
tag1 = i['tag']
|
||||
name1 = i['name']
|
||||
tags = (i['tags'])
|
||||
tag_type = i.get('type')
|
||||
has_next_page = i.get('has_next_page')
|
||||
product_count = i.get('product_count')
|
||||
allSortedSpuId = json.dumps(i.get('allSortedSpuId'))
|
||||
if len(tags) > 0:
|
||||
for b in tags:
|
||||
tag2 = b['tag']
|
||||
name2 = b['name']
|
||||
tag_type = b['type']
|
||||
da2 = (tag1,name1,tag2,name2,tag_type)
|
||||
da4 = da3+da2+(None,has_next_page,product_count,allSortedSpuId)
|
||||
da4 += (lat, lng, prox, city)
|
||||
print(da4)
|
||||
print(len(da4))
|
||||
categoryList.append(da4)
|
||||
else:
|
||||
da2 = (tag1,name1,tag1,name1,tag_type)
|
||||
da4 = da3 + da2+(None,has_next_page,product_count,allSortedSpuId)
|
||||
da4+=(lat,lng,prox,city)
|
||||
print(da4)
|
||||
categoryList.append(da4)
|
||||
# print(len(da4))
|
||||
insertsql = """
|
||||
insert into categoryList2 (batch,parent_id,business_code,mt_org_id,poi_id_str,shop_name,address,tag1,tag1_name,tag2,tag2_name,tag_type,is_ok,has_next_page,product_count,allSortedSpuId,lat,lng,prox_data,city_name) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
"""
|
||||
tent2.write_data(insertsql,categoryList)
|
||||
@@ -0,0 +1,144 @@
|
||||
import re
|
||||
import pymysql
|
||||
|
||||
class All_Setting():
|
||||
def __init__(self,host,port,db):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.db = db
|
||||
|
||||
def remove_symbols(self,text):
|
||||
pattern = re.compile(r'[^\w\s]')
|
||||
return pattern.sub('', text)
|
||||
|
||||
def get_chinese(self,text,printTxt=False):
|
||||
# text = "海王星辰(广州智慧城店)"
|
||||
pattern = r'[^\w\s]'
|
||||
result = re.sub(pattern, '', text)
|
||||
if printTxt:
|
||||
print(result)
|
||||
return result
|
||||
|
||||
def get_shoppingmalls(self,sql):
|
||||
res_list = []
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
if conn:
|
||||
print('ok')
|
||||
cursor = conn.cursor()
|
||||
res = cursor.execute(sql)
|
||||
c2 = cursor.fetchall()
|
||||
return c2
|
||||
|
||||
def write_data(self,sql,data):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.executemany(sql,data)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
|
||||
def update_data(self,sql):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
def write_data_one(self,sql,data):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(sql,data)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
import json
|
||||
import time,requests
|
||||
|
||||
|
||||
def get_sign_meituan(url, dfpid, data):
|
||||
url_mtg = "http://118.89.119.254:18003/mt_jym_1_2"
|
||||
payload = json.dumps({
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "POST",
|
||||
"ua_type": "android"
|
||||
})
|
||||
headers = {
|
||||
'token': 'j760kynsopjfm0sa9ghjwsd',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response1 = requests.request("POST", url_mtg, headers=headers, data=payload)
|
||||
print(response1.text)
|
||||
mtgsig1 = response1.json()
|
||||
return str(mtgsig1)
|
||||
|
||||
def get_sign_waimai(url, dfpid, data):
|
||||
print('我是外卖mtg')
|
||||
|
||||
url_mtg = "http://118.89.119.254:18003/get_mt_tg_0507_jym"
|
||||
payload = json.dumps({
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "POST",
|
||||
# "ua_type": "android"
|
||||
})
|
||||
headers = {
|
||||
'token': 'j760kynsopjfm0sa9ghjwsd',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("POST", url_mtg, headers=headers, data=payload)
|
||||
mtgsig = response.json()
|
||||
print(mtgsig)
|
||||
return str(mtgsig)
|
||||
|
||||
def get_Datatext(dataq):
|
||||
str1 = ''
|
||||
for i in dataq:
|
||||
key, value = i, dataq[i]
|
||||
str2 = f'{key}={value}&'
|
||||
str1 = str1 + str2
|
||||
data = str1[0:-1]
|
||||
return data
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user