import json import os import queue import re import time import requests import newsetting as ten from concurrent.futures.thread import ThreadPoolExecutor from urllib.parse import urlparse, parse_qs, urlencode, urlunparse tent = ten.All_Setting(host='183.6.7.91',port=33016,db='headers_project') tent2 = ten.All_Setting(host='183.6.7.91',port=33016,db='mt_newretail') import urllib.parse def key_quote(key): key1 = urllib.parse.quote(key) print(key1) return key1 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 get_sign_new1(url, data, dfpid, mtg_origin,openId): headers = {"content-type": "application/json", "token": "test_sdfio23923ojbedfojgbouqgew4r32dds"} body = { "mtg_origin":mtg_origin, "url": url, "data": data, "dfpid": dfpid, "method": "POST", "open_id": openId,# 微信的open_id } # url = "http://124.222.120.219:18003/hz_wm_jym_1008" url = 'http://129.211.12.35:18003/minipro_mt_0206' req = requests.post(url, headers=headers, json=body, proxies={'http': None, 'https': None}, verify=False).text print(req) return req def get_headers(): sql = ''' select `id`,json_data from medince_item_hd where is_ok is null and title like '%便利店%' ''' sql = ''' select `id`,json_data from medince_item_hd where is_ok is null ''' headers = tent.get_shoppingmalls(sql) return headers def get_items(): sql = ''' select `id`,`poi_id_str`,product_id,upccode from drug_detail_list where is_ok is null and `id` not in (select parent_id from save_item) and `shop_name` LIKE '%成人%' limit 1000; ''' sql = ''' select `id`,`poi_id_str`,product_id,upccode FROM `mt_newretail`.`drug_detail_list` WHERE `create_time` >= '2026-06-24 22:43' and is_ok is null; ''' item = tent2.get_shoppingmalls(sql) return item def update_headers(ind,is_ok,json_data=''): if is_ok==1: sql = f''' update medince_item_hd set req_count=req_count+1,current_count=current_count+1 where `id`={ind} ''' elif is_ok==418: sql = ''' update medince_item_hd set is_ok=%s,json_data=%s where `id`=%s ''' tent.write_data(sql,((is_ok,json_data,ind),)) return else: sql = f''' update medince_item_hd set is_ok={is_ok} where `id`={ind} ''' tent.update_data(sql) def save_item(ind,data): sql = ''' insert into save_item (parent_id,json_data) values (%s,%s) ''' tent2.write_data(sql,((ind,data),)) def update_item(ind): sql = ''' update drug_detail_list set is_ok=1 where `id`=%s ''' tent2.write_data(sql,(ind,)) def run(hd,work): hd_ind = hd[0] url,headers,data = json.loads(hd[1]) while 1: spu_tag = False if work.empty(): break id_, poi_id_str, spu_id, sku_id = work.get() if bool(spu_tag) is False: spu_tag = "undefined" varib = {"wm_poi_id":"-100","poi_id_str":poi_id_str,"spu_id":spu_id,"sku_id":"0","spu_tag":'null',"activity_tag":"undefined","share_activity_uuid":"null","sale_type":"0","ch":"","planKey":"drug-detail"} varib2 = str(varib) data['variablesStr'] = key_quote(varib2) ''' 便利店详情 ''' # data['poi_id_str'] = poi_id_str # data['poi_id_str'] = 'GmXWpjQTF2fdKJ6xjsrBswI' # data['spu_id'] = spu_id # data['skus_id'] = sku_id longitude,latitude = '29869624', '121266950' data['wm_latitude'],data['wm_longitude'] = longitude,latitude data['latitude'],data['longitude'] = longitude,latitude data['wm_actual_latitude'],data['wm_actual_longitude'] = longitude,latitude req_time = str(int(time.time() * 1000)) data['req_time'] = req_time url_data = urlparse(url) params = parse_qs(url_data.query) params['req_time'] = [str(int(time.time() * 1000))] params['wm_longitude'] = [longitude] params['wm_latitude'] = [latitude] params['longitude'] = [longitude] params['latitude'] = [latitude] params['wm_actual_longitude'] = [longitude] params['wm_actual_latitude'] = [latitude] new_query = urlencode(params, doseq=True) url = urlunparse( (url_data.scheme, url_data.netloc, url_data.path, url_data.params, new_query, url_data.fragment)) mtg_origin = eval(headers['mtgsig']) dfpid = mtg_origin['a3'] data2 = get_Datatext(data) openId = headers['openId'] headers["Content-Length"] = str(len(data2)) headers['mtgsig'] = get_sign_new1(url, data2, dfpid, mtg_origin, openId) # prox ={"http": "http://kso8:kso8s@183.131.35.75:21702", "https": "http://kso8:kso8s@183.131.35.75:21702"} prox ={"http": None, "https": None} print(req_time) print(url) req = requests.post(url, headers=headers, data=data2, verify=False, proxies=prox) print(req.text[:]) if '您的网络好像不太给力,请稍后再试' in req.text: json_data = json.dumps([url,headers,data]) update_headers(hd_ind,418,json_data) return False if req.status_code == 403: update_headers(hd_ind,403) return False save_item(id_,json.dumps(req.json())) update_item(id_) update_headers(hd_ind,1) # input(456) if __name__ == '__main__': # while True: headers = get_headers() # if not headers: # print('没包了, 退出') # break items = get_items() work = queue.Queue() for i in items: work.put(i) thread_num = 1 if thread_num <= 1: for i in headers: run(i,work) else: with ThreadPoolExecutor(thread_num) as p: for i in headers: p.submit(run,i,work)