# -*- coding: utf-8 -*- """ Created on 2025-05-24 --------- @summary: utils --------- @author: Lzz """ from urllib import parse import execjs import requests from untils.tools import get_proxy def get_nodeId(params,proxies=False): proxy = proxies en_str = get_enstr(params) headers = { "Accept": "application/json, text/plain, */*", "Accept-Language": "zh-CN,zh;q=0.9", "Cache-Control": "no-cache", "Connection": "keep-alive", "Pragma": "no-cache", "Referer": "https://ygp.gdzwfw.gov.cn/ggzy-portal/", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36", "X-Dgi-Req-App": en_str.get('X-Dgi-Req-App'), "X-Dgi-Req-Nonce": en_str.get('X-Dgi-Req-Nonce'), "X-Dgi-Req-Signature": en_str.get('X-Dgi-Req-Signature'), "X-Dgi-Req-Timestamp": en_str.get('X-Dgi-Req-Timestamp'), } url = "https://ygp.gdzwfw.gov.cn/ggzy-portal/center/apis/trading-notice/new/nodeList" retry = 0 while retry < 3: try: res = requests.get(url, headers=headers, params=params, proxies=proxy, timeout=60, verify=False) nodeId_info = res.json().get('data') nodeId_dict = {} for nd in nodeId_info: dsList = nd.get('dsList') for i in dsList: for k, v in i.items(): for child in v: nodeId_dict[child] = nd.get('nodeId') nodeId_dict[nd.get('noticeId')] = nd.get('nodeId') if nodeId_dict: break proxy = get_proxy(socks5h=True) retry += 1 except: retry += 1 return nodeId_dict def get_enstr(data): p_list = [] for key, value in data.items(): if str(value) == "False": value = "false" p_list.append(f"{key}={value}") p_str = parse.quote("&".join(p_list), safe="&=") with open('mmsggzyjypt_encrypt.js', 'r') as fr: ex_js = fr.read() ctx = execjs.compile(ex_js) pm = ctx.call('get_pm',p_str) return pm def create_href(data): with open('mmsggzyjypt_encrypt.js', 'r') as fr: ex_js = fr.read() ctx = execjs.compile(ex_js) pm = ctx.call('create_href',data) return pm def deal_time(tm): if tm and len(tm) == 8: pbtime = tm[:4] + "-" + tm[4:6] + "-" + tm[6:8] elif tm and len(tm) == 14: pbtime = tm[:4] + "-" + tm[4:6] + "-" + tm[6:8] + " " + tm[8:10] + ":" + tm[10:12] + ":" + tm[12:] else: pbtime = tm return pbtime